placeLimitOrder method

Future<TransactionBlock> placeLimitOrder({
  1. required String poolId,
  2. required int price,
  3. required int quantity,
  4. required OrderType orderType,
  5. int? expirationTimestamp,
  6. LimitOrderType restriction = LimitOrderType.NO_RESTRICTION,
  7. int? clientOrderId,
  8. SelfMatchingPreventionStyle selfMatchingPrevention = SelfMatchingPreventionStyle.CANCEL_OLDEST,
})

Place a limit order

poolId Object id of pool, created after invoking createPool.

price price of the limit order. The number must be an interger float scaled by FLOAT_SCALING_FACTOR.

quantity quantity of the limit order in BASE ASSET, eg: 100000000.

orderType bid for buying base with quote, ask for selling base for quote. ]

expirationTimestamp expiration timestamp of the limit order in ms. If omitted, the order will expire in 1 day from the time this function is called(not the time the transaction is executed).

restriction restrictions on limit orders, explain in doc for more details.

clientOrderId a client side defined order number for bookkeeping purpose, e.g., "1", "2", etc. If omitted, the sdk will assign a increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances.

selfMatchingPrevention Options for self-match prevention. Right now only support CANCEL_OLDEST.

Implementation

///
  /// [poolId] Object id of pool, created after invoking createPool.
  ///
  /// [price] price of the limit order. The number must be an interger float scaled by `FLOAT_SCALING_FACTOR`.
  ///
  /// [quantity] quantity of the limit order in BASE ASSET, eg: 100000000.
  ///
  /// [orderType] bid for buying base with quote, ask for selling base for quote. ]
  ///
  /// [expirationTimestamp] expiration timestamp of the limit order in ms. If omitted, the order will expire in 1 day
/// from the time this function is called(not the time the transaction is executed).
  ///
  /// [restriction] restrictions on limit orders, explain in doc for more details.
  ///
  /// [clientOrderId] a client side defined order number for bookkeeping purpose, e.g., "1", "2", etc. If omitted, the sdk will
/// assign a increasing number starting from 0. But this number might be duplicated if you are using multiple sdk instances.
  ///
  /// [selfMatchingPrevention] Options for self-match prevention. Right now only support `CANCEL_OLDEST`.
Future<TransactionBlock> placeLimitOrder({
	required String poolId,
	required int price,
	required int quantity,
	required OrderType orderType,
	int? expirationTimestamp,
	LimitOrderType restriction = LimitOrderType.NO_RESTRICTION,
	int? clientOrderId,
	SelfMatchingPreventionStyle selfMatchingPrevention = SelfMatchingPreventionStyle.CANCEL_OLDEST,
}) async {
    expirationTimestamp ??= DateTime.now().millisecondsSinceEpoch + ORDER_DEFAULT_EXPIRATION_IN_MS;
    clientOrderId ??= _nextClientOrderId();

	final txb = TransactionBlock();
	final args = [
		txb.object(poolId),
		txb.pureInt(clientOrderId),
		txb.pureInt(price),
		txb.pureInt(quantity),
		txb.pure(selfMatchingPrevention.index, BCS.U8),
		txb.pure(orderType == OrderType.bid, BCS.BOOL),
		txb.pureInt(expirationTimestamp),
		txb.pure(restriction.index, BCS.U8),
		txb.object(SUI_CLOCK_OBJECT_ID),
		txb.object(_checkAccountCap()),
	];
    final typeArgs = await getPoolTypeArgs(poolId);
	txb.moveCall(
		"$PACKAGE_ID::$MODULE_CLOB::place_limit_order",
		typeArguments: typeArgs,
		arguments: args,
	);
	return txb;
}