basana.external.binance.spot¶
- class basana.external.binance.spot.Account(cli, ws_mgr)¶
Spot account.
- Parameters:
cli (SpotAccount)
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, time_in_force='GTC', client_order_id=None, **kwargs)¶
Creates a limit order.
Check https://binance-docs.github.io/apidocs/spot/en/#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.
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, **kwargs)¶
Creates a market order.
Check https://binance-docs.github.io/apidocs/spot/en/#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.
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, 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/#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.
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, time_in_force='GTC', client_order_id=None, **kwargs)¶
Creates a stop limit order.
Check https://binance-docs.github.io/apidocs/spot/en/#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.
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) – The trading pair.
order_id (str | None) – The order id.
client_order_id (str | None) – The client order id.
include_trades (bool) – True to include trades in the order info, False otherwise.
- 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/binance-spot-api-docs/user-data-stream#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/binance-spot-api-docs/user-data-stream.
- Parameters:
event_handler (Callable[[Event], Awaitable[Any]]) – The event handler.
- class basana.external.binance.spot.Balance(json)¶
- Parameters:
json (dict)
- property available: Decimal¶
The available balance.
- property locked: Decimal¶
The locked balance.
- property total: Decimal¶
The total balance (available + locked).
- class basana.external.binance.spot.CreatedOrder(json)¶
- Parameters:
json (dict)
- property amount: Decimal | None¶
The amount.
Only available for RESULT / FULL responses.
- property amount_filled: Decimal | None¶
The amount filled.
Only available for RESULT / FULL responses.
- property client_order_id: str¶
The client order id.
- property datetime: datetime¶
The creation datetime.
- property id: str¶
The order id.
- property is_open: bool¶
True if the order is open, False otherwise.
Only available for RESULT / FULL responses.
- property limit_price: Decimal | None¶
The limit price.
Only available for RESULT / FULL responses.
- property order_list_id: str | None¶
The order list id.
- property quote_amount_filled: Decimal | None¶
The amount filled in quote units.
Only available for RESULT / FULL responses.
- property status: str | None¶
The status.
Only available for RESULT / FULL responses. Check Order status in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-status-status.
- property time_in_force: str | None¶
The time in force.
Only available for RESULT / FULL responses. Check Time in force in https://developers.binance.com/docs/binance-spot-api-docs/enums#time-in-force-timeinforce.
- class basana.external.binance.spot.OrderInfo(json, trades)¶
- Parameters:
json (dict)
trades (Sequence[Trade])
- property amount: Decimal¶
The amount.
- property amount_filled: Decimal¶
The amount filled.
- property amount_remaining: Decimal¶
The amount remaining to be filled.
- property client_order_id: str¶
The client order id.
- property fees: Dict[str, Decimal]¶
The fees.
- property fill_price: Decimal | None¶
The fill price.
- property id: str¶
The order id.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_price: Decimal | None¶
The limit price.
- property operation: OrderOperation¶
The operation.
- property order_list_id: str | None¶
The order list id.
- property quote_amount_filled: Decimal¶
The amount filled in quote units.
- property status: str¶
The status.
Check Order status in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-status-status.
- property stop_price: Decimal | None¶
The stop price.
- property time_in_force: str | None¶
The time in force.
Check Time in force in https://developers.binance.com/docs/binance-spot-api-docs/enums#time-in-force-timeinforce.
- class basana.external.binance.spot.OpenOrder(json)¶
- Parameters:
json (dict)
- property amount: Decimal¶
The amount.
- property amount_filled: Decimal¶
The amount filled.
- property client_order_id: str¶
The client order id.
- property datetime: datetime¶
The creation datetime.
- property id: str¶
The order id.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_price: Decimal | None¶
The limit price.
- property operation: OrderOperation¶
The operation.
- property order_list_id: str | None¶
The order list id.
- property quote_amount: Decimal | None¶
The order amount in quote units.
- property quote_amount_filled: Decimal¶
The amount filled in quote units.
- property status: str¶
The status.
Check Order status in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-status-status.
- property stop_price: Decimal | None¶
The stop price.
- property time_in_force: str | None¶
The time in force.
Check Time in force in https://developers.binance.com/docs/binance-spot-api-docs/enums#time-in-force-timeinforce.
- property type: str¶
The type of order.
Check Order types in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-types-ordertypes-type.
- class basana.external.binance.spot.CanceledOrder(json)¶
- Parameters:
json (dict)
- property amount: Decimal¶
The amount.
- property amount_filled: Decimal¶
The amount filled.
- property client_order_id: str¶
The client order id.
- property id: str¶
The order id.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_price: Decimal | None¶
The limit price.
- property operation: OrderOperation¶
The operation.
- property order_list_id: str | None¶
The order list id.
- property quote_amount_filled: Decimal¶
The amount filled in quote units.
- property status: str¶
The status.
Check Order status in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-status-status.
- property stop_price: Decimal | None¶
The stop price.
- property time_in_force: str | None¶
The time in force.
Check Time in force in https://developers.binance.com/docs/binance-spot-api-docs/enums#time-in-force-timeinforce.
- property type: str¶
The type of order.
Check Order types in https://developers.binance.com/docs/binance-spot-api-docs/enums#order-types-ordertypes-type.
- class basana.external.binance.spot.CreatedOCOOrder(json)¶
- Parameters:
json (dict)
- property client_order_list_id: str¶
A client id for the order list.
- property datetime: datetime¶
The creation datetime.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_order_id: str¶
The id for the limit order.
- property order_list_id: str¶
The order list id.
- property stop_loss_order_id: str¶
The id for the stop loss order.
- class basana.external.binance.spot.OCOOrderInfo(json)¶
- Parameters:
json (dict)
- property client_order_list_id: str¶
A client id for the order list.
- property datetime: datetime¶
The creation datetime.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_order_id: str¶
The id for the limit order.
- property order_list_id: str¶
The order list id.
- property stop_loss_order_id: str¶
The id for the stop loss order.
- class basana.external.binance.spot.CanceledOCOOrder(json)¶
- Parameters:
json (dict)
- property client_order_list_id: str¶
A client id for the order list.
- property datetime: datetime¶
The creation datetime.
- property is_open: bool¶
True if the order is open, False otherwise.
- property limit_order_id: str¶
The id for the limit order.
- property order_list_id: str¶
The order list id.
- property stop_loss_order_id: str¶
The id for the stop loss order.