basana.external.binance.cross_margin¶
- class basana.external.binance.cross_margin.Account(cli, ws_mgr)¶
Cross margin account.
- Parameters:
cli (CrossMarginAccount)
ws_mgr (WebsocketManager)
- async cancel_oco_order(pair, order_list_id=None, client_order_list_id=None)¶
Cancels an OCO order.
If the order can’t be canceled a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
pair (Pair) – The trading pair.
order_list_id (str | None) – The order list id.
client_order_list_id (str | None) – A client id for the order list.
- Return type:
Note
Either order_list_id or client_order_list_id should be set, but not both.
- async cancel_order(pair, order_id=None, client_order_id=None)¶
Cancels an order.
If the order can’t be canceled a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
pair (Pair) – The trading pair.
order_id (str | None) – The order id.
client_order_id (str | None) – The client order id.
- Return type:
Note
Either order_id or client_order_id should be set, but not both.
- async create_limit_order(operation, pair, amount, limit_price, side_effect_type='NO_SIDE_EFFECT', time_in_force='GTC', client_order_id=None, **kwargs)¶
Creates a limit order.
Check https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade for more information. If the order can’t be created a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell in base units.
limit_price (Decimal) – The limit price.
side_effect_type (str) – One of NO_SIDE_EFFECT, MARGIN_BUY or AUTO_REPAY.
time_in_force (str) – The time in force.
client_order_id (str | None) – A client order id.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async create_market_order(operation, pair, amount=None, quote_amount=None, client_order_id=None, side_effect_type='NO_SIDE_EFFECT', **kwargs)¶
Creates a market order.
Check https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade for more information. If the order can’t be created a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal | None) – The amount to buy/sell in base units.
quote_amount (Decimal | None) – The amount to buy/sell in quote units.
client_order_id (str | None) – A client order id.
side_effect_type (str) – One of NO_SIDE_EFFECT, MARGIN_BUY or AUTO_REPAY.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
Note
Either amount or quote_amount should be set, but not both.
- async create_oco_order(operation, pair, amount, limit_price, stop_price, stop_limit_price=None, side_effect_type='NO_SIDE_EFFECT', stop_limit_time_in_force='GTC', list_client_order_id=None, limit_client_order_id=None, stop_client_order_id=None, **kwargs)¶
Creates an OCO order.
Check https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-oco-trade for more information. If the order can’t be created a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell in base units.
limit_price (Decimal) – The limit price.
stop_price (Decimal) – The stop price.
stop_limit_price (Decimal | None) – The stop limit price.
side_effect_type (str) – One of NO_SIDE_EFFECT, MARGIN_BUY or AUTO_REPAY.
stop_limit_time_in_force (str) – The time in force for the stop limit order.
list_client_order_id (str | None) – A client id for the order list.
limit_client_order_id (str | None) – A client id for the limit order.
stop_client_order_id (str | None) – A client id for the stop order.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async create_stop_limit_order(operation, pair, amount, stop_price, limit_price, side_effect_type='NO_SIDE_EFFECT', time_in_force='GTC', client_order_id=None, **kwargs)¶
Creates a stop limit order.
Check https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade for more information. If the order can’t be created a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
operation (OrderOperation) – The order operation.
pair (Pair) – The pair to trade.
amount (Decimal) – The amount to buy/sell in base units.
stop_price (Decimal) – The stop price.
limit_price (Decimal) – The limit price.
side_effect_type (str) – One of NO_SIDE_EFFECT, MARGIN_BUY or AUTO_REPAY.
time_in_force (str) – The time in force.
client_order_id (str | None) – A client order id.
kwargs (Dict[str, Any]) – Additional keyword arguments that will be forwarded.
- Return type:
- async get_oco_order_info(order_list_id=None, client_order_list_id=None)¶
Returns information about an OCO order.
- Parameters:
order_list_id (str | None) – The order list id.
client_order_list_id (str | None) – A client id for the order list.
- Return type:
Note
Either order_list_id or client_order_list_id should be set, but not both.
- async get_open_orders(pair=None)¶
Returns open orders.
- async get_order_info(pair, order_id=None, client_order_id=None, include_trades=True)¶
Returns information about an order.
- Parameters:
pair (Pair) – That trading pair.
order_id (str | None) – The order id.
client_order_id (str | None) – The client order id.
include_trades (bool)
- Return type:
Note
Either order_id or client_order_id should be set, but not both.
Including trades requires making an extra request to Binance.
- subscribe_to_order_events(event_handler)¶
Registers an async callable that will be called for every new order update.
Works as defined in https://developers.binance.com/docs/margin_trading/trade-data-stream/Event-Order-Update.
- Parameters:
event_handler (Callable[[OrderEvent], Awaitable[Any]]) – The event handler.
- subscribe_to_user_data_events(event_handler)¶
Registers an async callable that will be called for every new user data event.
Works as defined in https://developers.binance.com/docs/margin_trading/trade-data-stream.
- Parameters:
event_handler (Callable[[Event], Awaitable[Any]]) – The event handler.
- async transfer_from_spot_account(asset, amount)¶
Transfer balances from the spot account to the cross margin account.
If the transfer can’t be completed a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
asset (str) – The asset to transfer.
amount (Decimal) – The amount to transfer.
- Return type:
dict
- async transfer_to_spot_account(asset, amount)¶
Transfer balances from the cross margin account to the spot account.
If the transfer can’t be completed a
basana.external.binance.exchange.Errorwill be raised.- Parameters:
asset (str) – The asset to transfer.
amount (Decimal) – The amount to transfer.
- Return type:
dict