mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 07:14:20 +01:00
Rename close_order > cancel_order
This commit is contained in:
@@ -24,7 +24,7 @@ async def trade_completed(order, trade):
|
|||||||
print ("Order confirmed.")
|
print ("Order confirmed.")
|
||||||
print (order)
|
print (order)
|
||||||
print (trade)
|
print (trade)
|
||||||
await bfx.ws.close_order(order.id)
|
await bfx.ws.cancel_order(order.id)
|
||||||
|
|
||||||
@bfx.ws.on('error')
|
@bfx.ws.on('error')
|
||||||
def log_error(msg):
|
def log_error(msg):
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ bfx = Client(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@bfx.ws.on('order_snapshot')
|
@bfx.ws.on('order_snapshot')
|
||||||
async def close_all(data):
|
async def cancel_all(data):
|
||||||
await bfx.ws.close_all_orders()
|
await bfx.ws.cancel_all_orders()
|
||||||
|
|
||||||
@bfx.ws.on('order_confirmed')
|
@bfx.ws.on('order_confirmed')
|
||||||
async def trade_completed(order):
|
async def trade_completed(order):
|
||||||
@@ -24,9 +24,9 @@ async def trade_completed(order):
|
|||||||
## close the order
|
## close the order
|
||||||
# await order.close()
|
# await order.close()
|
||||||
# or
|
# or
|
||||||
# await bfx.ws.close_order(order.id)
|
# await bfx.ws.cancel_order(order.id)
|
||||||
# or
|
# or
|
||||||
# await bfx.ws.close_all_orders()
|
# await bfx.ws.cancel_all_orders()
|
||||||
|
|
||||||
@bfx.ws.on('error')
|
@bfx.ws.on('error')
|
||||||
def log_error(msg):
|
def log_error(msg):
|
||||||
|
|||||||
@@ -55,59 +55,11 @@ def _parse_trade(tData, symbol):
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BfxWebsocket(GenericWebsocket):
|
class BfxWebsocket(GenericWebsocket):
|
||||||
'''
|
"""
|
||||||
More complex websocket that heavily relies on the btfxwss module. This websocket requires
|
More complex websocket that heavily relies on the btfxwss module. This websocket requires
|
||||||
authentication and is capable of handling orders.
|
authentication and is capable of handling orders.
|
||||||
https://github.com/Crypto-toolbox/btfxwss
|
https://github.com/Crypto-toolbox/btfxwss
|
||||||
|
"""
|
||||||
Translation names:
|
|
||||||
|
|
||||||
translation table for channel names:
|
|
||||||
Data Channels
|
|
||||||
os - Orders
|
|
||||||
hos - Historical Orders
|
|
||||||
ps - Positions
|
|
||||||
hts - Trades (snapshot)
|
|
||||||
te - Trade Executed
|
|
||||||
tu - Trade Execution update
|
|
||||||
ws - Wallets
|
|
||||||
bu - Balance Info
|
|
||||||
miu - Margin Info
|
|
||||||
fiu - Funding Info
|
|
||||||
fos - Offers
|
|
||||||
hfos - Historical Offers
|
|
||||||
fcs - Credits
|
|
||||||
hfcs - Historical Credits
|
|
||||||
fls - Loans
|
|
||||||
hfls - Historical Loans
|
|
||||||
htfs - Funding Trades
|
|
||||||
n - Notifications (WIP)
|
|
||||||
|
|
||||||
Events:
|
|
||||||
- all: listen for all messages coming through
|
|
||||||
- connected: called when a connection is made
|
|
||||||
- authenticated: called when the websocket passes authentication
|
|
||||||
- notification (array): incoming account notification
|
|
||||||
- error (string): error from the websocket
|
|
||||||
- order_closed (Order, Trade): when an order has been closed
|
|
||||||
- order_new (Order, Trade): when an order has been created but not closed. Note: will
|
|
||||||
not be called if order is executed and filled instantly
|
|
||||||
- order_confirmed (Order, Trade): when an order has been submitted and received
|
|
||||||
- wallet_snapshot (string): Initial wallet balances (Fired once)
|
|
||||||
- order_snapshot (string): Initial open orders (Fired once)
|
|
||||||
- positions_snapshot (string): Initial open positions (Fired once)
|
|
||||||
- wallet_update (string): changes to the balance of wallets
|
|
||||||
- seed_candle (candleArray): initial past candle to prime strategy
|
|
||||||
- seed_trade (tradeArray): initial past trade to prime strategy
|
|
||||||
- funding_offer_snapshot:
|
|
||||||
- funding_loan_snapshot:
|
|
||||||
- funding_credit_snapshot:
|
|
||||||
- balance_update when the state of a balance is changed
|
|
||||||
- new_trade: a new trade on the market has been executed
|
|
||||||
- new_candle: a new candle has been produced
|
|
||||||
- margin_info_update: new margin information has been broadcasted
|
|
||||||
- funding_info_update: new funding information has been broadcasted
|
|
||||||
'''
|
|
||||||
|
|
||||||
ERRORS = {
|
ERRORS = {
|
||||||
10000: 'Unknown event',
|
10000: 'Unknown event',
|
||||||
@@ -436,11 +388,11 @@ class BfxWebsocket(GenericWebsocket):
|
|||||||
async def update_order(self, *args, **kwargs):
|
async def update_order(self, *args, **kwargs):
|
||||||
return await self.orderManager.update_order(*args, **kwargs)
|
return await self.orderManager.update_order(*args, **kwargs)
|
||||||
|
|
||||||
async def close_order(self, *args, **kwargs):
|
async def cancel_order(self, *args, **kwargs):
|
||||||
return await self.orderManager.close_order(*args, **kwargs)
|
return await self.orderManager.cancel_order(*args, **kwargs)
|
||||||
|
|
||||||
async def close_all_orders(self, *args, **kwargs):
|
async def cancel_all_orders(self, *args, **kwargs):
|
||||||
return await self.orderManager.close_all_orders(*args, **kwargs)
|
return await self.orderManager.cancel_all_orders(*args, **kwargs)
|
||||||
|
|
||||||
async def close_order_multi(self, *args, **kwargs):
|
async def cancel_order_multi(self, *args, **kwargs):
|
||||||
return await self.close_order_multi(*args, **kwargs)
|
return await self.cancel_order_multi(*args, **kwargs)
|
||||||
|
|||||||
@@ -197,19 +197,19 @@ class OrderManager:
|
|||||||
await self.bfxapi._send_auth_command('ou', payload)
|
await self.bfxapi._send_auth_command('ou', payload)
|
||||||
self.logger.info("Update Order order_id={} dispatched".format(orderId))
|
self.logger.info("Update Order order_id={} dispatched".format(orderId))
|
||||||
|
|
||||||
async def close_order(self, orderId, onConfirm=None, onClose=None):
|
async def cancel_order(self, orderId, onConfirm=None, onClose=None):
|
||||||
if orderId not in self.open_orders:
|
if orderId not in self.open_orders:
|
||||||
raise Exception("Order id={} is not open".format(orderId))
|
raise Exception("Order id={} is not open".format(orderId))
|
||||||
order = self.open_orders[orderId]
|
order = self.open_orders[orderId]
|
||||||
self.pending_callbacks[order.cId] = (onConfirm, onClose)
|
self.pending_callbacks[order.cId] = (onConfirm, onClose)
|
||||||
await self._close_order(orderId)
|
await self._cancel_order(orderId)
|
||||||
self.logger.info("Order cancel order_id={} dispatched".format(orderId))
|
self.logger.info("Order cancel order_id={} dispatched".format(orderId))
|
||||||
|
|
||||||
async def close_all_orders(self):
|
async def cancel_all_orders(self):
|
||||||
ids = [self.open_orders[x].id for x in self.open_orders]
|
ids = [self.open_orders[x].id for x in self.open_orders]
|
||||||
await self.close_order_multi(ids)
|
await self.cancel_order_multi(ids)
|
||||||
|
|
||||||
async def close_order_multi(self, orderIds):
|
async def cancel_order_multi(self, orderIds):
|
||||||
task_batch = []
|
task_batch = []
|
||||||
for oid in orderIds:
|
for oid in orderIds:
|
||||||
task_batch += [
|
task_batch += [
|
||||||
@@ -217,7 +217,7 @@ class OrderManager:
|
|||||||
]
|
]
|
||||||
await asyncio.wait(*[ task_batch ])
|
await asyncio.wait(*[ task_batch ])
|
||||||
|
|
||||||
async def _close_order(self, orderId):
|
async def _cancel_order(self, orderId):
|
||||||
await self.bfxapi._send_auth_command('oc', { 'id': orderId })
|
await self.bfxapi._send_auth_command('oc', { 'id': orderId })
|
||||||
|
|
||||||
async def _update(self, orderId, price=None, amount=None, delta=None, price_aux_limit=None,
|
async def _update(self, orderId, price=None, amount=None, delta=None, price_aux_limit=None,
|
||||||
|
|||||||
Reference in New Issue
Block a user