tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
734 stars 265 forks source link

v2.8.10: fix FuturesPositionTrade type #362

Closed gianpaj closed 10 months ago

gianpaj commented 10 months ago

fix typos and add marginAsset

example trade:

{
    symbol: "BTCUSDT",
    id: 123,
    orderId: 123,
    side: "SELL",
    price: 26832.5,
    qty: 0.025,
    realizedPnl: "0",
    marginAsset: "USDT",
    quoteQty: "670.81250",
    commission: 0.00113016,
    commissionAsset: "BNB",
    time: 1695237604838,
    positionSide: "BOTH",
    buyer: false,
    maker: false
  }

Example code used:

import { USDMClient } from "binance";

const key = process.env.APIKEY || "";
const secret = process.env.APISECRET || "";

const usdmClient = new USDMClient({
  api_key: key,
  api_secret: secret,
  beautifyResponses: true,
});

(async () => {
  try {
    const todayAtMidnight = new Date().setHours(0, 0, 0, 0);
    const startTime = new Date(todayAtMidnight).getTime();

    // @ts-ignore
    const trades = await usdmClient.getAccountTrades({ startTime });
    console.log(trades);
    console.log("number of trades:", trades.length);
  } catch (e) {
    console.error("Error: request failed: ", e);
  }

})();