From a1388ef296d7021858b3f006eb0b10c4404266cc Mon Sep 17 00:00:00 2001 From: gcarq Date: Tue, 7 Nov 2017 18:41:48 +0100 Subject: [PATCH] add tick_interval to get_ticker_history as an optional parameter --- freqtrade/exchange/__init__.py | 6 +++--- freqtrade/exchange/bittrex.py | 24 ++++++++++++++---------- freqtrade/exchange/interface.py | 3 ++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 6205138da..87bd0bbd1 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -1,7 +1,7 @@ import enum import logging from random import randint -from typing import List, Dict, Any +from typing import List, Dict, Any, Optional import arrow @@ -122,8 +122,8 @@ def get_ticker(pair: str) -> dict: return _API.get_ticker(pair) -def get_ticker_history(pair: str) -> List: - return _API.get_ticker_history(pair) +def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List: + return _API.get_ticker_history(pair, tick_interval) def cancel_order(order_id: str) -> None: diff --git a/freqtrade/exchange/bittrex.py b/freqtrade/exchange/bittrex.py index f7011ce2e..5c46df519 100644 --- a/freqtrade/exchange/bittrex.py +++ b/freqtrade/exchange/bittrex.py @@ -1,5 +1,5 @@ import logging -from typing import List, Dict +from typing import List, Dict, Optional import requests from bittrex.bittrex import Bittrex as _Bittrex @@ -20,14 +20,11 @@ class Bittrex(Exchange): BASE_URL: str = 'https://www.bittrex.com' TICKER_METHOD: str = BASE_URL + '/Api/v2.0/pub/market/GetTicks' PAIR_DETAIL_METHOD: str = BASE_URL + '/Market/Index' - # Ticker inveral - TICKER_INTERVAL: str = 'fiveMin' - # Sleep time to avoid rate limits, used in the main loop - SLEEP_TIME: float = 25 @property def sleep_time(self) -> float: - return self.SLEEP_TIME + """ Sleep time to avoid rate limits, used in the main loop """ + return 25 def __init__(self, config: dict) -> None: global _API, _EXCHANGE_CONF @@ -86,17 +83,24 @@ class Bittrex(Exchange): 'last': float(data['result']['Last']), } - def get_ticker_history(self, pair: str): - url = self.TICKER_METHOD + def get_ticker_history(self, pair: str, tick_interval: int): headers = { # TODO: Set as global setting 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' } + + if tick_interval == 1: + interval = 'oneMin' + elif tick_interval == 5: + interval = 'fiveMin' + else: + raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval)) + params = { 'marketName': pair.replace('_', '-'), - 'tickInterval': self.TICKER_INTERVAL, + 'tickInterval': interval, } - data = requests.get(url, params=params, headers=headers).json() + data = requests.get(self.TICKER_METHOD, params=params, headers=headers).json() if not data['success']: raise RuntimeError('{message} params=({pair})'.format( message=data['message'], diff --git a/freqtrade/exchange/interface.py b/freqtrade/exchange/interface.py index 904123093..44297ee6a 100644 --- a/freqtrade/exchange/interface.py +++ b/freqtrade/exchange/interface.py @@ -83,10 +83,11 @@ class Exchange(ABC): """ @abstractmethod - def get_ticker_history(self, pair: str) -> List: + def get_ticker_history(self, pair: str, tick_interval: int) -> List: """ Gets ticker history for given pair. :param pair: Pair as str, format: BTC_ETC + :param tick_interval: ticker interval in minutes :return: list, format: [ { 'O': float, (Open)