Table of Contents

Method CreateTakeProfitOrderAsync

Namespace
WhalesSecret.TradeScriptLib.API.TradingV1
Assembly
WhalesSecret.TradeScriptLib.dll

CreateTakeProfitOrderAsync(SymbolPair, OrderSide, decimal, decimal, CancellationToken)

Sends a new take-profit order request to an exchange.

Task<ILiveTakeProfitOrder> CreateTakeProfitOrderAsync(SymbolPair symbolPair, OrderSide side, decimal thresholdPrice, decimal size, CancellationToken cancellationToken = default)

Parameters

symbolPair SymbolPair

Market on the exchange.

side OrderSide

Whether to buy or sell the base symbol.

thresholdPrice decimal

When the market of symbolPair on the exchange reaches the price, the take-profit order becomes Market order.

size decimal

Amount of symbolPair base symbol to buy or sell.

cancellationToken CancellationToken

Cancellation token that allows the caller to cancel the operation.

Returns

Task<ILiveTakeProfitOrder>

ILiveTakeProfitOrder when a response was received from exchange and the order was accepted by the exchange.

Remarks

Note that if the operation is canceled, the order may still be placed.

Unlike other methods, it's not possible to safely follow the connection strategy when placing orders. If there is a network problem and we get disconnected from an exchange, other methods can be safely retried when the connection is re-established. However, when placing orders, the order may or may not be successfully placed when the disconnection happens. Therefore, it's not safe to repeat the operation when the connection is re-established. That is why this method may only wait for reconnection before the request to place the order was sent. After that if we get disconnected, the call fails.

Exceptions

RejectedException

Thrown if the exchange rejected an order request.

NotConnectedException

Thrown if the request could not be sent to the exchange.

NotAvailableException

Thrown if the used connection has not been created with Trading support.

ExchangeResponseTimeoutException

Thrown if exchange does not respond in timely manner.

InvalidExchangeResponseException

Thrown if the exchange responded with invalid response.

ExchangeIsUnderMaintenanceException

Thrown if the exchange is in maintenance mode and does not accept new requests.

ApiRequestLimitReachedException

Thrown if the exchange rejected to create a new order due to an API rate limit.

InvalidRequestDataException

Thrown if the exchange rejected to create a new order because some value in the order is malformed or otherwise invalid.

InvalidArgumentException

Thrown if the order request is null, an unsupported exchange market is passed, or an invalid client order ID has been provided.

OperationCanceledException

Thrown if the operation was cancelled including cancellation due to shutdown or object disposal.

NotConnectedTimeoutException

Thrown if the connection strategy associated with this instance is BlockUntilReconnectedOrTimeout with non-infinite timeout value and this timeout expired while the connection to the exchange is interrupted. That is, this exception does not limit the request itself, it rather limits the period of time that allows the client to recover from the interruption of the connection to the exchange.

OperationFailedException

Thrown if the request failed for an unknown reason with an unknown outcome.

BudgetExceededException

Thrown if a trading strategy budget is associated with the trade API client and placing the order would exceed the budget.

BudgetCalculationException

Thrown if a trading strategy budget is associated with the trade API client and it is not possible to calculate whether an order would exceed it if it was placed.

CreateTakeProfitOrderAsync(string?, SymbolPair, OrderSide, decimal, decimal, CancellationToken)

Sends a new take-profit order request to an exchange.

Task<ILiveTakeProfitOrder> CreateTakeProfitOrderAsync(string? clientOrderId, SymbolPair symbolPair, OrderSide side, decimal thresholdPrice, decimal size, CancellationToken cancellationToken = default)

Parameters

clientOrderId string

Unique client order ID, or null to let the system generate the ID.

symbolPair SymbolPair

Market on the exchange.

side OrderSide

Whether to buy or sell the base symbol.

thresholdPrice decimal

When the market of symbolPair on the exchange reaches the price, the take-profit order becomes Market order.

size decimal

Amount of symbolPair base symbol to buy or sell.

cancellationToken CancellationToken

Cancellation token that allows the caller to cancel the operation.

Returns

Task<ILiveTakeProfitOrder>

ILiveTakeProfitOrder when a response was received from exchange and the order was accepted by the exchange.

Remarks

Note that if the operation is canceled, the order may still be placed.

Unlike other methods, it's not possible to safely follow the connection strategy when placing orders. If there is a network problem and we get disconnected from an exchange, other methods can be safely retried when the connection is re-established. However, when placing orders, the order may or may not be successfully placed when the disconnection happens. Therefore, it's not safe to repeat the operation when the connection is re-established. That is why this method may only wait for reconnection before the request to place the order was sent. After that if we get disconnected, the call fails.

Exceptions

RejectedException

Thrown if the exchange rejected an order request.

NotConnectedException

Thrown if the request could not be sent to the exchange.

NotAvailableException

Thrown if the used connection has not been created with Trading support.

ExchangeResponseTimeoutException

Thrown if exchange does not respond in timely manner.

InvalidExchangeResponseException

Thrown if the exchange responded with invalid response.

ExchangeIsUnderMaintenanceException

Thrown if the exchange is in maintenance mode and does not accept new requests.

ApiRequestLimitReachedException

Thrown if the exchange rejected to create a new order due to an API rate limit.

InvalidRequestDataException

Thrown if the exchange rejected to create a new order because some value in the order is malformed or otherwise invalid.

InvalidArgumentException

Thrown if the order request is null, an unsupported exchange market is passed, or an invalid client order ID has been provided.

OperationCanceledException

Thrown if the operation was cancelled including cancellation due to shutdown or object disposal.

NotConnectedTimeoutException

Thrown if the connection strategy associated with this instance is BlockUntilReconnectedOrTimeout with non-infinite timeout value and this timeout expired while the connection to the exchange is interrupted. That is, this exception does not limit the request itself, it rather limits the period of time that allows the client to recover from the interruption of the connection to the exchange.

OperationFailedException

Thrown if the request failed for an unknown reason with an unknown outcome.

BudgetExceededException

Thrown if a trading strategy budget is associated with the trade API client and placing the order would exceed the budget.

BudgetCalculationException

Thrown if a trading strategy budget is associated with the trade API client and it is not possible to calculate whether an order would exceed it if it was placed.