createLimitOrder function

Future<Map<String, dynamic>?> createLimitOrder({
  1. required String clientOrderId,
  2. required String productId,
  3. required String side,
  4. required String baseSize,
  5. required String limitPrice,
  6. bool postOnly = false,
  7. required Credential credential,
  8. bool isSandbox = false,
  9. Client? client,
})

Creates a limit order. GTC: Good Till Cancelled. Buy or sell a specified quantity of an Asset at a specified price. If posted, the Order will remain on the Order Book until canceled.

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. postOnly - Whether the order should be a post-only order. 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>?> createLimitOrder(
    {required String clientOrderId,
    required String productId,
    required String side,
    required String baseSize,
    required String limitPrice,
    bool postOnly = false,
    required Credential credential,
    bool isSandbox = false,
    Client? client}) async {
  final orderConfiguration = {
    'limit_limit_gtc': {
      'base_size': baseSize,
      'limit_price': limitPrice,
      'post_only': postOnly,
    }
  };

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