Unify 'stopPrice' in createOrder
See original GitHub issueUsers can set stop orders (aka conditional orders, aka trigger orders, aka algo orders) by assigning params['stopPrice']
.
When type='market'
it’s a stop market order, and when type='limit'
it’s a stop limit order
Futures/Swap exchanges should set the exchange parameter for reduce only to true
Some exchanges have separate endpoints for stoploss orders and regular orders, so make sure that fetchOrder
and cancelOrder
work as well
Just to reiterate:
PRs for reference:
First, there’s two types/cases of “stops” and we have to differentiate between the two:
- A standalone conditional stop order aka algo order – conditional orders can exist by themselves and can be placed separately from other orders.
- A stop loss order and/or a take profit stop order – those orders can not exist by themselves and are usually tied to a position or to another order that opens a margin position (regardless of the market type, whether it is a contract-margin market or a spot-margin market).
This issue https://github.com/ccxt/ccxt/issues/12044 about the stopPrice
unification is related to type/case (1) ONLY.
The usage of type/case (1) is the following:
Suppose you want to place an order (b) if the price meets some condition. To do that, you can place a special order (a) called “stop conditional” order.
A “stop conditional” order (a) is an order to place another “triggered” order (b). That triggered order (b) can be either an order to open a new contract-position, or it could be a spot-order, pretty much any kind of order. It does not care if you have a position or not. When the price condition is met, then the conditional stop order (a) will be triggered, and it will result in placing another triggered order (b) of type/amount/price that the user specifies. So, in general, to place a conditional stop order (a), the user has to supply to createOrder()
:
- conditional
stopPrice
– this is related to the conditional order (a) itself - triggered
type
('market'
or'limit'
) – this is related to the order (b) that will be placed by the conditional order, when triggered - triggered
amount
– this is related to the order (b) that will be placed by the conditional order, when triggered - triggered
price
(if'limit'
) – this is related to the order (b) that will be placed by the conditional order, when triggered
So, the stopPrice
conditional order (a) type/case (1) is just a way of conditionally-placing another triggered order (b) if the market meets some condition. It will be triggered when that condition is met. If the desired condition never occurs again, then the conditional order (a) will never be triggered, it will wait until you cancel it. The order (b) won’t be placed at all, if the condition is never met.
The usage of type/case (2) is the following:
Suppose you want to open a contract-margin position or spot-margin position by placing an order (a).
You also want to close that position when your desired unrealized profit meets a certain level, in percentage or in absolute prices. At that point you want to realize or “fix” your unrealized profits on that open position. You want to close a profitable position at some point with another order that would fix the profits on that position. That is called “take profit stop” order. (b)
And you also want to close that position if the market goes against your expectation, and when your losses reach a certain level, you want to stop getting further losses, or _“fix” your losses. That is called a “stop loss” order. ©
In this case, the user wants to place order (a) and attach two stop-orders (b) and © to the resulting position that will be opened by order (a).
Therefore, in createOrder()
, the user needs to specify a set of params for all three orders:
- opening order (a) amount
- opening order (a) type (
'market'
or'limit'
) - opening order (a) price (if
'limit'
) - closing order (b)
stopLossPrice
– this is optional - closing order ©
takeProfitPrice
– this is optional
Note, that the amount is not specified for orders (b) and ©, cause those orders will usually close the entire amount
of the position specified in order (a).
Since both orders (b) and © are optional, the user can skip any of the two if he wants to close that position manually.
Also, orders of type (b) and © can be added/attached later to an already existing open position.
So, stop-loss/take-profit orders cannot exist by themselves, cause their purpose is to fix losses and profits on existing positions (this works for both contract margin and spot margin).
There is no unification schema for type/case (2) at this time. It is yet to be designed. Probably with a pair of extra params like stopLossPrice
and takeProfitPrice
(as opposed to stopPrice
in case (1)).
Once again, this issue https://github.com/ccxt/ccxt/issues/12044 about the stopPrice
unification is related to type/case (1) ONLY.
One more note: of course, the user can cancel/fetch/edit orders (1a) and (1b) as well the user can cancel/fetch/edit orders (2a), (2b) and (2c). The difference is how you place them and to what they’re referred, applied or tied.
Start with the certified exchanges
- aax
- ascendex
- binance #11852
- binancecoinm #11852
- binanceusdm #11852
- binanceus #11852
- bitmart #13137
- bitvavo
- currencycom #12410
- ftx
- ftxus
- gateio #11844
- huobi
- huobijp #13137
- huobipro
- idex
- mexc #12302
- okx #13440
- wavesexchange #13137
- zb #12772
and these are some popular exchanges it should also be unified in
- bitfinex
- bitfinex2
- bitmex
- bittrex #12904
- bybit #13075
- coinbase #13137
- coinbaseprime
- coinbasepro
- deribit
- kraken
- krakenfutures
- kucoin #12836
- kucoinfutures
- phemex
And then the rest of the exchanges
- bequant
- bibox #13527
- bigone
- bit2c
- bitbank
- bitbay
- bitbns
- bitcoincom
- bitflyer
- bitforex #13906
- bitget #13238
- bithumb
- bitpanda
- bitrue
- bitso
- bitstamp #13906
- bitstamp1
- bl3p
- blockchaincom #12149
- btcalpha #13906
- btcbox
- btcmarkets
- btctradeua
- btcturk
- buda
- bw #13906
- bytetrade #13906
- cdax #13906
- cex #13393
- coincheck
- coinex #13013
- coinfalcon #13906
- coinmate
- coinone #13906
- coinspot #13906
- crex24
- cryptocom
- delta
- digifinex #13906
- eqonex
- equos
- exmo
- flowbtc
- fmfwio
- gemini
- hitbtc
- hitbtc3 #12357
- hollaex
- independentreserve #13906
- indodax #13906
- itbit #13906
- kuna
- latoken
- latoken1
- lbank #13906
- lbank2 #13446
- liquid
- luno
- lykke #13906
- mercado
- ndax
- novadax
- oceanex
- okcoin
- paymium #13906
- poloniex
- probit #13906
- qtrade #13906
- ripio
- stex
- therock
- tidebit
- tidex
- timex #13906
- upbit
- vcc
- wazirx
- whitebit
- woo #13137
- xena
- yobit #13906
- zaif
- zipmex
- zonda
Once it’s unified could you check the exchange please
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:24 (21 by maintainers)
@DoctorSlimm for example, some exchanges don’t have market orders. For those we used to set
exchange.has['createMarketOrder'] = false
. That would indicate to a user, that the exchange does not support market orders. There’s a corresponding sub-family of unified helper methodscreateMarketOrder
,createMarketBuyOrder
andcreateMarketSellOrder
, in the base classes.We don’t have a specific flag for stop orders yet, so you can skip this exchange for now, we might add a unified helper like
createStopOrder
later, and then we will designate the missing stop-order functionality asexchange.has['createStopOrder'] = false
or something like that.@ttodua @Dan-krm @carlosmiei @DoctorSlimm
I created a task list, once you unify stopPrice on an exchange, can you check the box for that exchange please?
Thanks