createLimitOrder function
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);
}