def set_network(self, network: str): """Set/update the current network :param network: "mainnet" or "testnet" :type network: str :returns: the client :raises: raises if network not provided :raises: `Invalid network' if the given network is invalid """ if not network: raise Exception("Network must be provided") else: self.network = network # choose network (testnet or mainnet) if self.network == 'testnet': # initialise with Testnet environment self.env = BinanceEnvironment.get_testnet_env() elif self.network == 'mainnet': # initialise with mainnet environment self.env = BinanceEnvironment.get_production_env() else: raise Exception("Invalid network") self.client = AsyncHttpApiClient(env=self.env) self.address = '' return self.client
def __init__(self): self.env = BinanceEnvironment.get_testnet_env() self.client = HttpApiClient(env=self.env) with open('secret/bnb_key.txt', 'r') as f: key = f.readline() self.wallet = Wallet(key, env=self.env) self.address = self.wallet.address driver_logger.info(f'bnb address: {self.address}')
def __init__(self, wallet_settings: WalletSettings): self._settings = wallet_settings w_env = BinanceEnvironment.get_production_env() if wallet_settings.env_name == 'TESTNET': w_env = BinanceEnvironment.get_testnet_env() self._wallet = Wallet( private_key=wallet_settings.private_key.get_secret_value(), env=w_env) self._http_client: Optional[AsyncHttpApiClient] = None
def freeze_bnb_wish(amount): freeze_env = BinanceEnvironment.get_production_env() if NETWORK_SIGN_TRANSACTION_BWISH == 'testnet': freeze_env = BinanceEnvironment.get_testnet_env() client = HttpApiClient(env=freeze_env) bep_wallet = Wallet(BINANCE_PAYMENT_PASSWORD, env=freeze_env) # from settings value = float(amount / 10**18) freeze_msg = TransferMsg(wallet=bep_wallet, symbol=COLD_TOKEN_SYMBOL_BNB, amount=value, to_address=COLD_BNB_ADDRESS, memo='freeze bnb wish') res = client.broadcast_msg(freeze_msg, sync=True) print('result', res, flush=True) if not res[0]['ok']: raise Exception('cannot make bnb wish freeze tx')
def __init__(self, wallet_settings: WalletSettings): self._settings = wallet_settings w_env = BinanceEnvironment.get_production_env() if wallet_settings.env_name == 'TESTNET': w_env = BinanceEnvironment.get_testnet_env() if wallet_settings.private_key: log_init_type = 'private_key' self._wallet = Wallet(private_key=wallet_settings.private_key.get_secret_value(), env=w_env) elif wallet_settings.mnemonic: log_init_type = 'mnemonic' self._wallet = Wallet.create_wallet_from_mnemonic(wallet_settings.mnemonic.get_secret_value(), env=w_env) else: raise Exception(f"Unable to initialise wallet {wallet_settings.name} no private_key or mnemonic set") self._http_client: Optional[AsyncHttpApiClient] = None logging.info(f"Initialised wallet {wallet_settings.name} with {log_init_type}")
def __init__(self, key, test=False): self.BUSD = 'BUSD-BD1' self.BNB = 'BNB' self.pairs = [] self.bnb_pairs = {} self.busd_pairs = {} self.api_instance = binance_client.DefaultApi() if test: self.env = BinanceEnvironment.get_testnet_env() self.RUNE = 'RUNE-67C' self.api_instance.api_client.configuration.host = self.env.api_url + '/api' else: self.env = BinanceEnvironment(api_url='https://dex-european.binance.org', wss_url='wss://dex.binance.org/api/', hrp='bnb') self.RUNE = 'RUNE-B1A' binance_logger.info(f'Binance connected to node: {self.env.api_url}') self.client = HttpApiClient(env=self.env) self.wallet = Wallet(private_key=key, env=self.env) self.wallet.reload_account_sequence() self.account_info()
def env(self): return BinanceEnvironment.get_testnet_env()
def test_testnet_environment(self): env = BinanceEnvironment.get_testnet_env() assert env.hrp == BinanceEnvironment.TESTNET_ENV['hrp'] assert env.wss_url == BinanceEnvironment.TESTNET_ENV['wss_url'] assert env.api_url == BinanceEnvironment.TESTNET_ENV['api_url']
config = configparser.ConfigParser() config.read('./stream.conf') loop = None bnb_webhook_url = config['stream']['bnb_webhook_url'] token = config['stream']['bnb_token'] address = config.get('stream', 'bnb_master_address').strip() bnb_api_url = config['stream']['bnb_api_url'] bnb_wss_url = config['stream']['bnb_wss_url'] bnb_hrp_url = config['stream']['bnb_hrp_url'] use_testnet = config['stream'].getboolean('use_testnet') sleep_time = config['stream'].getint('sleep_time') if use_testnet is True: print("Use test net") testnet_env = BinanceEnvironment.get_testnet_env() else: print('Use main net') testnet_env = BinanceEnvironment(api_url=bnb_api_url, wss_url=bnb_wss_url, hrp=bnb_hrp_url) print('bnb_webhook_url: {}, token: {}, address: {}'.format( bnb_webhook_url, token, str(address))) print('bnb_api_url: {}, bnb_wss_url: {}, bnb_hrp_url: {}'.format( bnb_api_url, bnb_wss_url, bnb_hrp_url)) headers = { 'content-type': 'application/json', 'Authorization': '', }