question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create a limit buy order using the full available amount on the right-hand side of the pair?

See original GitHub issue

Considering that we are using Binance, and we would like to trade over the pair ETH/BTC, for example.

What would it be the best way to create a limit buy order using the full available amount on the right-hand side of the pair?

For example, let’s consider, for explaining purposes, that the price of the pair ETH/BTC is like 10 ETH -> 1 BTC, and we have a total amount of 20 BTC in our balance.

If we were using the Binance UI, we could create a limit buy order (buying ETH) using 100% of our BTC balance (in this case 20 BTC), and we could stipulate the price of 10 ETH for 1 BTC. So when this order is fulfilled, we would get 200 ETH in our balance. How can we do that with CCXT?

Please note, that if this was the inverse, selling ETH, would be easier, since we could get the current ETH balance and sell it all for the stipulated price, with a code like this one (python):

eth_balance = ccxt_exchange_instance.fetchBalance()['free']['ETH']
ccxt_exchange_instance.create_order(
  'ETH/BTC',
  'limit',
  'sell',
  eth_balance,
  10, # 10 ETH -> 1 BTC
  {}
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xCuri0commented, Mar 3, 2021

Use a market order and quoteOrderQty in params to specify amount in the quote currency (BTC) on Binance

0reactions
kroitorcommented, Mar 4, 2021

What could I use as a workaround for that? You said that I could calculate this in userland, what did you have in mind?

A limit order requires the amount and the price, where:

cost (quoteOrderQty) = amount * price

Therefore when both multipliers are known, you can use pure logic + arithmetics to calculate the values of your limit order.

symbol = 'ETH/BTC'  # BTC/USDT, ETH/USDT, BNB/BTC, etc... 
markets = exchange.load_markets()
market = exchange.market(symbol)
quote = market['quote']
balance = exchange.fetch_total_balance()
cost = balance[quote]
ticker = exchange.fetch_ticker(symbol)
price = ticker['last']
amount = cost / price
order = exchange.create_order(symbol, 'limit', side, amount, price)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Buy Limit Order: Definition, Pros & Cons, and Example
A buy limit order is an order to purchase an asset at or below a specified price. The order allows traders to control...
Read more >
How to Trade on Binance.US (Market & Limit Orders)
In this example we are placing a 'Limit' order, make sure the 'Limit' tab is selected. C. Your available balance. Which currency is...
Read more >
Managing open orders - Coinbase Help
You will see that there are two balances: Available and Hold. Funds reserved for open orders are placed on hold and will not...
Read more >
Frequently Asked Questions: Purchase Order – Limit Items
The document includes pairs of questions and answers about the Purchase Orders ... You can choose to create an limit item on the...
Read more >
How to place a limit order on 1inch
Connect your wallet, using this guide;. In the section 'You pay', select the asset you want to sell and enter the amount. ***Placing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found