feat: implement funding trades endpoint (rest) (#135)

* feat: support funding_trades endpoint
* chore: bump version, add changelog entry
* chore: add final newline to funding_trade.py
* fix: 'maker' is now placeholder in fundingtrade

Co-authored-by: Richard Hoekstra <me@richardhoekstra.com>
Co-authored-by: Robert Kowalski <robert@bitfinex.com>
This commit is contained in:
Richard Hoekstra
2021-05-24 13:32:50 +02:00
committed by GitHub
parent 8660fac2bb
commit e7218aef92
5 changed files with 78 additions and 3 deletions

View File

@@ -1,3 +1,6 @@
1.1.15
-) Implemented Funding Trades (rest)
1.1.14
-) bfx_websockets.py ERRORS dictionary now contains a message for error number 10305

View File

@@ -19,5 +19,6 @@ from .withdraw import Withdraw
from .ticker import Ticker
from .funding_ticker import FundingTicker
from .ledger import Ledger
from .funding_trade import FundingTrade
NAME = 'models'
NAME = "models"

View File

@@ -0,0 +1,55 @@
"""
Module used to describe all of the different data types
"""
class FundingTradeModel:
"""
Enum used to index the different values in a raw funding trade array
"""
ID = 0
SYMBOL = 1
MTS_CREATE = 2
OFFER_ID = 3
AMOUNT = 4
RATE = 5
PERIOD = 6
class FundingTrade:
"""
ID integer Offer ID
SYMBOL string The currency of the offer (fUSD, etc)
MTS_CREATE int Millisecond Time Stamp when the offer was created
OFFER_ID int The ID of the offer
AMOUNT float Amount the offer is for
RATE float Rate of the offer
PERIOD int Period of the offer
"""
def __init__(self, tid, symbol, mts_create, offer_id, amount, rate, period):
self.tid = tid
self.symbol = symbol
self.mts_create = mts_create
self.offer_id = offer_id
self.amount = amount
self.rate = rate
self.period = period
@staticmethod
def from_raw_rest_trade(raw_trade):
"""
Generate a Ticker object from a raw ticker array
"""
# [[636040,"fUST",1574077528000,41237922,-100,0.0024,2,null]]
return FundingTrade(
raw_trade[FundingTradeModel.ID],
raw_trade[FundingTradeModel.SYMBOL],
raw_trade[FundingTradeModel.MTS_CREATE],
raw_trade[FundingTradeModel.OFFER_ID],
raw_trade[FundingTradeModel.AMOUNT],
raw_trade[FundingTradeModel.RATE],
raw_trade[FundingTradeModel.PERIOD]
)
def __str__(self):
return "FundingTrade '{}' x {} @ {} for {} days".format(
self.symbol, self.amount, self.rate, self.period)

View File

@@ -10,7 +10,7 @@ import datetime
from ..utils.custom_logger import CustomLogger
from ..utils.auth import generate_auth_headers, calculate_order_flags, gen_unique_cid
from ..models import Wallet, Order, Position, Trade, FundingLoan, FundingOffer
from ..models import Wallet, Order, Position, Trade, FundingLoan, FundingOffer, FundingTrade
from ..models import FundingCredit, Notification, Ledger
@@ -456,6 +456,22 @@ class BfxRest:
raw_trades = await self.post(endpoint, params=params)
return [Trade.from_raw_rest_trade(rt) for rt in raw_trades]
async def get_funding_trades(self, symbol, start, end, limit=25):
"""
Get all of the funding trades between the start and end period associated with API_KEY
- Requires authentication.
# Attributes
@param symbol string: pair symbol i.e fUSD
@param start int: millisecond start time
@param end int: millisecond end time
@param limit int: max number of items in response
@return Array <models.FundingTrade>
"""
endpoint = "auth/r/funding/trades/{}/hist".format(symbol)
raw_trades = await self.post(endpoint)
return [FundingTrade.from_raw_rest_trade(rt) for rt in raw_trades]
async def get_funding_offers(self, symbol):
"""
Get all of the funding offers associated with API_KEY - Requires authentication.

View File

@@ -2,4 +2,4 @@
This module contains the current version of the bfxapi lib
"""
__version__ = '1.1.14'
__version__ = '1.1.15'