Removing old data
This commit is contained in:
parent
4f29e16a50
commit
3c2e3f1f56
@ -14,6 +14,7 @@ _API_V2: _Bittrex = None
|
|||||||
_EXCHANGE_CONF: dict = {}
|
_EXCHANGE_CONF: dict = {}
|
||||||
_cache: dict = dict()
|
_cache: dict = dict()
|
||||||
|
|
||||||
|
|
||||||
class Bittrex(Exchange):
|
class Bittrex(Exchange):
|
||||||
"""
|
"""
|
||||||
Bittrex API wrapper.
|
Bittrex API wrapper.
|
||||||
@ -22,7 +23,6 @@ class Bittrex(Exchange):
|
|||||||
BASE_URL: str = 'https://www.bittrex.com'
|
BASE_URL: str = 'https://www.bittrex.com'
|
||||||
PAIR_DETAIL_METHOD: str = BASE_URL + '/Market/Index'
|
PAIR_DETAIL_METHOD: str = BASE_URL + '/Market/Index'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, config: dict) -> None:
|
def __init__(self, config: dict) -> None:
|
||||||
global _API, _API_V2, _EXCHANGE_CONF
|
global _API, _API_V2, _EXCHANGE_CONF
|
||||||
|
|
||||||
@ -48,21 +48,17 @@ class Bittrex(Exchange):
|
|||||||
def buy(self, pair: str, rate: float, amount: float) -> str:
|
def buy(self, pair: str, rate: float, amount: float) -> str:
|
||||||
data = _API.buy_limit(pair.replace('_', '-'), amount, rate)
|
data = _API.buy_limit(pair.replace('_', '-'), amount, rate)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
raise OperationalException(
|
||||||
message=data['message'],
|
'{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
pair=pair,
|
message=data['message'], pair=pair, rate=rate, amount=amount))
|
||||||
rate=rate,
|
|
||||||
amount=amount))
|
|
||||||
return data['result']['uuid']
|
return data['result']['uuid']
|
||||||
|
|
||||||
def sell(self, pair: str, rate: float, amount: float) -> str:
|
def sell(self, pair: str, rate: float, amount: float) -> str:
|
||||||
data = _API.sell_limit(pair.replace('_', '-'), amount, rate)
|
data = _API.sell_limit(pair.replace('_', '-'), amount, rate)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
raise OperationalException(
|
||||||
message=data['message'],
|
'{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
pair=pair,
|
message=data['message'], pair=pair, rate=rate, amount=amount))
|
||||||
rate=rate,
|
|
||||||
amount=amount))
|
|
||||||
return data['result']['uuid']
|
return data['result']['uuid']
|
||||||
|
|
||||||
def get_balance(self, currency: str) -> float:
|
def get_balance(self, currency: str) -> float:
|
||||||
@ -76,7 +72,9 @@ class Bittrex(Exchange):
|
|||||||
def get_balances(self):
|
def get_balances(self):
|
||||||
data = _API.get_balances()
|
data = _API.get_balances()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException(
|
||||||
|
'{message}'.format(
|
||||||
|
message=data['message']))
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
def get_ticker(self, pair: str) -> dict:
|
def get_ticker(self, pair: str) -> dict:
|
||||||
@ -99,14 +97,14 @@ class Bittrex(Exchange):
|
|||||||
'last': float(data['result']['Last']),
|
'last': float(data['result']['Last']),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
|
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
|
||||||
if tick_interval == 1:
|
if tick_interval == 1:
|
||||||
interval = 'oneMin'
|
interval = 'oneMin'
|
||||||
elif tick_interval == 5:
|
elif tick_interval == 5:
|
||||||
interval = 'fiveMin'
|
interval = 'fiveMin'
|
||||||
else:
|
else:
|
||||||
raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval))
|
raise ValueError(
|
||||||
|
'Cannot parse tick_interval: {}'.format(tick_interval))
|
||||||
if pair in _cache.keys():
|
if pair in _cache.keys():
|
||||||
# pair is in cache retriev lastest candle
|
# pair is in cache retriev lastest candle
|
||||||
sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval)
|
sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval)
|
||||||
@ -116,19 +114,23 @@ class Bittrex(Exchange):
|
|||||||
pair=pair))
|
pair=pair))
|
||||||
data = _cache[pair]
|
data = _cache[pair]
|
||||||
# this is the latest results we had
|
# this is the latest results we had
|
||||||
old_ticker = data['result'][-1];
|
old_ticker = data['result'][-1]
|
||||||
# check timestamp is newer ...
|
# check timestamp is newer ...
|
||||||
if (sdata['result'][0]['T'] > old_ticker['T']):
|
if (sdata['result'][0]['T'] > old_ticker['T']):
|
||||||
data['result'].append(sdata['result'][0])
|
data['result'].append(sdata['result'][0])
|
||||||
|
# avoid habinf to much data to analyze
|
||||||
|
data['result'].pop(0)
|
||||||
elif (sdata['result'][0]['T'] == old_ticker['T']):
|
elif (sdata['result'][0]['T'] == old_ticker['T']):
|
||||||
#if volume has changed, update the latest result with the new one
|
# if volume has changed, update the latest result with the new
|
||||||
|
# one
|
||||||
if (sdata['result'][0]['V'] > old_ticker['V']):
|
if (sdata['result'][0]['V'] > old_ticker['V']):
|
||||||
data['result'][-1] = sdata['result'][0]
|
data['result'][-1] = sdata['result'][0]
|
||||||
else:
|
else:
|
||||||
data = _API_V2.get_candles(pair.replace('_', '-'), interval)
|
data = _API_V2.get_candles(pair.replace('_', '-'), interval)
|
||||||
# Update the value in cache
|
# Update the value in cache
|
||||||
_cache[pair] = data
|
_cache[pair] = data
|
||||||
# These sanity check are necessary because bittrex cannot keep their API stable.
|
# These sanity check are necessary because bittrex cannot keep their
|
||||||
|
# API stable.
|
||||||
if not data.get('result'):
|
if not data.get('result'):
|
||||||
raise ContentDecodingError('{message} params=({pair})'.format(
|
raise ContentDecodingError('{message} params=({pair})'.format(
|
||||||
message='Got invalid response from bittrex',
|
message='Got invalid response from bittrex',
|
||||||
@ -137,7 +139,8 @@ class Bittrex(Exchange):
|
|||||||
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
|
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
|
||||||
for tick in data['result']:
|
for tick in data['result']:
|
||||||
if prop not in tick.keys():
|
if prop not in tick.keys():
|
||||||
raise ContentDecodingError('{message} params=({pair})'.format(
|
raise ContentDecodingError(
|
||||||
|
'{message} params=({pair})'.format(
|
||||||
message='Required property {} not present in response'.format(prop),
|
message='Required property {} not present in response'.format(prop),
|
||||||
pair=pair))
|
pair=pair))
|
||||||
|
|
||||||
@ -174,24 +177,31 @@ class Bittrex(Exchange):
|
|||||||
order_id=order_id))
|
order_id=order_id))
|
||||||
|
|
||||||
def get_pair_detail_url(self, pair: str) -> str:
|
def get_pair_detail_url(self, pair: str) -> str:
|
||||||
return self.PAIR_DETAIL_METHOD + '?MarketName={}'.format(pair.replace('_', '-'))
|
return self.PAIR_DETAIL_METHOD + \
|
||||||
|
'?MarketName={}'.format(pair.replace('_', '-'))
|
||||||
|
|
||||||
def get_markets(self) -> List[str]:
|
def get_markets(self) -> List[str]:
|
||||||
data = _API.get_markets()
|
data = _API.get_markets()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException(
|
||||||
|
'{message}'.format(
|
||||||
|
message=data['message']))
|
||||||
return [m['MarketName'].replace('-', '_') for m in data['result']]
|
return [m['MarketName'].replace('-', '_') for m in data['result']]
|
||||||
|
|
||||||
def get_market_summaries(self) -> List[Dict]:
|
def get_market_summaries(self) -> List[Dict]:
|
||||||
data = _API.get_market_summaries()
|
data = _API.get_market_summaries()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException(
|
||||||
|
'{message}'.format(
|
||||||
|
message=data['message']))
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
def get_wallet_health(self) -> List[Dict]:
|
def get_wallet_health(self) -> List[Dict]:
|
||||||
data = _API_V2.get_wallet_health()
|
data = _API_V2.get_wallet_health()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException(
|
||||||
|
'{message}'.format(
|
||||||
|
message=data['message']))
|
||||||
return [{
|
return [{
|
||||||
'Currency': entry['Health']['Currency'],
|
'Currency': entry['Health']['Currency'],
|
||||||
'IsActive': entry['Health']['IsActive'],
|
'IsActive': entry['Health']['IsActive'],
|
||||||
|
Loading…
Reference in New Issue
Block a user