add tick_interval to get_ticker_history as an optional parameter
This commit is contained in:
parent
ddc7c94a1d
commit
a1388ef296
@ -1,7 +1,7 @@
|
|||||||
import enum
|
import enum
|
||||||
import logging
|
import logging
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Any, Optional
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
@ -122,8 +122,8 @@ def get_ticker(pair: str) -> dict:
|
|||||||
return _API.get_ticker(pair)
|
return _API.get_ticker(pair)
|
||||||
|
|
||||||
|
|
||||||
def get_ticker_history(pair: str) -> List:
|
def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List:
|
||||||
return _API.get_ticker_history(pair)
|
return _API.get_ticker_history(pair, tick_interval)
|
||||||
|
|
||||||
|
|
||||||
def cancel_order(order_id: str) -> None:
|
def cancel_order(order_id: str) -> None:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import List, Dict
|
from typing import List, Dict, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bittrex.bittrex import Bittrex as _Bittrex
|
from bittrex.bittrex import Bittrex as _Bittrex
|
||||||
@ -20,14 +20,11 @@ class Bittrex(Exchange):
|
|||||||
BASE_URL: str = 'https://www.bittrex.com'
|
BASE_URL: str = 'https://www.bittrex.com'
|
||||||
TICKER_METHOD: str = BASE_URL + '/Api/v2.0/pub/market/GetTicks'
|
TICKER_METHOD: str = BASE_URL + '/Api/v2.0/pub/market/GetTicks'
|
||||||
PAIR_DETAIL_METHOD: str = BASE_URL + '/Market/Index'
|
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
|
@property
|
||||||
def sleep_time(self) -> float:
|
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:
|
def __init__(self, config: dict) -> None:
|
||||||
global _API, _EXCHANGE_CONF
|
global _API, _EXCHANGE_CONF
|
||||||
@ -86,17 +83,24 @@ class Bittrex(Exchange):
|
|||||||
'last': float(data['result']['Last']),
|
'last': float(data['result']['Last']),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_ticker_history(self, pair: str):
|
def get_ticker_history(self, pair: str, tick_interval: int):
|
||||||
url = self.TICKER_METHOD
|
|
||||||
headers = {
|
headers = {
|
||||||
# TODO: Set as global setting
|
# 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'
|
'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 = {
|
params = {
|
||||||
'marketName': pair.replace('_', '-'),
|
'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']:
|
if not data['success']:
|
||||||
raise RuntimeError('{message} params=({pair})'.format(
|
raise RuntimeError('{message} params=({pair})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
|
@ -83,10 +83,11 @@ class Exchange(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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.
|
Gets ticker history for given pair.
|
||||||
:param pair: Pair as str, format: BTC_ETC
|
:param pair: Pair as str, format: BTC_ETC
|
||||||
|
:param tick_interval: ticker interval in minutes
|
||||||
:return: list, format: [
|
:return: list, format: [
|
||||||
{
|
{
|
||||||
'O': float, (Open)
|
'O': float, (Open)
|
||||||
|
Loading…
Reference in New Issue
Block a user