Fixed the function of setting TP and SL
This commit is contained in:
@@ -54,12 +54,6 @@ async def start_trading_cycle(
|
|||||||
tg_id=tg_id,
|
tg_id=tg_id,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
mode=0)
|
mode=0)
|
||||||
await set_margin_mode(tg_id=tg_id, margin_mode=margin_type)
|
|
||||||
await set_leverage(
|
|
||||||
tg_id=tg_id,
|
|
||||||
symbol=symbol,
|
|
||||||
leverage=leverage,
|
|
||||||
)
|
|
||||||
|
|
||||||
await rq.set_user_deal(
|
await rq.set_user_deal(
|
||||||
tg_id=tg_id,
|
tg_id=tg_id,
|
||||||
@@ -316,7 +310,12 @@ async def open_positions(
|
|||||||
try:
|
try:
|
||||||
client = await get_bybit_client(tg_id=tg_id)
|
client = await get_bybit_client(tg_id=tg_id)
|
||||||
get_ticker = await get_tickers(tg_id, symbol=symbol)
|
get_ticker = await get_tickers(tg_id, symbol=symbol)
|
||||||
price_symbol = safe_float(get_ticker.get("lastPrice")) or 0
|
|
||||||
|
if get_ticker is None:
|
||||||
|
price_symbol = 0
|
||||||
|
else:
|
||||||
|
price_symbol = safe_float(get_ticker.get("lastPrice"))
|
||||||
|
|
||||||
instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol)
|
instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol)
|
||||||
qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep")
|
qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep")
|
||||||
qty_step = safe_float(qty_step_str)
|
qty_step = safe_float(qty_step_str)
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ async def set_tp_sl_for_position(
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = await get_bybit_client(tg_id)
|
client = await get_bybit_client(tg_id)
|
||||||
|
take_profit = round(take_profit_price, 6) if take_profit_price is not None else None
|
||||||
|
stop_loss = round(stop_loss_price, 6) if stop_loss_price is not None else None
|
||||||
resp = client.set_trading_stop(
|
resp = client.set_trading_stop(
|
||||||
category="linear",
|
category="linear",
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
takeProfit=str(round(take_profit_price, 5)),
|
takeProfit=str(take_profit) if take_profit is not None else None,
|
||||||
stopLoss=str(round(stop_loss_price, 5)),
|
stopLoss=str(stop_loss) if stop_loss is not None else None,
|
||||||
positionIdx=position_idx,
|
positionIdx=position_idx,
|
||||||
tpslMode="Full",
|
tpslMode="Full",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user