Skip to content

Commit

Permalink
fix(v2.15.14): fixes #527 issue with max order ID length from portfol…
Browse files Browse the repository at this point in the history
…io margin, fixes #523 & #526 issue with number handling from multiple orders endpoint
  • Loading branch information
tiagosiebler committed Feb 27, 2025
1 parent c29bc4b commit ddc9a33
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
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.15.13",
"version": "2.15.14",
"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
21 changes: 18 additions & 3 deletions src/usdm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
Kline,
KlinesParams,
NewOCOParams,
numberInString,
OrderBookParams,
OrderIdProperty,
RecentTradesParams,
Expand Down Expand Up @@ -318,15 +319,29 @@ export class USDMClient extends BaseRestClient {
}

/**
* Warning: max 5 orders at a time! This method does not throw, instead it returns individual errors in the response array if any orders were rejected.
* Warning: max 5 orders at a time! This method does not throw, instead it returns
* individual errors in the response array if any orders were rejected.
*
* Known issue: `quantity` and `price` should be sent as strings
* Note: this method will automatically ensure "price" and "quantity" are sent as a
* string, if present in the request. See #523 & #526 for more details.
*/
submitMultipleOrders<TNumberType = number>(
submitMultipleOrders<TNumberType = numberInString>(
orders: NewFuturesOrderParams<TNumberType>[],
): Promise<(NewOrderResult | NewOrderError)[]> {
const stringOrders = orders.map((order) => {
const orderToStringify = { ...order };

// Known issue: `quantity` and `price` should be sent as strings, see #523, #526
const price = orderToStringify['price'];
if (price && typeof price == 'number') {
orderToStringify['price'] = `${price}` as TNumberType;
}

const quantity = orderToStringify['quantity'];
if (quantity && typeof quantity == 'number') {
orderToStringify['quantity'] = `${quantity}` as TNumberType;
}

this.validateOrderId(orderToStringify, 'newClientOrderId');
return JSON.stringify(orderToStringify);
});
Expand Down
2 changes: 1 addition & 1 deletion src/util/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function getOrderIdPrefix(network: BinanceBaseUrlKey): string {
}

export function generateNewOrderId(network: BinanceBaseUrlKey): string {
const id = nanoid(25);
const id = nanoid(22);
const prefixedId = 'x-' + getOrderIdPrefix(network) + id;

return prefixedId;
Expand Down

0 comments on commit ddc9a33

Please sign in to comment.