Create Order

Order could be in one of the following statuses:

  1. CREATED - assigned to the order on creation, which basically means accepted by the platform

  2. PENDING - order is getting executed or placed in order book

  3. PARTIALLY_FILLED - order is partially executed and no longer will be processed (terminated status)

  4. FILLED - order is fully executed and no longer will be processed (terminated status)

  5. CANCELLED - order is not filled and cancelled by user (terminated status)

  6. EXPIRED - order is expired (terminated status)

  7. REJECTED - order is rejected while trying to be executed(terminated status) - check rejectionReason for details

Create order expects signed data to be passed in. The order is as follows:

 accountId
 orderId
 marketId
 orderType
 orderDirection
 orderSide
 price
 quantity
 leverage
 slippage
 postOnly
 timeInForce
 clientTimestamp
 

Here is how it is implemented with typescript:

   const accountIdBytes = polkadotUtil.hexToU8a(accountId);
    const accountIdLowBytes = accountIdBytes.slice(16);
    const accountIdHighBytes = accountIdBytes.slice(0, 16);

    const orderIdU256 = SubstrateHelper.convertStringToU256(order.id);
    const orderIdBytes = polkadotUtil.bnToU8a(orderIdU256, { isLe: false });
    const orderIdLowBytes = orderIdBytes.slice(16);
    const orderIdHighBytes = orderIdBytes.slice(0, 16);

    const elements = [
      polkadotUtil.u8aToBn(accountIdLowBytes, { isLe: false }).toString(),
      polkadotUtil.u8aToBn(accountIdHighBytes, { isLe: false }).toString(),
      polkadotUtil.u8aToBn(orderIdLowBytes, { isLe: false }).toString(),
      polkadotUtil.u8aToBn(orderIdHighBytes, { isLe: false }).toString(),
      SubstrateHelper.convertStringToU128(order.marketId).toPrimitive(),
      SubstrateHelper.convertStringToU256(order.type).toPrimitive(),
      SubstrateHelper.convertStringToU256(order.direction).toPrimitive(),
      SubstrateHelper.convertStringToU256(order.side).toPrimitive(),
      SubstrateHelper.convertNumberToI128(order.price).toPrimitive(),
      SubstrateHelper.convertNumberToI128(order.quantity).toPrimitive(),
      SubstrateHelper.convertNumberToI128(order.leverage).toPrimitive(),
      SubstrateHelper.convertNumberToI128(order.slippage).toPrimitive(),
      order.postOnly ? 1 : 0,
      SubstrateHelper.convertStringToU256(order.timeInForce).toPrimitive(),
      order.clientTimestamp as number,
    ];

    return starknet.hash.computeHashOnElements(elements);

Last updated