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
from random import randint
from typing import List, Dict, Any, Optional
from cachetools import cached, TTLCache
import arrow
import requests
from cachetools import cached, TTLCache
from freqtrade import OperationalException
from freqtrade.exchange.interface import Exchange
@ -142,20 +142,20 @@ def get_balances():
return _API.fetch_balance()
@cached(TTLCache(maxsize=100, ttl=30))
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))
def get_ticker_history(pair: str, tick_interval) -> List[Dict]:
# TODO: tickers need to be in format 1m,5m
# fetch_ohlcv returns an [[datetime,o,h,l,c,v]]
_API.load_markets()
# if not _API.markets.get(pair):
# logger.warning('Pair {} doesnt exist in exchange' % pair)
# return []
return _API.fetch_ohlcv(pair, str(tick_interval)+'m')
if not _API.markets:
_API.load_markets()
ohlcv = _API.fetch_ohlcv(pair, str(tick_interval)+'m')
return ohlcv
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:
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]:
@ -192,17 +195,20 @@ def get_name() -> str:
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:
return _API.fee
return _API.fees['trading']
def get_wallet_health() -> List[Dict]:
data = _API.request('Currencies/GetWalletHealth', api='v2')
if not data['success']:
raise OperationalException('{}'.format(data['message']))
return [{
'Currency': entry['Health']['Currency'],
'IsActive': entry['Health']['IsActive'],
'LastChecked': entry['Health']['LastChecked'],
'Notice': entry['Currency'].get('Notice'),
} for entry in data['result']]
if not _API.markets:
_API.load_markets()
return _API.markets

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
:return: the list of pairs the user wants to trade without the one unavailable or black_listed
"""
# TODO: rename variables
sanitized_whitelist = whitelist
health = exchange.get_wallet_health()
known_pairs = set()
for status in health:
pair = '{}/{}'.format(status['Currency'], _CONF['stake_currency'])
for symbol, status in health.items():
pair = '{}/{}'.format(status['base'], _CONF['stake_currency'])
# 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', []):
continue
# else the pair is valid
known_pairs.add(pair)
# Market is not active
if not status['IsActive']:
if not status['active']:
sanitized_whitelist.remove(pair)
logger.info(
'Ignoring %s from whitelist (reason: %s).',
@ -426,7 +427,7 @@ def create_trade(stake_amount: float, interval: int) -> bool:
pair=pair,
stake_amount=stake_amount,
amount=amount,
fee=exchange.get_fee(),
fee=exchange.get_fee_maker(),
open_rate=buy_limit,
open_date=datetime.utcnow(),
exchange=exchange.get_name().upper(),