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.

Bug - unable to open short position with TP/SL on v1.84.40 (OKX)

See original GitHub issue
  • OS: Big Sur 11.6
  • Programming Language version: Python 3.8.10
  • CCXT version: 1.84.40
  • Exchange used: OKX

Hi, there seems to be a bug in recent version of CCXT with code that used to work in version 1.62.40. Issue arises in creating TakeProfit/StopLoss when creating a Short position in OKX.

Validated through testing that below code works on 1.62.40 but not on 1.84.40. Basically saying TakeProfit cannot be lower than order price even though it is a Sell order

Errors:

  • “TP trigger price can not be lower than the mark price”
  • “SL trigger price can not be higher than the last price”
symbol = 'GMT/USDT:USDT'

params = {'mgnMode': 'cross'}

OKX.setLeverage(symbol=symbol,leverage=leverage,params=params)

current_price = OKX.fetchTicker(symbol = symbol)['last']

side ='sell'

amount = 15

tp = current_price*(1-0.05)
sl = current_price+(current_price*0.05)

params = {
    'side': 'sell',
    'positionSide':'short',
    'slTriggerPxType': 'mark',
    'tpTriggerPxType': 'mark'
    'tpTriggerPx': tp,
    'tpOrdPx': tp,
    'slTriggerPx': sl,
    'slOrdPx': sl,
    'tdMode': 'cross'
}

# market order
order = OKX.createOrder(type = 'market', symbol=symbol, side=side, amount=amount, price = current_price, params = params)
okex5 {"code":"1","data":[{"algoId":"","sCode":"51280","sMsg":"SL trigger price can not be higher than the last price."}],"msg":""}

okex5 {"code":"1","data":[{"algoId":"","sCode":"51303","sMsg":"TP trigger price can not be lower than the mark price."}],"msg":""}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
frosty00commented, Jun 6, 2022

@bzhongy the new build should arrive in around 15mins, if you can update ccxt and try again after it arrives and report the results here that would be really appreciated!

1reaction
frosty00commented, Jun 6, 2022

@bzhongy thanks for reporting, will try to fix it now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shorting Bitcoin — how to profit from BTC bear markets and ...
If BTC's price falls while your position is open, it becomes profitable, as you can “cover” the short by buying back the asset...
Read more >
Short Selling: The Risks and Rewards | Charles Schwab
Short selling involves borrowing a security whose price you think is going to fall from your brokerage and selling it on the open...
Read more >
Short Selling: Definition, Pros, Cons, and Examples
Short selling occurs when an investor borrows a security, sells it on the open market, and expects to buy it back later for...
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