Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llegal characters found in parameter 'price' #221

Closed
olafkotur opened this issue Jul 19, 2022 · 3 comments
Closed

llegal characters found in parameter 'price' #221

olafkotur opened this issue Jul 19, 2022 · 3 comments

Comments

@olafkotur
Copy link

olafkotur commented Jul 19, 2022

With reference to MainClient.submitNewOrder, I'm getting the following response from Binance:

Illegal characters found in parameter 'price'; legal range is '^([0-9]{1,20})(\.[0-9]{1,20})?$'.

This only seems a problem with a 2 assets that I'm trading, out of 230. both with a very small number as a price 5.8e-7 - I saw a few posts on some other libs saying that binance expects this to be a string. I've had a look at NewSpotOrderParams interface but this only accepts a number.

I'm sending this as a number, so 5.8e-7 === 0.00000058, initially I thought it was some dodgy conversion on my side converting to string including the scientific notation, but unfortunately this isn't the case.

Is there any additional formatting done inside the lib to convert that number to a string before its sent to Binance?

Been stuck on this for some time so any help or pointers would be greatly appreciated.

@tiagosiebler
Copy link
Owner

Hi @olafkotur

I wrote the NewSpotOrderParams interface to mirror the types from the binance api docs:
https://binance-docs.github.io/apidocs/spot/en/#new-order-trade

My library doesn't do any formatting for this, it just passes on the values you've provided. The only validation would be through types and interfaces, but that's build time only.

That also means you could test your theory about passing 0.00000058 or 5.8e-7 using a // @ts-ignore in the line before your code setting price to a string instead of a number. Would be interesting if binance allows strings and numbers in this field, in which case this would only need a small change in NewSpotOrderParams so you can easily pass in such small numbers as strings. Could you try it?

@olafkotur
Copy link
Author

olafkotur commented Aug 2, 2022

Hey @tiagosiebler, I did some more testing with what you mentioned. Works like a charm - Binance API accepts number | string.

In this particular case since the number is so small I had to use an additional library to be able to accurately control the formatting of the number i.e. 6.5e-7 --> 0.00000065.

Out of curiosity I also tested this for the quantity param and this is also the case. For clarity sake, what I propose is the following:

export interface NewSpotOrderParams {
    symbol: string;
    side: OrderSide;
    type: OrderType;
    timeInForce?: OrderTimeInForce;
    quantity?: number | string;
    quoteOrderQty?: number;
    price?: number | string;
    newClientOrderId?: string;
    stopPrice?: number;
    icebergQty?: number;
    newOrderRespType?: OrderResponseType;
    isIsolated?: StringBoolean;
    sideEffectType?: SideEffects;
}

Thanks for the help, really appreciate it! ❤️ I'm gonna try my best to open a PR for this in the next couple of days 🙏🏽

@tiagosiebler
Copy link
Owner

Hey @tiagosiebler, I did some more testing with what you mentioned. Works like a charm - Binance API accepts number | string.

In this particular case since the number is so small I had to use an additional library to be able to accurately control the formatting of the number i.e. 6.5e-7 --> 0.00000065.

Out of curiosity I also tested this for the quantity param and this is also the case. For clarity sake, what I propose is the following:

export interface NewSpotOrderParams {
    symbol: string;
    side: OrderSide;
    type: OrderType;
    timeInForce?: OrderTimeInForce;
    quantity?: number | string;
    quoteOrderQty?: number;
    price?: number | string;
    newClientOrderId?: string;
    stopPrice?: number;
    icebergQty?: number;
    newOrderRespType?: OrderResponseType;
    isIsolated?: StringBoolean;
    sideEffectType?: SideEffects;
}

Thanks for the help, really appreciate it! ❤️ I'm gonna try my best to open a PR for this in the next couple of days 🙏🏽

Nice, this is really useful! Would love to see a PR to update the types based on your finding. Maybe you can include a link to your post here, as a comment on NewSpotOrderParams (since it won't be obvious why it supports a string while docs say number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants