createStopLimitOrderGTC function
Creates a stop limit order. GTC: Good Till Cancelled. An order that triggers a limit order when the last trade price hits a specified stop price.
POST /v3/brokerage/orders https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/orders/create-order
clientOrderId - A unique ID for the order, generated by the client.
productId - The ID of the product to trade.
side - The side of the order (BUY or SELL).
baseSize - The amount of base currency to buy or sell.
limitPrice - The price at which to buy or sell the base currency.
stopPrice - The price at which the order should be triggered.
stopDirection - The direction of the stop price (ABOVE or BELOW).
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns a map containing the result of the order creation, or null if the request fails.
Implementation
Future<Map<String, dynamic>?> createStopLimitOrderGTC(
{required String clientOrderId,
required String productId,
required OrderSide side,
required String baseSize,
required String limitPrice,
required String stopPrice,
required StopDirection stopDirection,
required Credential credential,
bool isSandbox = false,
Client? client}) async {
final orderConfiguration = {
'stop_limit_stop_limit_gtc': {
'base_size': baseSize,
'limit_price': limitPrice,
'stop_price': stopPrice,
'stop_direction': stopDirection.toCB(),
}
};
return _createOrder(
clientOrderId: clientOrderId,
productId: productId,
side: side,
orderConfiguration: orderConfiguration,
credential: credential,
isSandbox: isSandbox,
client: client);
}