implement get_markets
This commit is contained in:
parent
360143b8cf
commit
6f05648087
25
exchange.py
25
exchange.py
@ -25,7 +25,9 @@ class ApiWrapper(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, config: dict):
|
def __init__(self, config: dict):
|
||||||
"""
|
"""
|
||||||
Initializes the ApiWrapper with the given config, it does not validate those values.
|
Initializes the ApiWrapper with the given config,
|
||||||
|
it does basic validation whether the specified
|
||||||
|
exchange and pairs are valid.
|
||||||
:param config: dict
|
:param config: dict
|
||||||
"""
|
"""
|
||||||
self.dry_run = config['dry_run']
|
self.dry_run = config['dry_run']
|
||||||
@ -43,6 +45,13 @@ class ApiWrapper(object):
|
|||||||
self.api = Bittrex(api_key=config['bittrex']['key'], api_secret=config['bittrex']['secret'])
|
self.api = Bittrex(api_key=config['bittrex']['key'], api_secret=config['bittrex']['secret'])
|
||||||
else:
|
else:
|
||||||
self.api = None
|
self.api = None
|
||||||
|
raise RuntimeError('No exchange specified. Aborting!')
|
||||||
|
|
||||||
|
# Check if all pairs are available
|
||||||
|
markets = self.get_markets()
|
||||||
|
for pair in config[self.exchange.name.lower()]['pair_whitelist']:
|
||||||
|
if pair not in markets:
|
||||||
|
raise RuntimeError('Pair {} is not available at Poloniex'.format(pair))
|
||||||
|
|
||||||
def buy(self, pair: str, rate: float, amount: float) -> str:
|
def buy(self, pair: str, rate: float, amount: float) -> str:
|
||||||
"""
|
"""
|
||||||
@ -171,6 +180,20 @@ class ApiWrapper(object):
|
|||||||
elif self.exchange == Exchange.BITTREX:
|
elif self.exchange == Exchange.BITTREX:
|
||||||
return 'https://bittrex.com/Market/Index?MarketName={}'.format(pair.replace('_', '-'))
|
return 'https://bittrex.com/Market/Index?MarketName={}'.format(pair.replace('_', '-'))
|
||||||
|
|
||||||
|
def get_markets(self) -> List[str]:
|
||||||
|
"""
|
||||||
|
Returns all available markets
|
||||||
|
:return: list of all available pairs
|
||||||
|
"""
|
||||||
|
if self.exchange == Exchange.POLONIEX:
|
||||||
|
# TODO: implement
|
||||||
|
raise NotImplemented('Not implemented')
|
||||||
|
elif self.exchange == Exchange. BITTREX:
|
||||||
|
data = self.api.get_markets()
|
||||||
|
if not data['success']:
|
||||||
|
raise RuntimeError('BITTREX: {}'.format(data['message']))
|
||||||
|
return [m['MarketName'].replace('-', '_') for m in data['result']]
|
||||||
|
|
||||||
|
|
||||||
@synchronized
|
@synchronized
|
||||||
def get_exchange_api(conf: dict) -> ApiWrapper:
|
def get_exchange_api(conf: dict) -> ApiWrapper:
|
||||||
|
Loading…
Reference in New Issue
Block a user