Binance C++ Connector 2.0.0
Official C++ connectors for the Binance APIs
Loading...
Searching...
No Matches
binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection Class Reference

A connection to the DerivativesTradingCoinFutures WebSocket API, returned connected by WebsocketApi::connect(). More...

#include <websocket_api.hpp>

Public Member Functions

const common::WebsocketApiConfig & configuration () const noexcept
void disconnect ()
template<class CompletionToken>
auto async_disconnect (CompletionToken &&token)
bool is_connected () const
void ping_server ()
 Sends a ping frame on every open connection.
template<class F>
common::Subscription on_event (F &&callback)
 Registers a lifecycle callback (common::WebsocketEvent).
template<class T>
common::WebsocketApiResponse< T > send_message (std::string method, common::Params payload={}) const
 Calls a method the SDK does not wrap yet. T may be boost::json::value.
template<class T>
common::WebsocketApiResponse< T > send_signed_message (std::string method, common::Params payload={}) const
 Like send_message, but signed (adds apiKey, timestamp and signature).
template<class T, class CompletionToken>
auto async_send_message (std::string method, common::Params payload, CompletionToken &&token) const
template<class T, class CompletionToken>
auto async_send_signed_message (std::string method, common::Params payload, CompletionToken &&token) const
common::WebsocketApiResponse< AccountInformationResponseResult > account_information (const AccountInformationParams &params={}) const
 Account Information (USER_DATA).
template<class CompletionToken>
auto async_account_information (const AccountInformationParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< std::vector< FuturesAccountBalanceResponseResultInner > > futures_account_balance (const FuturesAccountBalanceParams &params={}) const
 Futures Account Balance (USER_DATA).
template<class CompletionToken>
auto async_futures_account_balance (const FuturesAccountBalanceParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< CancelAlgoOrderResponseResult > cancel_algo_order (const CancelAlgoOrderParams &params={}) const
 Cancel Algo Order (TRADE).
template<class CompletionToken>
auto async_cancel_algo_order (const CancelAlgoOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< CancelOrderResponseResult > cancel_order (const CancelOrderParams &params) const
 Cancel Order (TRADE).
template<class CompletionToken>
auto async_cancel_order (const CancelOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< ModifyOrderResponseResult > modify_order (const ModifyOrderParams &params) const
 Modify Order (TRADE).
template<class CompletionToken>
auto async_modify_order (const ModifyOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< NewAlgoOrderResponseResult > new_algo_order (const NewAlgoOrderParams &params) const
 New Algo Order (TRADE).
template<class CompletionToken>
auto async_new_algo_order (const NewAlgoOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< NewOrderResponseResult > new_order (const NewOrderParams &params) const
 New Order (TRADE).
template<class CompletionToken>
auto async_new_order (const NewOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< std::vector< PositionInformationResponseResultInner > > position_information (const PositionInformationParams &params={}) const
 Position Information (USER_DATA).
template<class CompletionToken>
auto async_position_information (const PositionInformationParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< QueryOrderResponseResult > query_order (const QueryOrderParams &params) const
 Query Order (USER_DATA).
template<class CompletionToken>
auto async_query_order (const QueryOrderParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< boost::json::value > close_user_data_stream (const CloseUserDataStreamParams &params={}) const
 Close User Data Stream (USER_STREAM).
template<class CompletionToken>
auto async_close_user_data_stream (const CloseUserDataStreamParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< KeepaliveUserDataStreamResponseResult > keepalive_user_data_stream (const KeepaliveUserDataStreamParams &params={}) const
 Keepalive User Data Stream (USER_STREAM).
template<class CompletionToken>
auto async_keepalive_user_data_stream (const KeepaliveUserDataStreamParams &params, CompletionToken &&token) const
common::WebsocketApiResponse< StartUserDataStreamResponseResult > start_user_data_stream (const StartUserDataStreamParams &params={}) const
 Start User Data Stream (USER_STREAM).
template<class CompletionToken>
auto async_start_user_data_stream (const StartUserDataStreamParams &params, CompletionToken &&token) const

Friends

class WebsocketApi

Detailed Description

A connection to the DerivativesTradingCoinFutures WebSocket API, returned connected by WebsocketApi::connect().

Cheap to copy: copies share one common::WebsocketApi (connection pool and executor), which reconnects and renews its connections until disconnect().

Every method has a blocking form (name(params)) and an asynchronous form (async_name(params, token)) that accepts any Asio completion token.

Member Function Documentation

◆ configuration()

const common::WebsocketApiConfig & binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::configuration ( ) const
inlinenodiscardnoexcept

◆ disconnect()

void binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::disconnect ( )
inline

◆ async_disconnect()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_disconnect ( CompletionToken && token)
inline

◆ is_connected()

bool binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::is_connected ( ) const
inlinenodiscard

◆ ping_server()

void binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::ping_server ( )
inline

Sends a ping frame on every open connection.

◆ on_event()

template<class F>
common::Subscription binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::on_event ( F && callback)
inline

Registers a lifecycle callback (common::WebsocketEvent).

Destroying the returned subscription removes it.

◆ send_message()

template<class T>
common::WebsocketApiResponse< T > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::send_message ( std::string method,
common::Params payload = {} ) const
inlinenodiscard

Calls a method the SDK does not wrap yet. T may be boost::json::value.

◆ send_signed_message()

template<class T>
common::WebsocketApiResponse< T > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::send_signed_message ( std::string method,
common::Params payload = {} ) const
inlinenodiscard

Like send_message, but signed (adds apiKey, timestamp and signature).

◆ async_send_message()

template<class T, class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_send_message ( std::string method,
common::Params payload,
CompletionToken && token ) const
inline

◆ async_send_signed_message()

template<class T, class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_send_signed_message ( std::string method,
common::Params payload,
CompletionToken && token ) const
inline

◆ account_information()

common::WebsocketApiResponse< AccountInformationResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::account_information ( const AccountInformationParams & params = {}) const
inlinenodiscard

Account Information (USER_DATA).

account.status.

Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.

Weight(IP): 5

Security Type: USER_DATA

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/account#account-information

◆ async_account_information()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_account_information ( const AccountInformationParams & params,
CompletionToken && token ) const
inline

◆ futures_account_balance()

common::WebsocketApiResponse< std::vector< FuturesAccountBalanceResponseResultInner > > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::futures_account_balance ( const FuturesAccountBalanceParams & params = {}) const
inlinenodiscard

Futures Account Balance (USER_DATA).

account.balance.

Futures Account Balance

Weight(IP): 5

Security Type: USER_DATA

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/account#futures-account-balance

◆ async_futures_account_balance()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_futures_account_balance ( const FuturesAccountBalanceParams & params,
CompletionToken && token ) const
inline

◆ cancel_algo_order()

common::WebsocketApiResponse< CancelAlgoOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::cancel_algo_order ( const CancelAlgoOrderParams & params = {}) const
inlinenodiscard

Cancel Algo Order (TRADE).

algoOrder.cancel.

Cancel an active algo order.

Weight(IP): 1

Security Type: TRADE

Notes:

  • Either algoId or clientAlgoId must be sent.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#cancel-algo-order

◆ async_cancel_algo_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_cancel_algo_order ( const CancelAlgoOrderParams & params,
CompletionToken && token ) const
inline

◆ cancel_order()

common::WebsocketApiResponse< CancelOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::cancel_order ( const CancelOrderParams & params) const
inlinenodiscard

Cancel Order (TRADE).

order.cancel.

Cancel an active order.

Weight(IP): 1

Security Type: TRADE

Notes:

  • Either orderId or origClientOrderId must be sent.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#cancel-order

◆ async_cancel_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_cancel_order ( const CancelOrderParams & params,
CompletionToken && token ) const
inline

◆ modify_order()

common::WebsocketApiResponse< ModifyOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::modify_order ( const ModifyOrderParams & params) const
inlinenodiscard

Modify Order (TRADE).

order.modify.

Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue

Weight: 1 on 10s order rate limit(X-MBX-ORDER-COUNT-10S); 1 on 1min order rate limit(X-MBX-ORDER-COUNT-1M); 0 on IP rate limit(x-mbx-used-weight-1m)

Security Type: TRADE

Notes:

  • Either orderId or origClientOrderId must be sent, and the orderId will prevail if both are sent.
  • Both quantity and price must be sent.
  • When the new quantity or price doesn't satisfy PRICE_FILTER / PERCENT_FILTER / LOT_SIZE, amendment will be rejected and the order will stay as it is.
  • However the order will be cancelled by the amendment in the following situations:
    • when the order is in partially filled status and the new quantity <= executedQty
    • When the order is GTX and the new price will cause it to be executed immediately
  • One order can only be modified for less than 10000 times.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#modify-order

◆ async_modify_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_modify_order ( const ModifyOrderParams & params,
CompletionToken && token ) const
inline

◆ new_algo_order()

common::WebsocketApiResponse< NewAlgoOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::new_algo_order ( const NewAlgoOrderParams & params) const
inlinenodiscard

New Algo Order (TRADE).

algoOrder.place.

Send in a new algo order.

Weight(IP): 0

Security Type: TRADE

Notes:

  • Condition orders will be triggered when:

  • If parameterpriceProtectis sent as true:
  • when price reaches the triggerPrice ,the difference rate between "MARK_PRICE" and "CONTRACT_PRICE" cannot be larger than the "triggerProtect" of the symbol
  • "triggerProtect" of a symbol can be got from GET /dapi/v1/exchangeInfo

  • STOP, STOP_MARKET:
  • BUY: latest price ("MARK_PRICE" or "CONTRACT_PRICE") >= triggerPrice
  • SELL: latest price ("MARK_PRICE" or "CONTRACT_PRICE") <= triggerPrice
  • TAKE_PROFIT, TAKE_PROFIT_MARKET:
  • BUY: latest price ("MARK_PRICE" or "CONTRACT_PRICE") <= triggerPrice
  • SELL: latest price ("MARK_PRICE" or "CONTRACT_PRICE") >= triggerPrice
  • TRAILING_STOP_MARKET:
  • BUY: the lowest price after order placed <= activatePrice, and the latest price >= the lowest price * (1 + callbackRate)
  • SELL: the highest price after order placed >= activatePrice, and the latest price <= the highest price * (1 - callbackRate)

  • For TRAILING_STOP_MARKET, if you got such error code.

{"code": -2021, "msg": "Order would immediately trigger."}

means that the parameters you send do not meet the following requirements:

  • BUY: activatePrice should be smaller than latest price.
  • SELL: activatePrice should be larger than latest price.

  • STOP_MARKET, TAKE_PROFIT_MARKET with closePosition=true:
  • Follow the same rules for condition orders.
  • If triggered,**close all** current long position( if SELL) or current short position( if BUY).
  • Cannot be used with quantity parameter
  • Cannot be used with reduceOnly parameter
  • In Hedge Mode,cannot be used with BUY orders in LONG position side. and cannot be used with SELL orders in SHORT position side
  • selfTradePreventionMode is only effective when timeInForce set to IOC or GTC.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#new-algo-order

◆ async_new_algo_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_new_algo_order ( const NewAlgoOrderParams & params,
CompletionToken && token ) const
inline

◆ new_order()

common::WebsocketApiResponse< NewOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::new_order ( const NewOrderParams & params) const
inlinenodiscard

New Order (TRADE).

order.place.

Send in a new order.

Weight(IP): 0

Security Type: TRADE

Notes:

  • Additional mandatory parameters based on type: | Type | Additional mandatory parameters | | :—: | — | | LIMIT | timeInForce, quantity, price | | MARKET | quantity | | STOP/TAKE_PROFIT | quantity, price, stopPrice | | STOP_MARKET/TAKE_PROFIT_MARKET | stopPrice | | TRAILING_STOP_MARKET | callbackRate |
    • Order with type STOP, parameter timeInForce can be sent ( default GTC). * Order with type TAKE_PROFIT, parameter timeInForce can be sent ( default GTC). * Condition orders will be triggered when:
    • If parameter priceProtect is sent as true:
    • when price reaches the stopPrice,the difference rate between "MARK_PRICE" and "CONTRACT_PRICE" cannot be larger than the "triggerProtect" of the symbol
    • "triggerProtect" of a symbol can be got from GET /dapi/v1/exchangeInfo
    • STOP, STOP_MARKET:
    • BUY: latest price ("MARK_PRICE" or "CONTRACT_PRICE") >= stopPrice
    • SELL: latest price ("MARK_PRICE" or "CONTRACT_PRICE") <= stopPrice
    • TAKE_PROFIT, TAKE_PROFIT_MARKET:
    • BUY: latest price ("MARK_PRICE" or "CONTRACT_PRICE") <= stopPrice
    • SELL: latest price ("MARK_PRICE" or "CONTRACT_PRICE") >= stopPrice
    • TRAILING_STOP_MARKET:
    • BUY: the lowest price after order placed <= activationPrice, and the latest price >= the lowest price * (1 + callbackRate)
    • SELL: the highest price after order placed >= activationPrice, and the latest price <= the highest price * (1 - callbackRate)
    • For TRAILING_STOP_MARKET, if you got such error code.
    • BUY: activationPrice should be smaller than latest price.
    • SELL: activationPrice should be larger than latest price.
    • If newOrderRespType is sent as RESULT:
    • MARKET order: the final FILLED result of the order will be return directly.
    • LIMIT order with special timeInForce: the final status result of the order(FILLED or EXPIRED) will be returned directly.
    • STOP_MARKET, TAKE_PROFIT_MARKET with closePosition=true:
    • Follow the same rules for condition orders.
    • If triggered,**close all** current long position(if SELL) or current short position(if BUY).
    • Cannot be used with quantity parameter
    • Cannot be used with reduceOnly parameter
    • In Hedge Mode, cannot be used with BUY orders in LONG position side. and cannot be used with SELL orders in SHORT position side

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#new-order

◆ async_new_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_new_order ( const NewOrderParams & params,
CompletionToken && token ) const
inline

◆ position_information()

common::WebsocketApiResponse< std::vector< PositionInformationResponseResultInner > > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::position_information ( const PositionInformationParams & params = {}) const
inlinenodiscard

Position Information (USER_DATA).

account.position.

Get current position information.

Weight(IP): 5

Security Type: USER_DATA

Notes:

  • Please use with user data stream ACCOUNT_UPDATE to meet your timeliness and accuracy needs.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#position-information

◆ async_position_information()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_position_information ( const PositionInformationParams & params,
CompletionToken && token ) const
inline

◆ query_order()

common::WebsocketApiResponse< QueryOrderResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::query_order ( const QueryOrderParams & params) const
inlinenodiscard

Query Order (USER_DATA).

order.status.

Check an order's status.

  • These orders will not be found:
    • order status is CANCELED or EXPIRED AND order has NO filled trade AND created time + 3 days < current time
    • order create time + 90 days < current time

Weight(IP): 1

Security Type: USER_DATA

Notes:

  • Either orderId or origClientOrderId must be sent.

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/trade#query-order

◆ async_query_order()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_query_order ( const QueryOrderParams & params,
CompletionToken && token ) const
inline

◆ close_user_data_stream()

common::WebsocketApiResponse< boost::json::value > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::close_user_data_stream ( const CloseUserDataStreamParams & params = {}) const
inlinenodiscard

Close User Data Stream (USER_STREAM).

userDataStream.stop.

Close out a user data stream.

Weight(IP): 1

Security Type: USER_STREAM

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/user-data-streams#close-user-data-stream

◆ async_close_user_data_stream()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_close_user_data_stream ( const CloseUserDataStreamParams & params,
CompletionToken && token ) const
inline

◆ keepalive_user_data_stream()

common::WebsocketApiResponse< KeepaliveUserDataStreamResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::keepalive_user_data_stream ( const KeepaliveUserDataStreamParams & params = {}) const
inlinenodiscard

Keepalive User Data Stream (USER_STREAM).

userDataStream.ping.

Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 60 minutes.

Weight(IP): 1

Security Type: USER_STREAM

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/user-data-streams#keepalive-user-data-stream

◆ async_keepalive_user_data_stream()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_keepalive_user_data_stream ( const KeepaliveUserDataStreamParams & params,
CompletionToken && token ) const
inline

◆ start_user_data_stream()

common::WebsocketApiResponse< StartUserDataStreamResponseResult > binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::start_user_data_stream ( const StartUserDataStreamParams & params = {}) const
inlinenodiscard

Start User Data Stream (USER_STREAM).

userDataStream.start.

Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. If the account has an active listenKey, that listenKey will be returned and its validity will be extended for 60 minutes.

Weight(IP): 1

Security Type: USER_STREAM

See https://developers.binance.com/en/docs/catalog/core-trading-derivatives-trading-coin-m-futures/api/ws-api/user-data-streams#start-user-data-stream

◆ async_start_user_data_stream()

template<class CompletionToken>
auto binance::derivatives_trading_coin_futures::websocket_api::WebsocketApiConnection::async_start_user_data_stream ( const StartUserDataStreamParams & params,
CompletionToken && token ) const
inline

◆ WebsocketApi

friend class WebsocketApi
friend