Method CreateStopLossOrderAsync
- Namespace
- WhalesSecret.TradeScriptLib.API.TradingV1
- Assembly
- WhalesSecret.TradeScriptLib.dll
CreateStopLossOrderAsync(SymbolPair, OrderSide, decimal, decimal, CancellationToken)
Sends a new stop-loss order request to the exchange.
Task<ILiveStopLossOrder> CreateStopLossOrderAsync(SymbolPair symbolPair, OrderSide side, decimal thresholdPrice, decimal size, CancellationToken cancellationToken = default)
Parameters
symbolPair
SymbolPairMarket on the exchange.
side
OrderSideWhether to buy or sell the base symbol.
thresholdPrice
decimalWhen the market of
symbolPair
on the exchange reaches the price, the stop-loss order becomes Market order.size
decimalAmount of
symbolPair
base symbol to buy or sell.cancellationToken
CancellationTokenCancellation token that allows the caller to cancel the operation.
Returns
- Task<ILiveStopLossOrder>
ILiveStopLossOrder 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.
CreateStopLossOrderAsync(string?, SymbolPair, OrderSide, decimal, decimal, CancellationToken)
Sends a new stop-loss order request to the exchange.
Task<ILiveStopLossOrder> CreateStopLossOrderAsync(string? clientOrderId, SymbolPair symbolPair, OrderSide side, decimal thresholdPrice, decimal size, CancellationToken cancellationToken = default)
Parameters
clientOrderId
stringUnique client order ID, or
null
to let the system generate the ID.symbolPair
SymbolPairMarket on the exchange.
side
OrderSideWhether to buy or sell the base symbol.
thresholdPrice
decimalWhen the market of
symbolPair
on the exchange reaches the price, the stop-loss order becomes Market order.size
decimalAmount of
symbolPair
base symbol to buy or sell.cancellationToken
CancellationTokenCancellation token that allows the caller to cancel the operation.
Returns
- Task<ILiveStopLossOrder>
ILiveStopLossOrder 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.