mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2026-01-06 07:24:19 +01:00
fixed trades handling error
added new_user_trade use to examples updated docs
This commit is contained in:
@@ -20,6 +20,10 @@ def log_candle(candle):
|
||||
def log_trade(trade):
|
||||
print ("New trade: {}".format(trade))
|
||||
|
||||
@bfx.ws.on('new_user_trade')
|
||||
def log_user_trade(trade):
|
||||
print ("New user trade: {}".format(trade))
|
||||
|
||||
async def start():
|
||||
await bfx.ws.subscribe('candles', 'tBTCUSD', timeframe='1m')
|
||||
await bfx.ws.subscribe('trades', 'tBTCUSD')
|
||||
|
||||
@@ -67,6 +67,38 @@ def _parse_trade(tData, symbol):
|
||||
}
|
||||
|
||||
|
||||
def _parse_user_trade(tData):
|
||||
return {
|
||||
'id': tData[0],
|
||||
'symbol': tData[1],
|
||||
'mts_create': tData[2],
|
||||
'order_id': tData[3],
|
||||
'exec_amount': tData[4],
|
||||
'exec_price': tData[5],
|
||||
'order_type': tData[6],
|
||||
'order_price': tData[7],
|
||||
'maker': tData[8],
|
||||
'cid': tData[11],
|
||||
}
|
||||
|
||||
|
||||
def _parse_user_trade_update(tData):
|
||||
return {
|
||||
'id': tData[0],
|
||||
'symbol': tData[1],
|
||||
'mts_create': tData[2],
|
||||
'order_id': tData[3],
|
||||
'exec_amount': tData[4],
|
||||
'exec_price': tData[5],
|
||||
'order_type': tData[6],
|
||||
'order_price': tData[7],
|
||||
'maker': tData[8],
|
||||
'fee': tData[9],
|
||||
'fee_currency': tData[10],
|
||||
'cid': tData[11],
|
||||
}
|
||||
|
||||
|
||||
def _parse_deriv_status_update(sData, symbol):
|
||||
return {
|
||||
'symbol': symbol,
|
||||
@@ -141,6 +173,7 @@ class BfxWebsocket(GenericWebsocket):
|
||||
- `funding_credit_snapshot` (array): Opening funding credit balances
|
||||
- `balance_update` (array): When the state of a balance is changed
|
||||
- `new_trade` (array): A new trade on the market has been executed
|
||||
- `new_user_trade` (array): A new - your - trade has been executed
|
||||
- `new_ticker` (Ticker|FundingTicker): A new ticker update has been published
|
||||
- `new_funding_ticker` (FundingTicker): A new funding ticker update has been published
|
||||
- `new_trading_ticker` (Ticker): A new trading ticker update has been published
|
||||
@@ -284,6 +317,11 @@ class BfxWebsocket(GenericWebsocket):
|
||||
symbol = self.subscriptionManager.get(data[0]).symbol
|
||||
tradeObj = _parse_trade(tData, symbol)
|
||||
self._emit('trade_update', tradeObj)
|
||||
else:
|
||||
# user trade
|
||||
# [0,"tu",[738045455,"tTESTBTC:TESTUSD",1622169615771,66635385225,0.001,38175,"EXCHANGE LIMIT",39000,-1,-0.000002,"TESTBTC",1622169615685]]
|
||||
tradeObj = _parse_user_trade_update(tData)
|
||||
self._emit('user_trade_update', tradeObj)
|
||||
|
||||
async def _trade_executed_handler(self, data):
|
||||
tData = data[2]
|
||||
@@ -292,6 +330,11 @@ class BfxWebsocket(GenericWebsocket):
|
||||
symbol = self.subscriptionManager.get(data[0]).symbol
|
||||
tradeObj = _parse_trade(tData, symbol)
|
||||
self._emit('new_trade', tradeObj)
|
||||
else:
|
||||
# user trade
|
||||
# [0, 'te', [37558151, 'tBTCUSD', 1643542688513, 1512164914, 0.0001, 30363, 'EXCHANGE MARKET', 100000, -1, None, None, 1643542688390]]
|
||||
tradeObj = _parse_user_trade(tData)
|
||||
self._emit('new_user_trade', tradeObj)
|
||||
|
||||
async def _wallet_update_handler(self, data):
|
||||
# [0,"wu",["exchange","USD",89134.66933283,0]]
|
||||
|
||||
@@ -76,10 +76,12 @@ https://github.com/Crypto-toolbox/btfxwss
|
||||
- `funding_credit_snapshot` (array): Opening funding credit balances
|
||||
- `balance_update` (array): When the state of a balance is changed
|
||||
- `new_trade` (array): A new trade on the market has been executed
|
||||
- `new_user_trade` (array): A new - your - trade has been executed
|
||||
- `new_ticker` (Ticker|FundingTicker): A new ticker update has been published
|
||||
- `new_funding_ticker` (FundingTicker): A new funding ticker update has been published
|
||||
- `new_trading_ticker` (Ticker): A new trading ticker update has been published
|
||||
- `trade_update` (array): A trade on the market has been updated
|
||||
- `user_trade_update` (array): A - your - trade has been updated
|
||||
- `new_candle` (array): A new candle has been produced
|
||||
- `margin_info_updates` (array): New margin information has been broadcasted
|
||||
- `funding_info_updates` (array): New funding information has been broadcasted
|
||||
|
||||
Reference in New Issue
Block a user