submit spot order

API details

Order submission supports both limit orders and swap orders. Developers can choose the appropriate type based on their specific requirements.

Submit spot order

post
Body
typestringOptional
userIdstringOptional
noncestringOptional
messagestringOptional
hashstringOptional
signaturestringOptional
Responses
200
OK
post
POST /v1/tx/submit-spot-order HTTP/1.1
Host: testnetopenapi.hibit.app
Content-Type: application/json
Accept: */*
Content-Length: 96

{
  "type": "text",
  "userId": "text",
  "nonce": "text",
  "message": "text",
  "hash": "text",
  "signature": "text"
}
{
  "code": 1,
  "message": "text",
  "data": {
    "txHash": "text"
  }
}

Code example

Limit order

import {
  hibitClient,
  HibitNetwork,
  OrderCategory,
  OrderSide,
  SubmitSpotOrderInput,
  DecimalOptions
} from '@delandlabs/hibit-sdk';

// Set client options (should be done once in your app)
hibitClient.setOptions({
  network: HibitNetwork.Testnet,
  hin: BigInt('123456'),
  proxyKey: 'your_proxy_private_key_hex'
});

async function submitLimitOrder() {
  const input: SubmitSpotOrderInput = {
    marketId: BigInt('10001'),
    orderCategory: OrderCategory.LimitOrder,
    limitOrderDetails: {
      orderSide: OrderSide.Bid, // Bid for buy, Ask for sell
      price: 100.5,
      volume: 0.01
    }
  };
  const decimalOptions: DecimalOptions = {
    baseAssetDecimals: 18,
    quoteAssetDecimals: 6
  };
  try {
    const txHash = await hibitClient.submitSpotOrder(input, decimalOptions);
    console.log('Limit order submitted, txHash:', txHash);
  } catch (err) {
    console.error('Submit limit order failed:', err);
  }
}
submitLimitOrder();

Swap order

import {
  hibitClient,
  HibitNetwork,
  OrderCategory,
  OrderSide,
  SwapV2ExactTokensType,
  SubmitSpotOrderInput,
  DecimalOptions
} from '@delandlabs/hibit-sdk';

// Set client options (should be done once in your app)
hibitClient.setOptions({
  network: HibitNetwork.Testnet,
  hin: BigInt('123456'),
  proxyKey: 'your_proxy_private_key_hex'
});

async function submitSwapOrder() {
  const input: SubmitSpotOrderInput = {
    marketId: BigInt('10001'),
    orderCategory: OrderCategory.SwapOrder,
    swapV2OrderDetails: {
      orderSide: OrderSide.Bid, // Bid for buy, Ask for sell
      exactTokensType: SwapV2ExactTokensType.Source, // Source: consume exactTokens, Target: get exactTokens
      exactTokens: '100'
      // minOut, maxIn can be added for slippage protection
    }
  };
  const decimalOptions: DecimalOptions = {
    baseAssetDecimals: 18,
    quoteAssetDecimals: 6
  };

  /*
    Parameter logic:
    - proxyPrivateKey: from reset-proxy-key
    - hin: Hibit Identity Number
    - marketId: Market identifier
    - orderSide: OrderSide.Bid (buy, use quote to buy base), OrderSide.Ask (sell, sell base for quote)
    - exactTokensType:
        SwapV2ExactTokensType.Source: consume exactTokens
        SwapV2ExactTokensType.Target: get exactTokens
    - exactTokens: string
        If Source: amount to consume
        If Target: amount to receive
    - minOut/maxIn: optional slippage protection
    - baseAssetDecimals/quoteAssetDecimals: decimals for each asset

    Token consumption logic:
    1. Source mode (exactTokensType=Source): consume exactTokens
       - If orderSide=Ask: consume base asset (ask)
       - If orderSide=Bid: consume quote asset (bid)
    2. Target mode (exactTokensType=Target): get exactTokens
       - If orderSide=Bid: consume quote to get base (bid)
       - If orderSide=Ask: consume base to get quote (ask)
  */

  try {
    const txHash = await hibitClient.submitSpotOrder(input, decimalOptions);
    console.log('Swap order submitted, txHash:', txHash);
  } catch (err) {
    console.error('Submit swap order failed:', err);
  }
}

submitSwapOrder();

SDK

Source code https://github.com/Deland-Labs/hibit-sdk

References

What is HIN?

How to Obtain your HIN and Proxy Key?

Last updated