mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Merge pull request #104 from itsdeka/master (get_seed_candles)
get_seed_candles() has been fixed in a backwards compatibility manner
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
1.1.10
|
||||
- Fixed get_seed_candles() [backwards compatible]
|
||||
|
||||
1.1.9
|
||||
- Implemented PULSE endpoints (rest)
|
||||
- Updated pyee and changed deprecated class EventEmitter() -> AsyncIOEventEmitter() to make it work with all Python 3.X versions
|
||||
|
||||
@@ -6,6 +6,7 @@ import asyncio
|
||||
import aiohttp
|
||||
import time
|
||||
import json
|
||||
import datetime
|
||||
|
||||
from ..utils.custom_logger import CustomLogger
|
||||
from ..utils.auth import generate_auth_headers, calculate_order_flags, gen_unique_cid
|
||||
@@ -71,27 +72,27 @@ class BfxRest:
|
||||
# Public Data #
|
||||
##################################################
|
||||
|
||||
async def get_seed_candles(self, symbol, tf='1m'):
|
||||
async def get_seed_candles(self, symbol, tf='1m', start=None, end=None, limit=10000, sort=0):
|
||||
"""
|
||||
Used by the honey framework, this function gets the last 4k candles.
|
||||
Get all of the seed candles between the start and end period.
|
||||
# Attributes
|
||||
@param symbol symbol string: pair symbol i.e tBTCUSD
|
||||
@param start int: millisecond start time
|
||||
@param end int: millisecond end time
|
||||
@param tf int: timeframe inbetween candles i.e 1m (min), ..., 1D (day),
|
||||
... 1M (month)
|
||||
@param limit int: max number of items in response (max. 10000)
|
||||
@param sort int: if = 1 it sorts results returned with old > new
|
||||
@return Array [ MTS, OPEN, CLOSE, HIGH, LOW, VOLUME ]
|
||||
"""
|
||||
endpoint = 'candles/trade:{}:{}/hist?limit=5000&_bfx=1'.format(tf, symbol)
|
||||
time_difference = (1000 * 60) * 5000
|
||||
# get now to the nearest min
|
||||
now = int(round((time.time() // 60 * 60) * 1000))
|
||||
task_batch = []
|
||||
for x in range(0, 10):
|
||||
start = x * time_difference
|
||||
end = now - (x * time_difference) - time_difference
|
||||
e2 = endpoint + '&start={}&end={}'.format(start, end)
|
||||
task_batch += [asyncio.ensure_future(self.fetch(e2))]
|
||||
|
||||
if not start and not end:
|
||||
start = 0
|
||||
end = int(round((time.time() // 60 * 60) * 1000))
|
||||
|
||||
endpoint = f'candles/trade:{tf}:{symbol}/hist?limit={limit}&start={start}&end={end}&sort={sort}'
|
||||
self.logger.info("Downloading seed candles from Bitfinex...")
|
||||
# call all fetch requests async
|
||||
done, _ = await asyncio.wait(*[task_batch])
|
||||
candles = []
|
||||
for task in done:
|
||||
candles += task.result()
|
||||
candles.sort(key=lambda x: x[0], reverse=True)
|
||||
candles = await self.fetch(endpoint)
|
||||
self.logger.info("Downloaded {} candles.".format(len(candles)))
|
||||
return candles
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
This module contains the current version of the bfxapi lib
|
||||
"""
|
||||
|
||||
__version__ = '1.1.9'
|
||||
__version__ = '1.1.10'
|
||||
|
||||
Reference in New Issue
Block a user