fairdesk / fairdesk-api-docs

API docs for fairdesk exchange
5 stars 7 forks source link

[nodejs] Future place order demo in nodejs #8

Open mossding opened 7 months ago

mossding commented 7 months ago
const axios = require("axios");
const hmac256 = require("crypto-js/hmac-sha256");
const { v4: uuidv4 } = require("uuid");

const api_key = "(Please use your own account to create it in the personal center of fairdesk.com)";
const secret_key = "(Please use your own account to create it in the personal center of fairdesk.com)";

const baseurl = "https://api.fairdesk.com";
const path = "/api/v1/private/trade/place-order";
const url = baseurl + path;

const postPlaceOrder = async () => {
  const payload = {
    quantity: "0.001",
    price: "22601.5",
    side: "BUY",
    type: "LIMIT",
    timeInForce: "GTC",
    symbol: "btcusdt",
    clientOrderId: "API_" + uuidv4(),
    orderRespType: "ACK",
  };

  const time_stamp = String((new Date().getTime() + 60) * 10 ** 3);
  const param_str = path + time_stamp + JSON.stringify(payload);
  const hash = hmac256(param_str, secret_key).toString();
  const signature = hash;

  headers = {
    "x-fairdesk-access-key": api_key,
    "x-fairdesk-request-signature": signature,
    "x-fairdesk-request-expiry": time_stamp,
    "Content-Type": "application/json",
  };
  try {
    const response = await axios.post(url, payload, { headers: headers });
    console.log(response);
  } catch (error) {
    console.log(error);
  }
};

postPlaceOrder();
mossding commented 7 months ago

Copy trading place order payload data example

{
    "symbol":"btcusdt",
    "clientOrderId":"WEB_YrnHXO00S_RC",
    "isolated":true,
    "orderRespType":"ACK",
    "positionSide":"EACH",
    "price":"21914",
    "quantity":"0.001",
    "side":"BUY",
    "timeInForce":"GTC",
    "type":"LIMIT",
    "reduceOnly":false,
    "copyTradeFlag":true,
    "leverage":25 
}