Limit Order Running On Node

How to Install the sdk in your project

npm i @openocean.finance/limitorder-sdk

How to use the sdk in your project

import { LimitOrderNodeSdk } from '@openocean.finance/limitorder-sdk'

Demo

import { LimitOrderNodeSdk } from '@openocean.finance/limitorder-sdk';
import Web3 from "web3";
import axios from "axios";
// let tunnel = require('tunnel')



let chainId = 56
const providerUrl = 'https://bsc-dataseed1.ninicoin.io';
const web3 = new Web3(providerUrl);

let privateKey = 'Your wallet private key'

let inToken = {
  "address": "0x55d398326f99059ff775485246999027b3197955",
  "decimals": 18,
  "symbol": "USDT",
}
let outToken = {
  "address": "0xe9e7cea3dedca5984780bafc599bd69add087d56",
  "decimals": 18,
  "symbol": "BUSD"
}
let gasPrice = 3 * (10 ** 9)

const baseUrl = 'https://open-api.openocean.finance'
// const agent = tunnel.httpsOverHttp({
//   proxy: {
//     host: '127.0.0.1',
//     port: 7890,
//   }
// });

let openoceanLimitOrderSdk = new LimitOrderNodeSdk(chainId, web3, privateKey)

async function createOrder() {
  let orderData = await openoceanLimitOrderSdk.createLimitOrder(
    {
      makerTokenAddress: inToken.address,
      makerTokenDecimals: inToken.decimals,
      takerTokenAddress: outToken.address,
      takerTokenDecimals: outToken.decimals,
      makerAmount: 1 * (10 ** inToken.decimals) + '',
      takerAmount: 2 * (10 ** outToken.decimals) + '',
      gasPrice,
      expire: '6Month'
    }
  )

  const result = await axios.post(
    `${baseUrl}/v1/${chainId}/limit-order`,
    orderData,
    {
      headers: {
        'Content-Type': 'application/json',
      },
      // httpsAgent: agent,
      // proxy: false,
    }
  );
  // If you get a 403 error, you need to use tunnel
  console.log(result)
  
}


async function cancelOrder() {
  let orderList = await getOrderList()

  if (orderList && orderList.length) {
    // Cancel the first order
    const order = orderList[0];
    const result = await axios.post(
      `${baseUrl}/v1/${chainId}/limit-order/cancelLimitOrder`,
      { orderHash: order.orderHash },
      {
        // httpsAgent: agent,
        // proxy: false,
      }
    );

    const { status } = (result && result.data) || {};
    if (!(status === 3 || status === 4)) {
      let res = await openoceanLimitOrderSdk.cancelLimitOrder(
        {
          orderData: order.data,
          gasPrice,
        }
      );
      console.log(res)
    }
  }
}



async function getOrderList() {
  const reqUrl = `${baseUrl}/v1/${chainId}/limit-order/address/${openoceanLimitOrderSdk.signerAddress}?page=1&limit=100&statuses=[1,2,5]&sortBy=createDateTime&exclude=0`;
  const { data } = await axios.get(reqUrl, {
    // httpsAgent: agent,
    // proxy: false,
  });
  return data.data
}


createOrder()
// cancelOrder()


Last updated