def __init__(self, bitshares_instance, config): self.bitshares_instance = bitshares_instance set_shared_bitshares_instance(bitshares_instance) self.config = config self.worker_manager = None # Configure logging data_dir = user_data_dir(APP_NAME, AUTHOR) filename = os.path.join(data_dir, 'dexbot.log') formatter = logging.Formatter( '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s' ) logger = logging.getLogger("dexbot.per_worker") fh = logging.FileHandler(filename) fh.setFormatter(formatter) logger.addHandler(fh) logger.setLevel(logging.INFO) self.pyqt_handler = PyQtHandler() self.pyqt_handler.setLevel(logging.INFO) logger.addHandler(self.pyqt_handler) logger.info("DEXBot {} on python {} {}".format(VERSION, sys.version[:6], sys.platform), extra={ 'worker_name': 'NONE', 'account': 'NONE', 'market': 'NONE' }) # Configure orders logging initialize_orders_log()
def test_default_connection(self): b1 = BitShares("wss://eu.nodes.bitshares.ws", nobroadcast=True) set_shared_bitshares_instance(b1) test = Asset("1.3.0", blockchain_instance=b1) # Needed to clear cache test.refresh() """
def set_bitshares_instance(self, bitshares_instance): """ Set bitshares instance :param bitshares_instance: A bitshares instance """ self.bitshares_instance = bitshares_instance set_shared_bitshares_instance(bitshares_instance)
def new_func(ctx, *args, **kwargs): ctx.bitshares = BitShares( ctx.config["node"], **ctx.obj ) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def __init__(self, bitshares_instance): self.bitshares_instance = bitshares_instance set_shared_bitshares_instance(bitshares_instance) self.worker_manager = None # Configure logging formatter = logging.Formatter( '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s' ) logger = logging.getLogger("dexbot.per_worker") fh = logging.FileHandler('dexbot.log') fh.setFormatter(formatter) logger.addHandler(fh) logger.setLevel(logging.INFO) self.pyqt_handler = PyQtHandler() self.pyqt_handler.setLevel(logging.INFO) logger.addHandler(self.pyqt_handler) logger.info("DEXBot {} on python {} {}".format(VERSION, sys.version[:6], sys.platform), extra={ 'worker_name': 'NONE', 'account': 'NONE', 'market': 'NONE' })
def new_func(ctx, *args, **kwargs): newoptions = ctx.obj newoptions.update(kwargsChain) ctx.bitshares = BitShares(**newoptions) ctx.blockchain = ctx.bitshares set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares( nobroadcast=True, ) set_shared_bitshares_instance(self.bts)
def enable(self): if not self.enabled: from bitshares.instance import set_shared_bitshares_instance broken = BrokenBitsharesInstance() set_shared_bitshares_instance(broken) self.enabled = True
def __init__(self, *args, **kwargs): super(Testcases, self).__init__(*args, **kwargs) bitshares = BitShares( "wss://node.bitshares.eu", nobroadcast=True, ) set_shared_bitshares_instance(bitshares)
def new_func(ctx, *args, **kwargs): ctx.bitshares = BitShares( ctx.config["node"], **ctx.obj ) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def new_func(ctx, *args, **kwargs): ctx.bitshares = BitShares(ctx.config["node"], num_retries=-1, expiration=60, **ctx.obj) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def setup_bitshares_market(bts_symbol): bitshares_instance = BitShares( "wss://losangeles.us.api.bitshares.org/ws", nobroadcast=True # <<--- set this to False when you want to fire! ) set_shared_bitshares_instance(bitshares_instance) bts_market = Market(bts_symbol, bitshares_instance=bitshares_instance) return bts_market
def new_func(ctx, *args, **kwargs): ctx.bitshares = BitShares( ctx.config["node"], bundle=True, # We bundle many feeds into a single tx **ctx.obj ) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares("wss://node.testnet.bitshares.eu", nobroadcast=True, keys={"active": wif}) set_shared_bitshares_instance(self.bts) self.bts.set_default_account("init0")
def new_func(ctx, *args, **kwargs): nodelist = sort_nodes(ctx) ctx.bitshares = BitShares(nodelist, num_retries=-1, expiration=60, **ctx.obj) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
def new_bitshares_instance(self, node, retries=-1, expiration=60): """ Create bitshares instance :param retries: Number of retries to connect, -1 default to infinity :param expiration: Delay in seconds until transactions are supposed to expire :param list node: Node or a list of nodes """ self.bitshares_instance = BitShares(node, num_retries=retries, expiration=expiration) set_shared_bitshares_instance(self.bitshares_instance)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares(url, nobroadcast=True) set_shared_bitshares_instance(self.bts) self.asset = Asset("1.3.0") self.symbol = self.asset["symbol"] self.precision = self.asset["precision"] self.asset2 = Asset("1.3.1")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares( "wss://node.testnet.bitshares.eu", nobroadcast=True, ) self.bts.set_default_account("init0") set_shared_bitshares_instance(self.bts) self.chain = Blockchain(mode="head")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif]) self.bts.set_default_account("init0") set_shared_bitshares_instance(self.bts)
def bitshares_instance(bitshares_testnet, private_keys): """Initialize BitShares instance connected to a local testnet.""" bitshares = BitShares( node="ws://127.0.0.1:{}".format(bitshares_testnet.service_port), keys=private_keys, num_retries=-1, ) # Shared instance allows to avoid any bugs when bitshares_instance is not passed # explicitly when instantiating objects. Todo: remove this set_shared_bitshares_instance(bitshares) return bitshares
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares( "wss://node.testnet.bitshares.eu", nobroadcast=True, keys={"active": wif}, ) # from getpass import getpass # self.bts.wallet.unlock(getpass()) set_shared_bitshares_instance(self.bts) self.bts.set_default_account("init0")
def _ensure_blockchain_connection(): """ Checks if the SharedInstance.instance is the configured instance and if not initializes and sets it """ if not Configured_Instance.configured_instance: Configured_Instance.configured_instance = _get_configured_instance() if SharedInstance.instance != Configured_Instance.configured_instance: set_shared_bitshares_instance(Configured_Instance.configured_instance) return Configured_Instance.configured_instance
def __init__(self, bitshares_instance): self.bitshares_instance = bitshares_instance set_shared_bitshares_instance(bitshares_instance) self.worker_manager = None # Configure logging formatter = logging.Formatter( '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s') logger = logging.getLogger("dexbot.per_worker") fh = logging.FileHandler('dexbot.log') fh.setFormatter(formatter) logger.addHandler(fh) logger.setLevel(logging.INFO)
def bitshares_instance(bitshares_testnet): """ Initialize BitShares instance connected to a local testnet """ bitshares = BitShares( node='ws://127.0.0.1:{}'.format(bitshares_testnet.service_port), keys=PRIVATE_KEYS, num_retries=10 ) # Shared instance allows to avoid any bugs when bitshares_instance is not passed explicitly when instantiating # objects set_shared_bitshares_instance(bitshares) # Todo: show chain params when connectiong to unknown network # https://github.com/bitshares/python-bitshares/issues/221 return bitshares
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bts = BitShares(nobroadcast=True, wif=[wif]) set_shared_bitshares_instance(self.bts) self.bts.set_default_account("init0") cache = ObjectCache(default_expiration=5, no_overwrite=True) init0 = { 'active': { 'account_auths': [], 'address_auths': [], 'key_auths': [[str(PrivateKey(wif).pubkey), 1]], 'weight_threshold': 1 }, 'active_special_authority': [0, {}], 'blacklisted_accounts': [], 'blacklisting_accounts': [], 'cashback_vb': '1.13.102', 'id': '1.2.90742', 'lifetime_referrer': '1.2.90742', 'lifetime_referrer_fee_percentage': 8000, 'membership_expiration_date': '1969-12-31T23:59:59', 'name': 'init0', 'network_fee_percentage': 2000, 'options': { 'extensions': [], 'memo_key': str(PrivateKey(wif).pubkey), 'num_committee': 0, 'num_witness': 0, 'votes': [], 'voting_account': '1.2.5' }, 'owner': { 'account_auths': [], 'address_auths': [], 'key_auths': [[str(PrivateKey(wif).pubkey), 1]], 'weight_threshold': 1 }, 'owner_special_authority': [0, {}], 'referrer': '1.2.90742', 'referrer_rewards_percentage': 0, 'registrar': '1.2.90742', 'statistics': '2.6.90742', 'top_n_control_flags': 0, 'whitelisted_accounts': [], 'whitelisting_accounts': [] } cache[init0["id"]] = init0 cache[init0["name"]] = init0 BlockchainObject._cache = cache
def test_default_connection(self): b1 = BitShares("wss://node.testnet.bitshares.eu", nobroadcast=True) set_shared_bitshares_instance(b1) test = Asset("1.3.0", blockchain_instance=b1) # Needed to clear cache test.refresh() b2 = BitShares("wss://node.bitshares.eu", nobroadcast=True) set_shared_bitshares_instance(b2) bts = Asset("1.3.0", blockchain_instance=b2) # Needed to clear cache bts.refresh() self.assertEqual(test["symbol"], "TEST") self.assertEqual(bts["symbol"], "X4T")
def setup_bitshares_market(bts_symbol): bitshares_instance = BitShares( "wss://siliconvalley.us.api.bitshares.org/ws", "wss://bitshares.openledger.info/ws", nobroadcast=True # <<--- set this to False when you want to fire! ) bts_config_file = "safe/bitshares.ini" bts_passwd, acct= get_bts_config(bts_config_file) bitshares_instance.wallet.unlock(bts_passwd) set_shared_bitshares_instance(bitshares_instance) bts_market = Market( bts_symbol, bitshares_instance=bitshares_instance ) return bts_market
def test_default_connection(self): b1 = BitShares( "wss://node.testnet.bitshares.eu", nobroadcast=True, ) set_shared_bitshares_instance(b1) test = Asset("1.3.0") b2 = BitShares( "wss://node.bitshares.eu", nobroadcast=True, ) set_shared_bitshares_instance(b2) bts = Asset("1.3.0") self.assertEqual(test["symbol"], "TEST") self.assertEqual(bts["symbol"], "BTS")
def new_func(ctx, *args, **kwargs): nodelist = ctx.config["node"] timeout = int(ctx.obj.get("sortnodes")) host_ip = '8.8.8.8' if ping(host_ip, 3) is False: click.echo("internet NOT available! Please check your connection!") log.critical("Internet not available, exiting") sys.exit(78) if timeout > 0: click.echo( "Checking for nearest nodes with timeout < {} sec....".format( timeout)) nodelist = get_sorted_nodelist(ctx.config["node"], timeout) click.echo("Nearest nodes -> " + str(nodelist)) ctx.bitshares = BitShares(nodelist, num_retries=-1, expiration=60, **ctx.obj) set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)
from datetime import datetime from bitshares import BitShares from bitshares.instance import set_shared_bitshares_instance # класс с расчетом цен на бирже BitShares from btsParser.Parser import Parser # класс для работы с VIZ (от Протея) from tvizbase.api import Api with open(os.path.dirname(__file__) + '/settings.json', 'r') as sett_file: settings = json.load(sett_file) decimal.getcontext().rounding = 'ROUND_HALF_UP' # подключение к ноде node в сети Bitshares BTS = BitShares(node=settings['bitshares_node']) set_shared_bitshares_instance(BTS) # подключение к сети VIZ viz = Api() # инициализация класса parser = Parser(settings) # получение данных о глубине стаканов parser.get_market_depth() # получение данных об истории сделок #parser.get_history_depth() # публикация данных в блокчейне VIZ viz.custom( 'vizplus_bitshares_info', # ID custom'а [ 'vizplus_bitshares_info', # название типа данных, может отличаться от ID { 'time_utc':
def new_func(ctx, *args, **kwargs): ctx.bitshares = BitShares(**ctx.obj) ctx.blockchain = ctx.bitshares set_shared_bitshares_instance(ctx.bitshares) return ctx.invoke(f, *args, **kwargs)