i am trying to set take profit order with bybit rest api (testnet)
i followd the docs https://bybit-exchange.github.io/docs/v5/position/trading-stop
but i just cant get it to work
i try to changing :
position_idx to 0 1 2
all so change tpsl_mode to full ,removing stop_loss changing and removing all non required fields
nothing workt
in this last one i get error:'{"retCode":10001,"retMsg":"empty value: apiTimestamp[] apiKey[] apiSignature[]","result":{},"retExtInfo":{},"time":1690745497593}'
def set_take_profit_bybit(symbol,profit_price,quantity):
BASE_URL = 'https://api-testnet.bybit.com'
SET_ISO_ENDPOINT='/v5/position/trading-stop'
endpoint = BASE_URL + SET_ISO_ENDPOINT
timestamp = int(time.time() * 1000)
stop_loss=0
tp_trigger_by='MarkPrice'
sl_trigger_by='IndexPrice'
category='linear'
tpsl_mode='Partial'
tp_order_type='Limit'
sl_order_type='Limit'
tp_size=quantity
sl_size=quantity
tp_limit_price='0.49'
sl_limit_price='0.21'
position_idx=2
payload = {
"api_key": API_KEY,
"category": category,
"symbol": symbol,
"takeProfit": profit_price,
"stopLoss": stop_loss,
"tpTriggerBy": tp_trigger_by,
"slTriggerBy": sl_trigger_by,
"tpslMode": tpsl_mode,
"tpOrderType": tp_order_type,
"slOrderType": sl_order_type,
"tpSize": tp_size,
"slSize": sl_size,
"tpLimitPrice": tp_limit_price,
"slLimitPrice": sl_limit_price,
"positionIdx": position_idx,
"timestamp": timestamp,
}
signature = create_signature(API_SECRET, payload)
payload["sign"] = signature
headers = {
"Content-Type": "application/x-www-form-urlencoded",
}
response = requests.post(endpoint, json=payload, headers=headers)