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

Help calculating buy amount for limit order with full balance against MEXC #22488

Open
ragamufin opened this issue May 14, 2024 · 0 comments
Open
Labels

Comments

@ragamufin
Copy link

Operating System

macOS

Programming Languages

JavaScript

CCXT Version

4.2.79

Description

Can someone help me?
I'm using ccxt to trade against mexc and I can't figure out the math to calculate the buy amount when putting in trades if I try to use my full balance
I get an error from the api saying insufficient position / funds

Let's say I'm trading:
symbol: USDC/USDT
balance: 100.00551067 USDT

I want to buy as much USDC as I can with the full balance of USDT
I'm using a limit order and the maker fee is 0% so no fee

My example code is like so:

const symbol = 'USDC/USDT'
const balance = exchange.amountToPrecision(symbol, 100.00551067)
const price = 1
const amount = exchange.amountToPrecision(symbol, balance / price)

console.log({ symbol, balance, amount }) 

This outputs:

{ "symbol": "USDC/USDT", "balance": 100, "amount": 100 }

This gives the insufficient error when placing a limit order with that amount and price

If I go to the UI and check there I see:
image

  • You can see Maker fee in the top right is 0%
  • The price is below the highest bid so definitely not going to be a market order
  • The amount slider is dragged to 100% and even if I try to increase the Amount or Total it resets to these values
  • USDT balance is truncated to 100.0055 due to precision
  • Amount and Total become 99.9
  • If I change the amount or Total to say 95, it stays 95 which means there is something different happening once you approach the full balance of the account

Can someone tell me what I'm missing? What's the formula for calculating the buy amount when using your total balance?

If I try to sell the full balance (if I have USDC) then the numbers line up perfectly. It's only for buys that I can't the numbers to line up. Trying different amounts over time, it seems to be subtracting 0.1 on the full balance as a part of its calculation

For the limits and precision, here is the output from exchange.market(symbol):
image 2

Thanks in advance to anyone who takes to the time to help me

Code

  

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

No branches or pull requests

2 participants