mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 23:04:21 +01:00
adds get_ledgers
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
1.1.7
|
||||||
|
- Adds rest.get_ledgers
|
||||||
|
|
||||||
1.1.6
|
1.1.6
|
||||||
- Adds 'new_ticker' websocket event stream
|
- Adds 'new_ticker' websocket event stream
|
||||||
- Adds 'ws.stop' function to kill all websocket connections
|
- Adds 'ws.stop' function to kill all websocket connections
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ from .deposit_address import DepositAddress
|
|||||||
from .withdraw import Withdraw
|
from .withdraw import Withdraw
|
||||||
from .ticker import Ticker
|
from .ticker import Ticker
|
||||||
from .funding_ticker import FundingTicker
|
from .funding_ticker import FundingTicker
|
||||||
|
from .ledger import Ledger
|
||||||
|
|
||||||
NAME = 'models'
|
NAME = 'models'
|
||||||
|
|||||||
56
bfxapi/models/ledger.py
Normal file
56
bfxapi/models/ledger.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
"""
|
||||||
|
Module used to describe a ledger object
|
||||||
|
"""
|
||||||
|
|
||||||
|
class LedgerModel:
|
||||||
|
"""
|
||||||
|
Enum used to index the location of each value in a raw array
|
||||||
|
"""
|
||||||
|
ID = 0
|
||||||
|
CURRENCY=1
|
||||||
|
MTS = 3
|
||||||
|
AMOUNT = 5
|
||||||
|
BALANCE = 6
|
||||||
|
DESCRIPTION = 8
|
||||||
|
|
||||||
|
class Ledger:
|
||||||
|
"""
|
||||||
|
ID int
|
||||||
|
CURRENCY string Currency (BTC, etc)
|
||||||
|
PLACEHOLDER
|
||||||
|
MTS int Millisecond Time Stamp of the update
|
||||||
|
PLACEHOLDER
|
||||||
|
AMOUNT string Amount of funds to ledger
|
||||||
|
BALANCE string Amount of funds to ledger
|
||||||
|
PLACEHOLDER
|
||||||
|
DESCRIPTION
|
||||||
|
"""
|
||||||
|
|
||||||
|
# [2794967447, 'USD', None, 1588004822000, None, -8.6166026, 4299.6846957, None, 'Trading fees for 4303.997301 UST (USTUSD) @ 1.001 on BFX (0.2%) on wallet exchange'],
|
||||||
|
|
||||||
|
def __init__(self, currency, mts, amount, balance, description):
|
||||||
|
self.currency = currency
|
||||||
|
self.mts = mts
|
||||||
|
self.amount = amount
|
||||||
|
self.balance = balance
|
||||||
|
self.description = description
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_raw_ledger(raw_ledger):
|
||||||
|
"""
|
||||||
|
Parse a raw ledger object into a Ledger object
|
||||||
|
|
||||||
|
@return Ledger
|
||||||
|
"""
|
||||||
|
currency = raw_ledger[LedgerModel.CURRENCY]
|
||||||
|
mts = raw_ledger[LedgerModel.MTS]
|
||||||
|
amount = raw_ledger[LedgerModel.AMOUNT]
|
||||||
|
balance = raw_ledger[LedgerModel.BALANCE]
|
||||||
|
description = raw_ledger[LedgerModel.DESCRIPTION]
|
||||||
|
return Ledger(currency, mts, amount, balance, description)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
''' Allow us to print the Ledger object in a pretty format '''
|
||||||
|
text = "Ledger <{} {} balance:{} '{}' mts={}>"
|
||||||
|
return text.format(self.amount, self.currency, self.balance,
|
||||||
|
self.description, self.mts)
|
||||||
@@ -10,7 +10,7 @@ import json
|
|||||||
from ..utils.custom_logger import CustomLogger
|
from ..utils.custom_logger import CustomLogger
|
||||||
from ..utils.auth import generate_auth_headers, calculate_order_flags, gen_unique_cid
|
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
|
||||||
from ..models import FundingCredit, Notification
|
from ..models import FundingCredit, Notification, Ledger
|
||||||
|
|
||||||
|
|
||||||
class BfxRest:
|
class BfxRest:
|
||||||
@@ -365,6 +365,21 @@ class BfxRest:
|
|||||||
credits = await self.post(endpoint, params=params)
|
credits = await self.post(endpoint, params=params)
|
||||||
return [FundingCredit.from_raw_credit(c) for c in credits]
|
return [FundingCredit.from_raw_credit(c) for c in credits]
|
||||||
|
|
||||||
|
async def get_ledgers(self, symbol, start, end, limit=25, category=None):
|
||||||
|
"""
|
||||||
|
Get all ledgers on account associated with API_KEY - Requires authentication.
|
||||||
|
See category filters here: https://docs.bitfinex.com/reference#rest-auth-ledgers
|
||||||
|
@return Array <models.Ledger>
|
||||||
|
"""
|
||||||
|
endpoint = "auth/r/ledgers/{}/hist".format(symbol)
|
||||||
|
params = "?start={}&end={}&limit={}".format(start, end, limit)
|
||||||
|
if (category):
|
||||||
|
payload = { "category": category , }
|
||||||
|
raw_ledgers = await self.post(endpoint, payload, params=params)
|
||||||
|
else:
|
||||||
|
raw_ledgers = await self.post(endpoint, params=params)
|
||||||
|
return [Ledger.from_raw_ledger(rl) for rl in raw_ledgers]
|
||||||
|
|
||||||
async def submit_funding_offer(self, symbol, amount, rate, period,
|
async def submit_funding_offer(self, symbol, amount, rate, period,
|
||||||
funding_type=FundingOffer.Type.LIMIT, hidden=False):
|
funding_type=FundingOffer.Type.LIMIT, hidden=False):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
This module contains the current version of the bfxapi lib
|
This module contains the current version of the bfxapi lib
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '1.1.6'
|
__version__ = '1.1.7'
|
||||||
|
|||||||
Reference in New Issue
Block a user