Skip to content

Commit

Permalink
feat(): updated latest changes per release notes - as of 03-11-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Cro committed Nov 4, 2024
1 parent 2cc9f55 commit fe2a424
Show file tree
Hide file tree
Showing 15 changed files with 819 additions and 535 deletions.
976 changes: 492 additions & 484 deletions docs/endpointFunctionList.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions examples/apidoc/CoinMClient/getDownloadIdForFuturesOrderHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/order/asyn
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getDownloadIdForFuturesOrderHistory(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/CoinMClient/getDownloadIdForFuturesTradeHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/trade/asyn
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getDownloadIdForFuturesTradeHistory(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/income/asyn
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getDownloadIdForFuturesTransactionHistory(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/CoinMClient/getFuturesOrderHistoryDownloadLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/order/asyn/id
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getFuturesOrderHistoryDownloadLink(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/CoinMClient/getFuturesTradeHistoryDownloadLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/trade/asyn/id
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getFuturesTradeHistoryDownloadLink(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CoinMClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: dapi/v1/income/asyn/id
// METHOD: GET
// PUBLIC: NO

const client = new CoinMClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getFuturesTransactionHistoryDownloadLink(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/MainClient/getPortfolioMarginProAccountBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { MainClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: sapi/v1/portfolio/balance
// METHOD: GET
// PUBLIC: NO

const client = new MainClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getPortfolioMarginProAccountBalance(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/MainClient/getPortfolioMarginProSpanAccountInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { MainClient } = require('binance');

// This example shows how to call this Binance API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "binance" for Binance exchange
// This Binance API SDK is available on npm via "npm install binance"
// ENDPOINT: sapi/v2/portfolio/account
// METHOD: GET
// PUBLIC: NO

const client = new MainClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getPortfolioMarginProSpanAccountInfo(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "binance",
"version": "2.13.11",
"version": "2.13.12",
"description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
49 changes: 49 additions & 0 deletions src/coinm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CoinMPositionTrade,
CoinMSymbolOrderBookTicker,
FundingRate,
FuturesTransactionHistoryDownloadLink,
GetClassicPortfolioMarginNotionalLimitParams,
PositionRisk,
SymbolOrPair,
Expand Down Expand Up @@ -471,6 +472,54 @@ export class CoinMClient extends BaseRestClient {
return this.getPrivate('dapi/v1/income', params);
}

getDownloadIdForFuturesTransactionHistory(params: {
startTime: number;
endTime: number;
}): Promise<{
avgCostTimestampOfLast30d: number;
downloadId: string;
}> {
return this.getPrivate('dapi/v1/income/asyn', params);
}

getFuturesTransactionHistoryDownloadLink(params: {
downloadId: string;
}): Promise<FuturesTransactionHistoryDownloadLink> {
return this.getPrivate('dapi/v1/income/asyn/id', params);
}

getDownloadIdForFuturesOrderHistory(params: {
startTime: number;
endTime: number;
}): Promise<{
avgCostTimestampOfLast30d: number;
downloadId: string;
}> {
return this.getPrivate('dapi/v1/order/asyn', params);
}

getFuturesOrderHistoryDownloadLink(params: {
downloadId: string;
}): Promise<FuturesTransactionHistoryDownloadLink> {
return this.getPrivate('dapi/v1/order/asyn/id', params);
}

getDownloadIdForFuturesTradeHistory(params: {
startTime: number;
endTime: number;
}): Promise<{
avgCostTimestampOfLast30d: number;
downloadId: string;
}> {
return this.getPrivate('dapi/v1/trade/asyn', params);
}

getFuturesTradeHistoryDownloadLink(params: {
downloadId: string;
}): Promise<FuturesTransactionHistoryDownloadLink> {
return this.getPrivate('dapi/v1/trade/asyn/id', params);
}

/**
*
* Portfolio Margin Endpoints
Expand Down
108 changes: 60 additions & 48 deletions src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ import {
BnsolRewardHistoryRecord,
BnsolRateHistoryRecord,
GetBnsolRateHistoryReq,
PortfolioMarginProSpanAccountInfo,
PortfolioMarginProAccountBalance,
} from './types/spot';

import {
Expand All @@ -553,61 +555,61 @@ export class MainClient extends BaseRestClient {
}

/**
* This method is used to get the latency and time sync between the client and the server.
* This is not official API endpoint and is only used for internal testing purposes.
* Use this method to check the latency and time sync between the client and the server.
* Final values might vary slightly, but it should be within few ms difference.
* If you have any suggestions or improvements to this measurement, please create an issue or pull request on GitHub.
*/
async fetchLatencySummary(): Promise<any> {
const clientTimeReqStart = Date.now();
const serverTime = await this.getServerTime();
const clientTimeReqEnd = Date.now();
console.log('serverTime', serverTime);

const serverTimeMs = serverTime;
const roundTripTime = clientTimeReqEnd - clientTimeReqStart;
const estimatedOneWayLatency = Math.floor(roundTripTime / 2);

// Adjust server time by adding estimated one-way latency
const adjustedServerTime = serverTimeMs + estimatedOneWayLatency;

// Calculate time difference between adjusted server time and local time
const timeDifference = adjustedServerTime - clientTimeReqEnd;

const result = {
localTime: clientTimeReqEnd,
serverTime: serverTimeMs,
roundTripTime,
estimatedOneWayLatency,
adjustedServerTime,
timeDifference,
};

console.log('Time synchronization results:');
console.log(result);

console.log(
`Your approximate latency to exchange server:
* This method is used to get the latency and time sync between the client and the server.
* This is not official API endpoint and is only used for internal testing purposes.
* Use this method to check the latency and time sync between the client and the server.
* Final values might vary slightly, but it should be within few ms difference.
* If you have any suggestions or improvements to this measurement, please create an issue or pull request on GitHub.
*/
async fetchLatencySummary(): Promise<any> {
const clientTimeReqStart = Date.now();
const serverTime = await this.getServerTime();
const clientTimeReqEnd = Date.now();
console.log('serverTime', serverTime);

const serverTimeMs = serverTime;
const roundTripTime = clientTimeReqEnd - clientTimeReqStart;
const estimatedOneWayLatency = Math.floor(roundTripTime / 2);

// Adjust server time by adding estimated one-way latency
const adjustedServerTime = serverTimeMs + estimatedOneWayLatency;

// Calculate time difference between adjusted server time and local time
const timeDifference = adjustedServerTime - clientTimeReqEnd;

const result = {
localTime: clientTimeReqEnd,
serverTime: serverTimeMs,
roundTripTime,
estimatedOneWayLatency,
adjustedServerTime,
timeDifference,
};

console.log('Time synchronization results:');
console.log(result);

console.log(
`Your approximate latency to exchange server:
One way: ${estimatedOneWayLatency}ms.
Round trip: ${roundTripTime}ms.
`,
);
);

if (timeDifference > 500) {
console.warn(
`WARNING! Time difference between server and client clock is greater than 500ms. It is currently ${timeDifference}ms.
if (timeDifference > 500) {
console.warn(
`WARNING! Time difference between server and client clock is greater than 500ms. It is currently ${timeDifference}ms.
Consider adjusting your system clock to avoid unwanted clock sync errors!
Visit https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Timestamp-for-this-request-is-outside-of-the-recvWindow for more information`,
);
} else {
console.log(
`Time difference between server and client clock is within acceptable range of 500ms. It is currently ${timeDifference}ms.`,
);
}
);
} else {
console.log(
`Time difference between server and client clock is within acceptable range of 500ms. It is currently ${timeDifference}ms.`,
);
}

return result;
}
return result;
}

/**
* Abstraction required by each client to aid with time sync / drift handling
Expand Down Expand Up @@ -3376,6 +3378,16 @@ async fetchLatencySummary(): Promise<any> {
return this.getPrivate('sapi/v1/portfolio/interest-history', params);
}

getPortfolioMarginProSpanAccountInfo(): Promise<PortfolioMarginProSpanAccountInfo> {
return this.getPrivate('sapi/v2/portfolio/account');
}

getPortfolioMarginProAccountBalance(params?: {
asset?: string;
}): Promise<PortfolioMarginProAccountBalance[]> {
return this.getPrivate('sapi/v1/portfolio/balance', params);
}

/**
*
* DERIVATIVES - Futures Data - Market
Expand Down
Loading

0 comments on commit fe2a424

Please sign in to comment.