mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
get_public_trades() orders should be sorted by [timestamp, id] (#127)
Co-authored-by: Robert Kowalski <robert@bitfinex.com> - solved the merge conflict in CHANGELOG
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
1.1.12
|
1.1.12
|
||||||
|
-) Applied clientside fix to get_public_trades() (in case of multiple trades at the same timestamp they should be ordered by id)
|
||||||
-) Invalid orders are now removed from pending_orders
|
-) Invalid orders are now removed from pending_orders
|
||||||
-) FOK orders cancelled are now removed from pending_orders
|
-) FOK orders cancelled are now removed from pending_orders
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class BfxRest:
|
|||||||
params = "?start={}&end={}&limit={}&sort={}".format(
|
params = "?start={}&end={}&limit={}&sort={}".format(
|
||||||
start, end, limit, sort)
|
start, end, limit, sort)
|
||||||
trades = await self.fetch(endpoint, params=params)
|
trades = await self.fetch(endpoint, params=params)
|
||||||
return trades
|
return sorted(trades, key=lambda x: (x[1], x[0]), reverse=True if sort == 1 else False)
|
||||||
|
|
||||||
async def get_public_books(self, symbol, precision="P0", length=25):
|
async def get_public_books(self, symbol, precision="P0", length=25):
|
||||||
"""
|
"""
|
||||||
|
|||||||
36
bfxapi/tests/test_rest_get_public_trades.py
Normal file
36
bfxapi/tests/test_rest_get_public_trades.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import asyncio
|
||||||
|
import concurrent.futures
|
||||||
|
from bfxapi import Client
|
||||||
|
|
||||||
|
bfx = Client(logLevel='DEBUG')
|
||||||
|
|
||||||
|
async def run():
|
||||||
|
start = 1617519600000
|
||||||
|
candles = await bfx.rest.get_public_candles(start=start, symbol='tBTCUSD', end=None, tf='1h', sort=1, limit=1)
|
||||||
|
candle = candles[0]
|
||||||
|
price = candle[1]
|
||||||
|
assert price == 57394.61698309
|
||||||
|
|
||||||
|
orders_ids = []
|
||||||
|
trades = await bfx.rest.get_public_trades(start=1617519600000, limit=5, symbol='tBTCUSD', end=None, sort=1)
|
||||||
|
print(trades)
|
||||||
|
for trade in trades:
|
||||||
|
orders_ids.append(trade[0])
|
||||||
|
assert orders_ids == [657815316, 657815314, 657815312, 657815311, 657815309]
|
||||||
|
|
||||||
|
# check that strictly decreasing order id condition is always respected
|
||||||
|
# check that not increasing timestamp condition is always respected
|
||||||
|
orders_ids = []
|
||||||
|
timestamps = []
|
||||||
|
trades = await bfx.rest.get_public_trades(start=1617519600000, limit=5000, symbol='tLEOUSD', end=None, sort=1)
|
||||||
|
print(trades)
|
||||||
|
for trade in trades:
|
||||||
|
orders_ids.append(trade[0])
|
||||||
|
timestamps.append(trade[1])
|
||||||
|
|
||||||
|
assert not all(x > y for x, y in zip(orders_ids, orders_ids[1:])) is False
|
||||||
|
assert not all(x >= y for x, y in zip(orders_ids, orders_ids[1:])) is False
|
||||||
|
|
||||||
|
def test_get_public_trades():
|
||||||
|
t = asyncio.ensure_future(run())
|
||||||
|
asyncio.get_event_loop().run_until_complete(t)
|
||||||
2
setup.py
2
setup.py
@@ -11,7 +11,7 @@ from os import path
|
|||||||
here = path.abspath(path.dirname(__file__))
|
here = path.abspath(path.dirname(__file__))
|
||||||
setup(
|
setup(
|
||||||
name='bitfinex-api-py',
|
name='bitfinex-api-py',
|
||||||
version='1.1.11',
|
version='1.1.12',
|
||||||
description='Official Bitfinex Python API',
|
description='Official Bitfinex Python API',
|
||||||
long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction',
|
long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction',
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
|||||||
Reference in New Issue
Block a user