node-binance-api icon indicating copy to clipboard operation
node-binance-api copied to clipboard

Precision is over the maximum defined for this asset.

Open Naografix opened this issue 4 years ago • 10 comments

Hello

I'm tring in the Binance Future's testnet and I got an error precision every time... I don't understand how to fix it.

    let price = await GetLastPrice();    
    let stepSize = global.filters[pair].stepSize; //pair = BTCUSDT
    let precision = stepSize.toString().split(".")[1].length || 0;
    let amount = (positionSizeInUsdt / price); //positionSizeInUsdt = 10000
    amount = binance.roundStep(amount, stepSize);
    console.log("Buy MARKET " + pair + " quantity: " + amount.toFixed(precision)+ " - stepSize: " + stepSize + " - precision: " + precision + " at: " + price);
    let buyOrder = await binance.futuresMarketBuy(pair, amount.toFixed(precision), {newOrderRespType: 'RESULT'});
    console.log(buyOrder);

And I got this error:

Buy MARKET BTCUSDT quantity: 0.268118 - stepSize: 0.00000100 - precision: 8 at: 37296.94000000 [Object: null prototype] { code: -1111, msg: 'Precision is over the maximum defined for this asset.' }

What is wrong with my code?

Thanks!

Naografix avatar Feb 05 '21 19:02 Naografix

I fixed the stepSize to BTCUSDT with precision 6 and not 8. I'd the same problem.

37296.94000000 <= here you have 8

aquilatrindade avatar Feb 24 '21 19:02 aquilatrindade

after precision convert to string

and if a precision = 6 or 8 and price 1.23450000 you must erace last zero to 1.2345

you look at minPrice in PRICE_FILTER?

gavcat avatar Mar 17 '21 14:03 gavcat

I also struggled with this problem and I figured out that for futures the precision is smaller than for spot trading. E.g. for BTCUSDT it's 3 but you can check in the application for the specific pair (just try to buy in futures and below the scroll it will show the amount where you can figure out the precision).

hronnie avatar Mar 20 '21 21:03 hronnie

I also struggled with this problem and I figured out that for futures the precision is smaller than for spot trading. E.g. for BTCUSDT it's 3 but you can check in the application for the specific pair (just try to buy in futures and below the scroll it will show the amount where you can figure out the precision).

you've saved my time. is there any API from Binance to check that?

hungbang avatar Dec 30 '21 08:12 hungbang

Oh I found that, we can use get exchange info API to see quantityPrecision

hungbang avatar Dec 30 '21 08:12 hungbang

Hi I am facing a very strange bug today, can anyone help me? I am calling this function futuresMarketSell to maker a sell order for BTCUSDT, qty: 0.00091 but I got this error: Precision is over the maximum defined for this asset not sure what is wrong here!

vdtuan avatar Mar 16 '22 05:03 vdtuan

futuresMarketBuy

Did you solve your issues? I need your help. Got this issue:

Object: null prototype] {
  code: -1111,
  msg: 'Precision is over the maximum defined for this asset.'
}

using this line of code:

quantity = parseFloat(20 / 0.02396).toFixed(5);

binance.futuresMarketBuy('GALAUSDT', quantity)
  .then(resp => console.info(resp))
  .catch(error => console.error(error));

Thank you for the help.

jamestangeres avatar Jul 06 '23 16:07 jamestangeres

Hey,

Yes I did. The trick is that you have to use the price precision from the symbol information. And please make sure that you are using the price precision for the price and quantity precision for quantity. Here is my method, maybe it helps (I'm getting the precision numbers from a mapping but you can get it from the exchange info but I didn't want to always get it since it's quite huge):

/**

  • Formats number to precision (Binance only accepts numbers with correct precision by the symbol) */ public formatNumberToPrecision(symbol: string, numberToPrecision: number, precisionType: PRECISION_TYPE): string { functions.logger.debug(Entering into formatNumberToPrecision with Symbol: ${symbol}, Number to precision: ${numberToPrecision}, Precision type: ${precisionType}); numberToPrecision = Math.abs(numberToPrecision); const precision = FUTURES_PRICE_PRECISION_MAPPING.get(symbol); let precisionValue: number; switch (precisionType) { case (PRECISION_TYPE.QUANTITY_PRECISION): { precisionValue = precision.quantityPrecision; break; } case (PRECISION_TYPE.PRICE_PRECISION): { precisionValue = precision.pricePrecision === 0 ? 0 : precision.pricePrecision - 1; } } const pow = Math.pow(10, precisionValue); const truncated = Math.trunc(numberToPrecision * pow); return (truncated/pow).toFixed(precisionValue); }

On Thu, 6 Jul 2023 at 18:38, jamestangeres @.***> wrote:

futuresMarketBuy

Did you solve your issues? I need your help. Got this issue:

Object: null prototype] { code: -1111, msg: 'Precision is over the maximum defined for this asset.' }

using this line of code:

quantity = parseFloat(20 / 0.02396).toFixed(5);

binance.futuresMarketBuy('GALAUSDT', quantity) .then(resp => console.info(resp)) .catch(error => console.error(error));

Thank you for the help.

— Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/577#issuecomment-1623984357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7FQDVN4R5HHBWCCGC3EC3XO3SZ5ANCNFSM4XFJUVGQ . You are receiving this because you commented.Message ID: @.***>

hronnie avatar Jul 06 '23 16:07 hronnie

Hey, Yes I did. The trick is that you have to use the price precision from the symbol information. And please make sure that you are using the price precision for the price and quantity precision for quantity. Here is my method, maybe it helps (I'm getting the precision numbers from a mapping but you can get it from the exchange info but I didn't want to always get it since it's quite huge): /** * Formats number to precision (Binance only accepts numbers with correct precision by the symbol) / public formatNumberToPrecision(symbol: string, numberToPrecision: number, precisionType: PRECISION_TYPE): string { functions.logger.debug(Entering into formatNumberToPrecision with Symbol: ${symbol}, Number to precision: ${numberToPrecision}, Precision type: ${precisionType}); numberToPrecision = Math.abs(numberToPrecision); const precision = FUTURES_PRICE_PRECISION_MAPPING.get(symbol); let precisionValue: number; switch (precisionType) { case (PRECISION_TYPE.QUANTITY_PRECISION): { precisionValue = precision.quantityPrecision; break; } case (PRECISION_TYPE.PRICE_PRECISION): { precisionValue = precision.pricePrecision === 0 ? 0 : precision.pricePrecision - 1; } } const pow = Math.pow(10, precisionValue); const truncated = Math.trunc(numberToPrecision * pow); return (truncated/pow).toFixed(precisionValue); } On Thu, 6 Jul 2023 at 18:38, jamestangeres @.> wrote: futuresMarketBuy Did you solve your issues? I need your help. Got this issue: Object: null prototype] { code: -1111, msg: 'Precision is over the maximum defined for this asset.' } using this line of code: quantity = parseFloat(20 / 0.02396).toFixed(5); binance.futuresMarketBuy('GALAUSDT', quantity) .then(resp => console.info(resp)) .catch(error => console.error(error)); Thank you for the help. — Reply to this email directly, view it on GitHub <#577 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7FQDVN4R5HHBWCCGC3EC3XO3SZ5ANCNFSM4XFJUVGQ . You are receiving this because you commented.Message ID: @.*>

Thank you for your reply. I appreciates it.. I'm able to buy using futuresMarketBuy.

I have questions, on my test account I have 25 usdt. I tried to use 20 usdt and it getting an msg of 'Margin is insufficient.' so I reduce it to 15 and I able to execute to the futuresBuyMarket.

Why using 20 usdt is margin insufficient?

Here's my code snippet for your reference:

Can you help me review my code if its correct? Thanks again


const usdtAccount = 15; // assuming the current balance of USDT is 25
const currentPrice = 12.629; // assuming the current price of AVAXUSDT is 12.629

const pricePrecision = formatNumberToPrecision(symbol, currentPrice, 'PRICE_PRECISION');
const qtyPrecision = formatNumberToPrecision(symbol, usdtAccount, 'QUANTITY_PRECISION');

const quantity = (qtyPrecision / pricePrecision).toFixed(0); // AVAX quantityPrecision: 0

console.log('quantity: ' + quantity);

binance.futuresMarketBuy(symbol, quantity)
  .then(resp => console.info(resp))
  .catch(error => console.error(error));

jamestangeres avatar Jul 07 '23 11:07 jamestangeres

No worries. I'm not a support guy 😉

On 2023. Jul 7., Fri at 13:08, jamestangeres @.***> wrote:

Hey, Yes I did. The trick is that you have to use the price precision from the symbol information. And please make sure that you are using the price precision for the price and quantity precision for quantity. Here is my method, maybe it helps (I'm getting the precision numbers from a mapping but you can get it from the exchange info but I didn't want to always get it since it's quite huge): /** * Formats number to precision (Binance only accepts numbers with correct precision by the symbol)

*/ public formatNumberToPrecision(symbol: string, numberToPrecision: number, precisionType: PRECISION_TYPE): string { functions.logger.debug(Entering into formatNumberToPrecision with Symbol: ${symbol}, Number to precision: ${numberToPrecision}, Precision type: ${precisionType}); numberToPrecision = Math.abs(numberToPrecision); const precision = FUTURES_PRICE_PRECISION_MAPPING.get(symbol); let precisionValue: number; switch (precisionType) { case (PRECISION_TYPE.QUANTITY_PRECISION): { precisionValue = precision.quantityPrecision; break; } case (PRECISION_TYPE.PRICE_PRECISION): { precisionValue = precision.pricePrecision === 0 ? 0 : precision.pricePrecision - 1; } } const pow = Math.pow(10, precisionValue); const truncated = Math.trunc(numberToPrecision * pow); return (truncated/pow).toFixed(precisionValue); } … <#m_6062578737899020505_> On Thu, 6 Jul 2023 at 18:38, jamestangeres @.> wrote: futuresMarketBuy Did you solve your issues? I need your help. Got this issue: Object: null prototype] { code: -1111, msg: 'Precision is over the maximum defined for this asset.' } using this line of code: quantity = parseFloat(20 / 0.02396).toFixed(5); binance.futuresMarketBuy('GALAUSDT', quantity) .then(resp => console.info http://console.info(resp)) .catch(error => console.error(error)); Thank you for the help. — Reply to this email directly, view it on GitHub <#577 (comment) https://github.com/jaggedsoft/node-binance-api/issues/577#issuecomment-1623984357>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7FQDVN4R5HHBWCCGC3EC3XO3SZ5ANCNFSM4XFJUVGQ https://github.com/notifications/unsubscribe-auth/AA7FQDVN4R5HHBWCCGC3EC3XO3SZ5ANCNFSM4XFJUVGQ . You are receiving this because you commented.Message ID: @.>

Thank you for your reply. I appreciates it.. I'm able to buy using futuresMarketBuy.

I have questions, on my test account I have 25 usdt. I tried to use 20 usdt and it getting an msg of 'Margin is insufficient.' so I reduce it to 15 and I able to execute to the futuresBuyMarket.

Why using 20 usdt is margin insufficient?

Here's my code snippet for your reference:

Can you help me review my code if its correct? Thanks again

const usdtAccount = 15; // assuming the current balance of USDT is 15 const currentPrice = 12.629; // assuming the current price of AVAXUSDT is 12.629

const pricePrecision = formatNumberToPrecision(symbol, currentPrice, 'PRICE_PRECISION'); const qtyPrecision = formatNumberToPrecision(symbol, usdtAccount, 'QUANTITY_PRECISION');

const quantity = (qtyPrecision / pricePrecision).toFixed();

console.log('quantity: ' + quantity);

binance.futuresMarketBuy(symbol, quantity) .then(resp => console.info(resp)) .catch(error => console.error(error));

— Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/577#issuecomment-1625249967, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7FQDXNPNL7F63EP434QALXO7U35ANCNFSM4XFJUVGQ . You are receiving this because you commented.Message ID: @.***>

hronnie avatar Jul 07 '23 15:07 hronnie