Here is some code that is working. However I cant confirm that the stop loss and take profits are being placed. I can see my buy order on bybit through the trading view, but nothing to indicate there is a tp or sl.
Could someone please provide some working/proven code?
I know there are ways to place extra orders to simulate this but I would prefer to avoid extra complexity if possible.
def place_order(testmode,type, symbol, side, takeprofitprice, stoplossprice, qty):
# Get the market data
market_data = get_market_ask_price(testmode, symbol="BTCUSDT")
# Get the market price
market_price = float(market_data)
# Calculate the take profit and stop loss prices
params = {
'stopLossPrice': stoplossprice,
'takeProfitPrice': stoplossprice,
}
request = {
"category":"spot",
"symbol":"BTCUSDT",
"side":side,
"orderType":"Limit",
"qty":str(qty), #in btc
"price":str(market_price),
"timeInForce":"GTC",
"orderLinkId":"spot-test-postonly",
"stopLoss":str(stoplossprice),
"takeProfit":str(takeprofitprice)
}
market_order = exchange.privatePostV5OrderCreate(request)
logger("market order",market_order)
symbol = 'BTC/USDT'
open_orders = exchange.fetch_open_orders(symbol=symbol)
logger("open orders",pd.df(open_orders))
return market_order