Method CreateBracketedOrderAsync
- Namespace
- WhalesSecret.TradeScriptLib.API.TradingV1
- Assembly
- WhalesSecret.TradeScriptLib.dll
CreateBracketedOrderAsync<TWorkingOrderRequest>(TWorkingOrderRequest, IReadOnlyList<BracketOrderDefinition>, OnBracketedOrderUpdateAsync?, CancellationToken)
Creates a bracketed order.
Task<ILiveBracketedOrder> CreateBracketedOrderAsync<TWorkingOrderRequest>(TWorkingOrderRequest workingOrderRequest, IReadOnlyList<BracketOrderDefinition> bracketOrdersDefinitions, IBracketedOrdersFactory.OnBracketedOrderUpdateAsync? onBracketedOrderUpdateAsync = null, CancellationToken cancellationToken = default) where TWorkingOrderRequest : OrderRequest
Parameters
workingOrderRequestTWorkingOrderRequestWorking order to place.
bracketOrdersDefinitionsIReadOnlyList<BracketOrderDefinition>Bracket orders to trigger when the working order is fully filled.
onBracketedOrderUpdateAsyncIBracketedOrdersFactory.OnBracketedOrderUpdateAsyncOptionally, callback to be called when an update is available for the bracketed order.
cancellationTokenCancellationTokenCancellation token that allows the caller to cancel the operation.
Returns
- Task<ILiveBracketedOrder>
ILiveBracketedOrder when a response was received from the exchange and all orders were accepted by the exchange.
Type Parameters
TWorkingOrderRequestType of working order request. Must be either LimitOrderRequest or MarketOrderRequest.
Exceptions
- InvalidArgumentException
Thrown if:
workingOrderRequestis null; or- client order ID of the
workingOrderRequestis more than MaxClientOrderIdLength characters long when trading strategy budget is used; or - client order ID of the
workingOrderRequestis more than MaxClientOrderIdWithoutBudgetLength characters long when trading strategy budget is not used; or workingOrderRequestis neither LimitOrderRequest nor MarketOrderRequest; orworkingOrderRequestis LimitOrderRequest and its time-in-force is not FillOrKill; orbracketOrdersDefinitionsis empty; orbracketOrdersDefinitionscontains more than MaxBracketOrders items; or- the type of any bracket order is neither StopLoss, TrailingStopLoss, TakeProfit, nor TakeProfitUsingLimitOrder; or
- size in percent of any of the stop-loss orders or the take-profit is either less than
0or greater than100; or - sum of sizes in percent of stop-loss orders in
bracketOrdersDefinitionsis greater than100; or - sum of sizes in percent of take-profit orders in
bracketOrdersDefinitionsis greater than100; or - threshold price of a stop-loss order is not below the price of
workingOrderRequestif it is a buy limit order request; or - threshold price of a stop-loss order is not above the price of
workingOrderRequestif it is a sell limit order request; or - threshold price of a take-profit order is not above the price of
workingOrderRequestif it is a buy limit order request; or - threshold price of a take-profit order is not below the price of
workingOrderRequestif it is a sell limit order request.
- RejectedException
Thrown if the exchange rejected a working 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, or an unsupported exchange market is passed, or an invalid client order ID has been provided, or if any of the given bracket orders definitions is invalid.- 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.
- 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.
- See Also