createStopLimitOrderGTD function

Future<Map<String, dynamic>?> createStopLimitOrderGTD({
  1. required String clientOrderId,
  2. required String productId,
  3. required OrderSide side,
  4. required String baseSize,
  5. required String limitPrice,
  6. required String stopPrice,
  7. required StopDirection stopDirection,
  8. required DateTime endTime,
  9. required Credential credential,
  10. bool isSandbox = false,
  11. Client? client,
})

Creates a stop limit order. GTD: Good Till Date. An order that triggers a limit order when the last trade price hits a specified stop price. The order will be cancelled if it is not filled by the specified end time.

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). endTime - The time at which the order should be cancelled if it is not filled. 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>?> createStopLimitOrderGTD(
    {required String clientOrderId,
    required String productId,
    required OrderSide side,
    required String baseSize,
    required String limitPrice,
    required String stopPrice,
    required StopDirection stopDirection,
    required DateTime endTime,
    required Credential credential,
    bool isSandbox = false,
    Client? client}) async {
  final orderConfiguration = {
    'stop_limit_stop_limit_gtd': {
      'base_size': baseSize,
      'limit_price': limitPrice,
      'stop_price': stopPrice,
      'stop_direction': stopDirection.toCB(),
      'end_time': endTime.toUtc().toIso8601String(),
    }
  };

  return _createOrder(
      clientOrderId: clientOrderId,
      productId: productId,
      side: side,
      orderConfiguration: orderConfiguration,
      credential: credential,
      isSandbox: isSandbox,
      client: client);
}