def test_binance_assets_are_known( database, inquirer, # pylint: disable=unused-argument ): # use a real binance instance so that we always get the latest data binance = Binance( api_key=make_api_key(), secret=make_api_secret(), database=database, msg_aggregator=MessagesAggregator(), ) mapping = binance.symbols_to_pair binance_assets = set() for _, pair in mapping.items(): binance_assets.add(pair.binance_base_asset) binance_assets.add(pair.binance_quote_asset) sorted_assets = sorted(binance_assets) for binance_asset in sorted_assets: try: _ = asset_from_binance(binance_asset) except UnsupportedAsset: assert binance_asset in UNSUPPORTED_BINANCE_ASSETS except UnknownAsset as e: test_warnings.warn( UserWarning( f'Found unknown asset {e.asset_name} in Binance. Support for it has to be added', ))
def create_test_binance( database: DBHandler, msg_aggregator: MessagesAggregator, location: Location = Location.BINANCE, name: str = 'binance', ) -> Binance: if location == Location.BINANCE: uri = BINANCE_BASE_URL elif location == Location.BINANCEUS: uri = BINANCEUS_BASE_URL else: raise AssertionError( f'Tried to create binance exchange with location {location}') binance = Binance( name=name, api_key=make_api_key(), secret=make_api_secret(), database=database, msg_aggregator=msg_aggregator, uri=uri, ) this_dir = os.path.dirname(os.path.abspath(__file__)) json_path = Path(this_dir) / 'data' / 'binance_exchange_info.json' with json_path.open('r') as f: json_data = json.loads(f.read()) binance._symbols_to_pair = create_binance_symbols_to_pair( json_data, location) binance.first_connection_made = True return binance
def get_exchange(self, account: str) -> ExchangeInterface: account_info = [a for a in self.config['accounts'] if a['name'] == account][0] exchange_opts = dict( name=account_info['name'], api_key=str(account_info['api_key']), secret=str(account_info['secret']).encode(), database=self, msg_aggregator=self.msg_aggregator ) if account_info['exchange'] == 'kraken': exchange = Kraken(**exchange_opts) elif account_info['exchange'] == 'binance': exchange = Binance(**exchange_opts) elif account_info['exchange'] == 'coinbase': exchange = Coinbase(**exchange_opts) elif account_info['exchange'] == 'coinbasepro': exchange = Coinbasepro(**exchange_opts, passphrase=str(account_info['passphrase'])) elif account_info['exchange'] == 'gemini': exchange = Gemini(**exchange_opts) elif account_info['exchange'] == 'bitmex': exchange = Bitmex(**exchange_opts) elif account_info['exchange'] == 'bittrex': exchange = Bittrex(**exchange_opts) elif account_info['exchange'] == 'poloniex': exchange = Poloniex(**exchange_opts) elif account_info['exchange'] == 'bitcoinde': exchange = Bitcoinde(**exchange_opts) elif account_info['exchange'] == 'iconomi': exchange = Iconomi(**exchange_opts) else: raise ValueError("Unknown exchange: " + account_info['exchange']) return exchange
def test_name(): exchange = Binance('binanceus1', 'a', b'a', object(), object(), uri=BINANCEUS_BASE_URL) assert exchange.location == Location.BINANCEUS assert exchange.name == 'binanceus1'
def create_test_binance( database: DBHandler, msg_aggregator: MessagesAggregator, ) -> Binance: binance = Binance( api_key=make_api_key(), secret=make_api_secret(), database=database, msg_aggregator=msg_aggregator, ) this_dir = os.path.dirname(os.path.abspath(__file__)) json_path = Path(this_dir) / 'data' / 'binance_exchange_info.json' with json_path.open('r') as f: json_data = json.loads(f.read()) binance._symbols_to_pair = create_binance_symbols_to_pair(json_data) binance.first_connection_made = True return binance
def function_scope_binance( database, inquirer, # pylint: disable=unused-argument function_scope_messages_aggregator, ): binance = Binance( api_key=make_api_key(), secret=make_api_secret(), database=database, msg_aggregator=function_scope_messages_aggregator, ) this_dir = os.path.dirname(os.path.abspath(__file__)) json_path = Path(this_dir).parent.parent / 'utils' / 'data' / 'binance_exchange_info.json' with json_path.open('r') as f: json_data = json.loads(f.read()) binance._symbols_to_pair = create_binance_symbols_to_pair(json_data) binance.first_connection_made = True return binance
def test_binance_assets_are_known( accounting_data_dir, inquirer, # pylint: disable=unused-argument ): # use a real binance instance so that we always get the latest data binance = Binance( api_key=make_api_key(), secret=make_api_secret(), user_directory=accounting_data_dir, msg_aggregator=MessagesAggregator(), ) mapping = binance.symbols_to_pair binance_assets = set() for _, pair in mapping.items(): binance_assets.add(pair.binance_base_asset) binance_assets.add(pair.binance_quote_asset) sorted_assets = sorted(binance_assets) for binance_asset in sorted_assets: try: _ = asset_from_binance(binance_asset) except UnsupportedAsset: assert binance_asset in UNSUPPORTED_BINANCE_ASSETS
def test_name(): exchange = Binance('binance1', 'a', b'a', object(), object()) assert exchange.location == Location.BINANCE assert exchange.name == 'binance1'
def test_name(): exchange = Binance('a', b'a', object(), object()) assert exchange.name == 'binance'
def test_name(): exchange = Binance('a', b'a', object(), object(), uri=BINANCE_US_BASE_URL) assert exchange.name == 'binance_us'