diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index b99a67809..73365969d 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -17,8 +17,8 @@ logger = logging.getLogger(__name__) def parse_ticker_dataframe(ticker: list) -> DataFrame: """ - Analyses the trend for the given pair - :param pair: pair as str in format BTC_ETH or BTC-ETH + Analyses the trend for the given ticker history + :param ticker: See exchange.get_ticker_history :return: DataFrame """ df = DataFrame(ticker) \ @@ -161,7 +161,7 @@ def plot_dataframe(dataframe: DataFrame, pair: str) -> None: if __name__ == '__main__': # Install PYQT5==5.9 manually if you want to test this helper function while True: - exchange.EXCHANGE = Bittrex({'key': '', 'secret': ''}) + exchange._API = Bittrex({'key': '', 'secret': ''}) test_pair = 'BTC_ETH' # for pair in ['BTC_ANT', 'BTC_ETH', 'BTC_GNT', 'BTC_ETC']: # get_buy_signal(pair) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index b424660bf..769d076e9 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -10,7 +10,7 @@ from freqtrade.exchange.interface import Exchange logger = logging.getLogger(__name__) # Current selected exchange -EXCHANGE: Exchange = None +_API: Exchange = None _CONF: dict = {} @@ -29,7 +29,7 @@ def init(config: dict) -> None: :param config: config to use :return: None """ - global _CONF, EXCHANGE + global _CONF, _API _CONF.update(config) @@ -45,7 +45,7 @@ def init(config: dict) -> None: except KeyError: raise RuntimeError('Exchange {} is not supported'.format(name)) - EXCHANGE = exchange_class(exchange_config) + _API = exchange_class(exchange_config) # Check if all pairs are available validate_pairs(config['exchange']['pair_whitelist']) @@ -58,62 +58,76 @@ def validate_pairs(pairs: List[str]) -> None: :param pairs: list of pairs :return: None """ - markets = EXCHANGE.get_markets() + markets = _API.get_markets() for pair in pairs: if pair not in markets: - raise RuntimeError('Pair {} is not available at {}'.format(pair, EXCHANGE.name.lower())) + raise RuntimeError('Pair {} is not available at {}'.format(pair, _API.name.lower())) def buy(pair: str, rate: float, amount: float) -> str: if _CONF['dry_run']: return 'dry_run' - return EXCHANGE.buy(pair, rate, amount) + return _API.buy(pair, rate, amount) def sell(pair: str, rate: float, amount: float) -> str: if _CONF['dry_run']: return 'dry_run' - return EXCHANGE.sell(pair, rate, amount) + return _API.sell(pair, rate, amount) def get_balance(currency: str) -> float: if _CONF['dry_run']: return 999.9 - return EXCHANGE.get_balance(currency) + return _API.get_balance(currency) def get_balances(): - return EXCHANGE.get_balances() + return _API.get_balances() def get_ticker(pair: str) -> dict: - return EXCHANGE.get_ticker(pair) + return _API.get_ticker(pair) def get_ticker_history(pair: str, minimum_date: arrow.Arrow): - return EXCHANGE.get_ticker_history(pair, minimum_date) + return _API.get_ticker_history(pair, minimum_date) def cancel_order(order_id: str) -> None: if _CONF['dry_run']: return - return EXCHANGE.cancel_order(order_id) + return _API.cancel_order(order_id) -def get_open_orders(pair: str) -> List[dict]: +def get_order(order_id: str) -> Dict: if _CONF['dry_run']: - return [] + return { - return EXCHANGE.get_open_orders(pair) + } + + return _API.get_order(order_id) def get_pair_detail_url(pair: str) -> str: - return EXCHANGE.get_pair_detail_url(pair) + return _API.get_pair_detail_url(pair) def get_markets() -> List[str]: - return EXCHANGE.get_markets() + return _API.get_markets() + + +def get_name() -> str: + return _API.name + + +def get_sleep_time() -> float: + return _API.sleep_time + + +def get_fee() -> float: + return _API.fee diff --git a/freqtrade/main.py b/freqtrade/main.py index 68277adaa..15778cb46 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -266,7 +266,7 @@ def app(config: dict) -> None: elif new_state == State.RUNNING: _process() # We need to sleep here because otherwise we would run into bittrex rate limit - time.sleep(exchange.EXCHANGE.sleep_time) + time.sleep(exchange.get_sleep_time()) old_state = new_state except RuntimeError: telegram.send_msg(