simplify exchange to make core trading w with dry_run work

This commit is contained in:
Samuel Husso 2018-02-10 14:41:49 +02:00
parent 5295723532
commit 2763076ab6
2 changed files with 30 additions and 23 deletions

View File

@ -5,10 +5,10 @@ import logging
import ccxt import ccxt
from random import randint from random import randint
from typing import List, Dict, Any, Optional from typing import List, Dict, Any, Optional
from cachetools import cached, TTLCache
import arrow import arrow
import requests import requests
from cachetools import cached, TTLCache
from freqtrade import OperationalException from freqtrade import OperationalException
from freqtrade.exchange.interface import Exchange from freqtrade.exchange.interface import Exchange
@ -142,20 +142,20 @@ def get_balances():
return _API.fetch_balance() return _API.fetch_balance()
@cached(TTLCache(maxsize=100, ttl=30))
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict: def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
return _API.get_ticker(pair, refresh) return _API.fetch_ticker(pair)
@cached(TTLCache(maxsize=100, ttl=30)) @cached(TTLCache(maxsize=100, ttl=30))
def get_ticker_history(pair: str, tick_interval) -> List[Dict]: def get_ticker_history(pair: str, tick_interval) -> List[Dict]:
# TODO: tickers need to be in format 1m,5m # TODO: tickers need to be in format 1m,5m
# fetch_ohlcv returns an [[datetime,o,h,l,c,v]] # fetch_ohlcv returns an [[datetime,o,h,l,c,v]]
_API.load_markets() if not _API.markets:
# if not _API.markets.get(pair): _API.load_markets()
# logger.warning('Pair {} doesnt exist in exchange' % pair) ohlcv = _API.fetch_ohlcv(pair, str(tick_interval)+'m')
# return []
return _API.fetch_ohlcv(pair, str(tick_interval)+'m') return ohlcv
def cancel_order(order_id: str) -> None: def cancel_order(order_id: str) -> None:
@ -177,7 +177,10 @@ def get_order(order_id: str) -> Dict:
def get_pair_detail_url(pair: str) -> str: def get_pair_detail_url(pair: str) -> str:
return _API.get_pair_detail_url(pair) # base_url = _API.urls.get('www')
# details = base_url + '/Market/Index'
# pair_url = details + '?MarketName={}'
return "PAIR {} URL".format(pair)
def get_markets() -> List[str]: def get_markets() -> List[str]:
@ -192,17 +195,20 @@ def get_name() -> str:
return _API.name return _API.name
def get_fee_maker() -> float:
return _API.fees['trading']['maker']
def get_fee_taker() -> float:
return _API.fees['trading']['taker']
def get_fee() -> float: def get_fee() -> float:
return _API.fee return _API.fees['trading']
def get_wallet_health() -> List[Dict]: def get_wallet_health() -> List[Dict]:
data = _API.request('Currencies/GetWalletHealth', api='v2') if not _API.markets:
if not data['success']: _API.load_markets()
raise OperationalException('{}'.format(data['message']))
return [{ return _API.markets
'Currency': entry['Health']['Currency'],
'IsActive': entry['Health']['IsActive'],
'LastChecked': entry['Health']['LastChecked'],
'Notice': entry['Currency'].get('Notice'),
} for entry in data['result']]

View File

@ -32,19 +32,20 @@ def refresh_whitelist(whitelist: List[str]) -> List[str]:
:param whitelist: the sorted list (based on BaseVolume) of pairs the user might want to trade :param whitelist: the sorted list (based on BaseVolume) of pairs the user might want to trade
:return: the list of pairs the user wants to trade without the one unavailable or black_listed :return: the list of pairs the user wants to trade without the one unavailable or black_listed
""" """
# TODO: rename variables
sanitized_whitelist = whitelist sanitized_whitelist = whitelist
health = exchange.get_wallet_health() health = exchange.get_wallet_health()
known_pairs = set() known_pairs = set()
for status in health: for symbol, status in health.items():
pair = '{}/{}'.format(status['Currency'], _CONF['stake_currency']) pair = '{}/{}'.format(status['base'], _CONF['stake_currency'])
# pair is not int the generated dynamic market, or in the blacklist ... ignore it # pair is not int the generated dynamic market, or in the blacklist ... ignore it
if pair not in whitelist or pair in _CONF['exchange'].get('pair_blacklist', []): if pair not in whitelist or pair in _CONF['exchange'].get('pair_blacklist', []):
continue continue
# else the pair is valid # else the pair is valid
known_pairs.add(pair) known_pairs.add(pair)
# Market is not active # Market is not active
if not status['IsActive']: if not status['active']:
sanitized_whitelist.remove(pair) sanitized_whitelist.remove(pair)
logger.info( logger.info(
'Ignoring %s from whitelist (reason: %s).', 'Ignoring %s from whitelist (reason: %s).',
@ -426,7 +427,7 @@ def create_trade(stake_amount: float, interval: int) -> bool:
pair=pair, pair=pair,
stake_amount=stake_amount, stake_amount=stake_amount,
amount=amount, amount=amount,
fee=exchange.get_fee(), fee=exchange.get_fee_maker(),
open_rate=buy_limit, open_rate=buy_limit,
open_date=datetime.utcnow(), open_date=datetime.utcnow(),
exchange=exchange.get_name().upper(), exchange=exchange.get_name().upper(),