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.

Calculating LOT Size In OKX

See original GitHub issue

I just started using CCXT few days ago. Just wondering if there’s any easy or direct way to calculate future lot size on OKX or do I have to calculate it manually?

For example, Is there any API which can take the available USDT as an input and give the max lot size in return?

Currently I’m doing something like this,

def fetch_order_qty(symbol):
    
    leverage = 10

    balance_req = okx.fetchBalance()
    balance = balance_req['free']['USDT']
    ticker_req = okx.fetchTicker(symbol)
    ticker_cost = ticker_req['bid']

    # risking 10% of the available capital
    trade_capital = 10/100*balance
    
    ticker_qty = (trade_capital / ticker_cost) * leverage  *  lot_multiplier
    return ticker_qty

print(fetch_order_qty('BTC-USDT-SWAP'))  

But every symbol got different kind of lots. So is there any ways to calculate it. Or is there a way to just directly buy the order using USDT margin amount without mentioning any LOT quantity using CCXT (OKX) ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Jun 21, 2022

Or is there a way to just directly buy the order using USDT margin amount without mentioning any LOT quantity using CCXT (OKX) ?

Yes, with OKX you can do that using the params-overrides in the following manner:

import ccxt
print ('CCXT Version:', ccxt.__version__)
exchange = ccxt.okx({
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_API_SECRET',
    'password': 'YOUR_API_PASSWORD',
})
markets = exchange.load_markets()
# exchange.verbose = True  # uncomment for debugging purposes if necessary
symbol = 'BTC/USDT:USDT'  # same as BTC-USDT-SWAP 
params = {
    'tgtCcy': 'quote_ccy',  # a switch to spend USDT
}
amount = YOUR_USDT_AMOUNT
price = 1  # or set a price for limit orders
order = exchange.create_order(symbol, 'market', 'buy', amount, price, params)

Hope that answers your question, let us know if not. Feel free to reopen this issue or just ask further questions if any.

1reaction
kroitorcommented, Jun 21, 2022

@buckydroid have you checked the market['contractSize'] ?

import ccxt
print ('CCXT Version:', ccxt.__version__)
exchange = ccxt.okx()
markets = exchange.load_markets()
market = exchange.market('BTC/USDT:USDT')  # same as BTC-USDT-SWAP 
print(market['symbol'], 'contractSize =', market['contractSize'])

On a sidenote, I’d suggest using the unified contract names:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calculating OKX LOT Size Using CCXT - Stack Overflow
Just wondering if there's any easy or direct way to calculate future lot size on OKX or do I have to calculate it...
Read more >
How to Use Trading Tools (Calculator & Trading Data) - OKX
You need to choose Type: long or short. Enter the leverage level in the Leverage entry. Enter the open price, close price and...
Read more >
Lotsize — Indicators and Signals - TradingView
Interactive script to calculate lot and position size when you use TradingView to trade on FTX or OKX. You can also use multi...
Read more >
Forex Position Size Calculator (2022) - Securities.io
A forex position size and risk calculator allows you to calculate the suggested lot sizes based on equity, risk percentage, & stop loss....
Read more >
How to Calculate Position Size in Crypto | CEX.IO Tutorial
Successful traders often stick to hard rules regarding position sizing so they never risk too much on one trade. Once you decide your...
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