Skip to content

Instantly share code, notes, and snippets.

@uneasyguy
Created February 1, 2021 17:39
Show Gist options
  • Save uneasyguy/afe8fc759980baf49d225e723185eab5 to your computer and use it in GitHub Desktop.
Save uneasyguy/afe8fc759980baf49d225e723185eab5 to your computer and use it in GitHub Desktop.
def get_binance_pairs(self,**kwargs):
base_currencies = kwargs.get('base_currencies','')
quote_currencies= kwargs.get('quote_currencies','')
input_pairs = None
binance_pairs = list()
def _clean(_input):
return _input.strip().upper()
exchange_info = binance.client.Client(None,None).get_exchange_info()
symbols = exchange_info['symbols']
if base_currencies and quote_currencies:
input_pairs = [f'{_clean(x)}{_clean(y)}' for x in quote_currencies for y in base_currencies]
for symbol in symbols:
if symbol['status'] != 'TRADING':
continue
if self.futures and 'MARGIN' not in symbol['permissions']:
continue
if not self.futures and 'SPOT' not in symbol['permissions']:
continue
currency_pair = symbol['symbol']
if input_pairs and currency_pair in input_pairs:
binance_pairs.append(currency_pair)
elif base_currencies and symbol['baseAsset'] in base_currencies:
binance_pairs.append(currency_pair)
elif quote_currencies and symbol['quoteAsset'] in quote_currencies:
binance_pairs.append(currency_pair)
else:
binance_pairs.append(currency_pair)
if binance_pairs:
return binance_pairs
else:
raise ValueError('Invalid Input: Binance returned no matching currency pairs.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment