Skip to content

Commit 1c289d7

Browse files
authored
Merge pull request #206 from itsdeka/liquidations-rest
implemented liquidations endpoint (rest)
2 parents 757cb4a + fa7d3e2 commit 1c289d7

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.0.3
2+
-) Implemented Liquidations endpoint (REST)
3+
14
2.0.2
25
-) Use private host for auth-based requests
36

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import sys
3+
import asyncio
4+
import time
5+
sys.path.append('../../../')
6+
7+
from bfxapi import Client, PUB_REST_HOST
8+
9+
bfx = Client(
10+
logLevel='INFO',
11+
rest_host=PUB_REST_HOST
12+
)
13+
14+
now = int(round(time.time() * 1000))
15+
then = now - (1000 * 60 * 60 * 24 * 10) # 10 days ago
16+
17+
async def get_liquidations():
18+
liquidations = await bfx.rest.get_liquidations(start=then, end=now)
19+
print(liquidations)
20+
21+
asyncio.get_event_loop().run_until_complete(get_liquidations())

bfxapi/rest/bfx_rest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ async def get_derivative_statuses(self, symbols):
219219
status = await self.fetch(endpoint)
220220
return status
221221

222+
async def get_liquidations(self, start, end, limit=100, sort=-1):
223+
"""
224+
Endpoint to retrieve liquidations. By default it will retrieve the most recent liquidations,
225+
but time-specific data can be retrieved using timestamps.
226+
227+
# Attributes
228+
@param start int: millisecond start time
229+
@param end int: millisecond end time
230+
@param limit int: max number of items in response (max. 500)
231+
@param sort int: if = 1 it sorts results returned with old > new
232+
@return Array [ POS_ID, MTS, SYMBOL, AMOUNT, BASE_PRICE, IS_MATCH, IS_MARKET_SOLD, PRICE_ACQUIRED ]
233+
"""
234+
endpoint = "liquidations/hist"
235+
params = "?start={}&end={}&limit={}&sort={}".format(
236+
start, end, limit, sort)
237+
liquidations = await self.fetch(endpoint, params=params)
238+
return liquidations
239+
222240
async def get_public_pulse_hist(self, end=None, limit=25):
223241
"""
224242
View the latest pulse messages. You can specify an end timestamp to view older messages.

bfxapi/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
This module contains the current version of the bfxapi lib
33
"""
44

5-
__version__ = '2.0.2'
5+
__version__ = '2.0.3'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
here = path.abspath(path.dirname(__file__))
1212
setup(
1313
name='bitfinex-api-py',
14-
version='2.0.2',
14+
version='2.0.3',
1515
description='Official Bitfinex Python API',
1616
long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction',
1717
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)