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
workingOrderRequest
TWorkingOrderRequestWorking order to place.
bracketOrdersDefinitions
IReadOnlyList<BracketOrderDefinition>Bracket orders to trigger when the working order is fully filled.
onBracketedOrderUpdateAsync
IBracketedOrdersFactory.OnBracketedOrderUpdateAsyncOptionally, callback to be called when an update is available for the bracketed order.
cancellationToken
CancellationTokenCancellation 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
TWorkingOrderRequest
Type of working order request. Must be either LimitOrderRequest or MarketOrderRequest.
Exceptions
- InvalidArgumentException
Thrown if:
workingOrderRequest
is null; or- client order ID of the
workingOrderRequest
is more than MaxClientOrderIdLength characters long when trading strategy budget is used; or - client order ID of the
workingOrderRequest
is more than MaxClientOrderIdWithoutBudgetLength characters long when trading strategy budget is not used; or workingOrderRequest
is neither LimitOrderRequest nor MarketOrderRequest; orworkingOrderRequest
is LimitOrderRequest and its time-in-force is not FillOrKill; orbracketOrdersDefinitions
is empty; orbracketOrdersDefinitions
contains more than MaxBracketOrders items; or- the type of any bracket order is neither StopLoss nor TakeProfit; or
- size in percent of any of the stop-loss orders or the take-profit is either less than
0
or greater than100
; or - sum of sizes in percent of stop-loss orders in
bracketOrdersDefinitions
is greater than100
; or - sum of sizes in percent of take-profit orders in
bracketOrdersDefinitions
is greater than100
; or - threshold price of a stop-loss order is not below the price of
workingOrderRequest
if it is a buy limit order request; or - threshold price of a stop-loss order is not above the price of
workingOrderRequest
if it is a sell limit order request; or - threshold price of a take-profit order is not above the price of
workingOrderRequest
if it is a buy limit order request; or - threshold price of a take-profit order is not below the price of
workingOrderRequest
if 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.- 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