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.

Create limit order with take profit and stop loss in Kucoin future with ccxt

See original GitHub issue

Hi, I want to create a limit order with take profit and stop loss in Kucoin future exchange.

For ex: I created a long contract and I wanna close it when profit = %4 AND loss = %10 so, what are the params, types, etc.?

I tried with the below code but I think it’s wrong.

Thank you.

  • Windows:
  • Programming Language version: Python
  • CCXT version: 1.77.34
exchange = ccxt.kucoinfutures({
    'apiKey': config.MOH_BUY_API_KEY,
    'secret': config.MOH_BUY_API_SECRET,
    'password': config.MOH_BUY_API_PASSPHRASE
})

symbol = 'AVAX/USDT:USDT'
amount = 1
leverage = 10
side = 'buy'
price = 'Market close price for the symbol in 1 min candels ' #9.75
stopPrice = (100-config.STOPLOSS)*0.01*price

params = {'leverage': leverage, 'stop': 'loss', 'stopPrice': stopPrice , 'stopPriceType': 'TP'}

order = exchange.create_order(symbol=symbol, type='limit', side=side, amount=amount, price=price, params=params)

ccxt.base.errors.BadRequest: kucoinfutures error.createOrder.stopInvalid

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
mefplusxcommented, Jun 6, 2022

@YuxinSUN89 @MohammadTaherkhani Guys! Kucoin give me answer!

Dear User,

Thank you for contacting us.

The Futures has two directions so they need to be discussed separately.

They all use the same API, but the input parameters are different.

POST /api/v1/orders

Param type Description

side String buy or sell

stop String [optional] Either down or up. Requires stopPrice and stopPriceType to be defined

stopPriceType String [optional] Either TP, IP or MP, Need to be defined if stop is specified.

stopPrice String [optional] Need to be defined if stop is specified.

  1. when your side is buy, stop-loss and take-profit price set as follows

    1) stop-loss: side=buy, stop=down, stopPriceType and stopPrice are set according to your needs

    1. take-profit:side=buy, stop=up, stopPriceType and stopPrice are set according to your needs
  2. when your side is sell, stop-loss and take-profit price set as follows

    1) stop-loss: side=sell, stop=up, stopPriceType and stopPrice are set according to your needs

    1. take-profit: side=sell, stop=down, stopPriceType and stopPrice are set according to your needs

python demo:

   # Take Profit & Stop Loss

    order = self.client.create_limit_order(

        symbol='XBTUSDTM',

        side='buy',

        lever=1,

        clientOid=get_uuid(),

        size='1',

        price='55000',

        stop='down',

        stopPrice='56000',  # When the price is reached, it will enter the orderbook and the funds will be frozen

        stopPriceType='MP',

        remark='Its stop-profit is set at $ 55,000 (MP)',

    )

    order = self.client.create_limit_order(

        symbol='XBTUSDTM',

        side='buy',

        lever=1,

        clientOid=get_uuid(),

        size='1',

        price='61000',

        stop='up',

        stopPrice='60500',  # When the price is reached, it will enter the orderbook and the funds will be frozen

        stopPriceType='MP',

        remark='Its stop-loss is set at $ 61,000 (MP)',

    )

If you have any questions or concerns regarding this process, please don’t hesitate to let us know.

Kind regards,

Aaron

KuCoin API Team

1reaction
mortezaataiycommented, Jul 10, 2022

CORRECT:

1)when your main order side is buy, stop-loss and take-profit order set as follows

stop-loss: side=sell, stop=down, stopPriceType and stopPrice are set according to your needs

take-profit:side=sell, stop=up, stopPriceType and stopPrice are set according to your needs

2)when your main order side is sell, stop-loss and take-profit order set as follows

stop-loss: side=buy, stop=up, stopPriceType and stopPrice are set according to your needs

take-profit: side=buy, stop=down, stopPriceType and stopPrice are set according to your needs

NOTIC: For stop-loss and take-profit order, reduceOnly: true

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Set Take Profit and Stop Loss When Placing ... - KuCoin
In the order-placing panel for Limit and Market order, click "Take Profit & Stop Loss", and choose "Last Price" or "Mark Price" to...
Read more >
api - python cctx Kucoin futures take profit - Stack Overflow
For take profit, create a limit order with same size, opposite side and 'reduceOnly':true parameter. def setTp(exchange, symbol: str, ...
Read more >
How to Create a STOP LOSS algorithmically (python & phemex)
in this video i show you exactly how to make a stop loss order in python using the ccxt pro package. it took...
Read more >
KuCoin Futures: Setting Take Profit & Stop Loss (Step-by-Step)
In this video I'll show you step by step how to set a take profit and stop loss order on KuCoin futures.▽ KuCoin...
Read more >
Exchanges — ccxt 2.4.71 documentation
Besides making basic market and limit orders, some exchanges offer margin trading ... your stop loss price } // for a take profit...
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