createNewOrder method

Future<Order> createNewOrder({
  1. String? profileId,
  2. OrderEnum? type,
  3. required SideEnum side,
  4. required String productId,
  5. StpEnum? stp,
  6. StopEnum? stop,
  7. double? stopPrice,
  8. double? price,
  9. double? size,
  10. double? funds,
  11. TimeInForceEnum? timeInForce,
  12. CancelAfterEnum? cancelAfter,
  13. bool? postOnly,
  14. String? clientOid,
})

Create a new order

Create an order. You can place two types of orders: limit and market. Orders can only be placed if your account has sufficient funds. Once an order is placed, your account funds will be put on hold for the duration of the order. How much and which funds are put on hold depends on the order type and parameters specified.

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postorders

Implementation

Future<Order> createNewOrder({
  String? profileId,
  OrderEnum? type,
  required SideEnum side,
  required String productId,
  StpEnum? stp,
  StopEnum? stop,
  double? stopPrice,
  double? price,
  double? size,
  double? funds,
  TimeInForceEnum? timeInForce,
  CancelAfterEnum? cancelAfter,
  bool? postOnly,
  String? clientOid,
}) async {
  var response = await _ordersRestClient.createNewOrder(
    profileId: profileId,
    type: type,
    side: side,
    productId: productId,
    stp: stp,
    stop: stop,
    stopPrice: stopPrice,
    price: price,
    size: size,
    funds: funds,
    timeInForce: timeInForce,
    cancelAfter: cancelAfter,
    postOnly: postOnly,
    clientOid: clientOid,
  );

  if (response.statusCode != 200) throw response;

  return Order.fromJson(json.decode(response.body));
}