lowercase variables

This commit is contained in:
xmatthias 2018-06-18 22:09:46 +02:00
parent c31519fdb2
commit ef53134499
2 changed files with 22 additions and 22 deletions

View File

@ -44,11 +44,11 @@ class Exchange(object):
# Current selected exchange # Current selected exchange
_api: ccxt.Exchange = None _api: ccxt.Exchange = None
_CONF: Dict = {} _conf: Dict = {}
_CACHED_TICKER: Dict[str, Any] = {} _cached_ticker: Dict[str, Any] = {}
# Holds all open sell orders for dry_run # Holds all open sell orders for dry_run
_DRY_RUN_OPEN_ORDERS: Dict[str, Any] = {} _dry_run_open_orders: Dict[str, Any] = {}
def __init__(self, config: dict) -> None: def __init__(self, config: dict) -> None:
""" """
@ -57,7 +57,7 @@ class Exchange(object):
exchange and pairs are valid. exchange and pairs are valid.
:return: None :return: None
""" """
self._CONF.update(config) self._conf.update(config)
if config['dry_run']: if config['dry_run']:
logger.info('Instance is running with dry_run enabled') logger.info('Instance is running with dry_run enabled')
@ -115,7 +115,7 @@ class Exchange(object):
logger.warning('Unable to validate pairs (assuming they are correct). Reason: %s', e) logger.warning('Unable to validate pairs (assuming they are correct). Reason: %s', e)
return return
stake_cur = self._CONF['stake_currency'] stake_cur = self._conf['stake_currency']
for pair in pairs: for pair in pairs:
# Note: ccxt has BaseCurrency/QuoteCurrency format for pairs # Note: ccxt has BaseCurrency/QuoteCurrency format for pairs
# TODO: add a support for having coins in BTC/USDT format # TODO: add a support for having coins in BTC/USDT format
@ -136,9 +136,9 @@ class Exchange(object):
return endpoint in self._api.has and self._api.has[endpoint] return endpoint in self._api.has and self._api.has[endpoint]
def buy(self, pair: str, rate: float, amount: float) -> Dict: def buy(self, pair: str, rate: float, amount: float) -> Dict:
if self._CONF['dry_run']: if self._conf['dry_run']:
order_id = f'dry_run_buy_{randint(0, 10**6)}' order_id = f'dry_run_buy_{randint(0, 10**6)}'
self._DRY_RUN_OPEN_ORDERS[order_id] = { self._dry_run_open_orders[order_id] = {
'pair': pair, 'pair': pair,
'price': rate, 'price': rate,
'amount': amount, 'amount': amount,
@ -170,9 +170,9 @@ class Exchange(object):
raise OperationalException(e) raise OperationalException(e)
def sell(self, pair: str, rate: float, amount: float) -> Dict: def sell(self, pair: str, rate: float, amount: float) -> Dict:
if self._CONF['dry_run']: if self._conf['dry_run']:
order_id = f'dry_run_sell_{randint(0, 10**6)}' order_id = f'dry_run_sell_{randint(0, 10**6)}'
self._DRY_RUN_OPEN_ORDERS[order_id] = { self._dry_run_open_orders[order_id] = {
'pair': pair, 'pair': pair,
'price': rate, 'price': rate,
'amount': amount, 'amount': amount,
@ -204,7 +204,7 @@ class Exchange(object):
@retrier @retrier
def get_balance(self, currency: str) -> float: def get_balance(self, currency: str) -> float:
if self._CONF['dry_run']: if self._conf['dry_run']:
return 999.9 return 999.9
# ccxt exception is already handled by get_balances # ccxt exception is already handled by get_balances
@ -217,7 +217,7 @@ class Exchange(object):
@retrier @retrier
def get_balances(self) -> dict: def get_balances(self) -> dict:
if self._CONF['dry_run']: if self._conf['dry_run']:
return {} return {}
try: try:
@ -251,11 +251,11 @@ class Exchange(object):
@retrier @retrier
def get_ticker(self, pair: str, refresh: Optional[bool] = True) -> dict: def get_ticker(self, pair: str, refresh: Optional[bool] = True) -> dict:
if refresh or pair not in self._CACHED_TICKER.keys(): if refresh or pair not in self._cached_ticker.keys():
try: try:
data = self._api.fetch_ticker(pair) data = self._api.fetch_ticker(pair)
try: try:
self._CACHED_TICKER[pair] = { self._cached_ticker[pair] = {
'bid': float(data['bid']), 'bid': float(data['bid']),
'ask': float(data['ask']), 'ask': float(data['ask']),
} }
@ -269,7 +269,7 @@ class Exchange(object):
raise OperationalException(e) raise OperationalException(e)
else: else:
logger.info("returning cached ticker-data for %s", pair) logger.info("returning cached ticker-data for %s", pair)
return self._CACHED_TICKER[pair] return self._cached_ticker[pair]
@retrier @retrier
def get_ticker_history(self, pair: str, tick_interval: str, def get_ticker_history(self, pair: str, tick_interval: str,
@ -318,7 +318,7 @@ class Exchange(object):
@retrier @retrier
def cancel_order(self, order_id: str, pair: str) -> None: def cancel_order(self, order_id: str, pair: str) -> None:
if self._CONF['dry_run']: if self._conf['dry_run']:
return return
try: try:
@ -334,8 +334,8 @@ class Exchange(object):
@retrier @retrier
def get_order(self, order_id: str, pair: str) -> Dict: def get_order(self, order_id: str, pair: str) -> Dict:
if self._CONF['dry_run']: if self._conf['dry_run']:
order = self._DRY_RUN_OPEN_ORDERS[order_id] order = self._dry_run_open_orders[order_id]
order.update({ order.update({
'id': order_id 'id': order_id
}) })
@ -353,7 +353,7 @@ class Exchange(object):
@retrier @retrier
def get_trades_for_order(self, order_id: str, pair: str, since: datetime) -> List: def get_trades_for_order(self, order_id: str, pair: str, since: datetime) -> List:
if self._CONF['dry_run']: if self._conf['dry_run']:
return [] return []
if not self.exchange_has('fetchMyTrades'): if not self.exchange_has('fetchMyTrades'):
return [] return []

View File

@ -336,9 +336,9 @@ def test_get_ticker(default_conf, mocker):
assert ticker['bid'] == 0.5 assert ticker['bid'] == 0.5
assert ticker['ask'] == 1 assert ticker['ask'] == 1
assert 'ETH/BTC' in exchange._CACHED_TICKER assert 'ETH/BTC' in exchange._cached_ticker
assert exchange._CACHED_TICKER['ETH/BTC']['bid'] == 0.5 assert exchange._cached_ticker['ETH/BTC']['bid'] == 0.5
assert exchange._CACHED_TICKER['ETH/BTC']['ask'] == 1 assert exchange._cached_ticker['ETH/BTC']['ask'] == 1
# Test caching # Test caching
api_mock.fetch_ticker = MagicMock() api_mock.fetch_ticker = MagicMock()
@ -541,7 +541,7 @@ def test_get_order(default_conf, mocker):
order = MagicMock() order = MagicMock()
order.myid = 123 order.myid = 123
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
exchange._DRY_RUN_OPEN_ORDERS['X'] = order exchange._dry_run_open_orders['X'] = order
print(exchange.get_order('X', 'TKN/BTC')) print(exchange.get_order('X', 'TKN/BTC'))
assert exchange.get_order('X', 'TKN/BTC').myid == 123 assert exchange.get_order('X', 'TKN/BTC').myid == 123