class TradingPlatform:
def buy_order(self, price, quantity):
print(f"Buying ${price:.2f}\t{quantity:.4f}")

def place_stop_loss_order(self, price):
    print(f"Stop Loss order placed at ${price:.2f}")
def calculate_order_sizes(total_equity, num_orders, equity_to_risk):
risk_amount = total_equity * equity_to_risk
order_sizes = []
for i in range(num_orders):
order_allocation = (i + 1) / num_orders
order_size = risk_amount * order_allocation
order_sizes.append(round(order_size, 4))
return order_sizes

def adjust_position_sizes(order_sizes, stop_loss_percent):
total_risk = sum(order_sizes)
stop_loss_multiplier = 1 / (1 - stop_loss_percent)
adjusted_sizes = [size * stop_loss_multiplier for size in order_sizes]
return adjusted_sizes

def place_scaled_buy_orders(entry_price, num_orders, total_equity, trading_platform, equity_to_risk, stop_loss_percent):
price_range = entry_price * price_range_percent
start_price = entry_price
stop_price = entry_price - price_range

order_sizes = calculate_order_sizes(total_equity, num_orders, equity_to_risk)
adjusted_sizes = adjust_position_sizes(order_sizes, stop_loss_percent)

price_gap = price_range / (num_orders - 1)

orders = []
for i in range(num_orders):
    orders.append((round(start_price, 2), adjusted_sizes[i]))
    start_price -= price_gap

stop_loss_price = min(orders, key=lambda x: x[0])[0] * (1 - stop_loss_percent)  

for order in orders:
    trading_platform.buy_order(order[0], order[1])

trading_platform.place_stop_loss_order(stop_loss_price)
import requests, time, hashlib, hmac, uuid, user

recv_window = str(5000); method_post = "POST"; method_get ="GET"

def HTTP_Request(endPoint, method, payload, Info):
timestamp = str(int(time.time() * 10 ** 3))
user.headers.update({'X-BAPI-TIMESTAMP': timestamp, 'X-BAPI-SIGN': genSignature(timestamp, payload, recv_window)})
url_with_endpoint = user.url_bybit_trade + endPoint; data = payload if method == "POST" else None
response = requests.Session().request(method, f"{url_with_endpoint}?{payload}" if method != "POST" else url_with_endpoint, headers=user.headers, data=data)
print(response.text, f"{Info}")

def genSignature(time_stamp, payload, recv_window):
param_str = str(time_stamp) + user.api_key + recv_window + payload
hash_obj = hmac.new(bytes(user.secret_key, "utf-8"), param_str.encode("utf-8"), hashlib.sha256)
signature = hash_obj.hexdigest()
return signature

response = requests.get(user.url_current_price, params={'symbol': user.symbol})

if response.status_code == 200:
data = response.json()
current_price = float(data['result'][0]['last_price'])

entry_price = current_price

num_orders = 15
total_equity = 10000
equity_to_risk = 0.1  
stop_loss_percent = 0.1  
price_range_percent = 0.02  

platform = TradingPlatform()

place_scaled_buy_orders(entry_price, num_orders, total_equity, platform, equity_to_risk, stop_loss_percent)

buy_orderLinkId, sell_orderLinkId = uuid.uuid4().hex, uuid.uuid4().hex

params_get_ballance ='category=linear&coin=USDT&accountType=CONTRACT'
HTTP_Request(user.endpoint_get_ballance,method_get,params_get_ballance,"Ballance") #Get Ballance

leverage_params = f'{{"category":"linear","symbol": "{user.symbol}","buyLeverage": "{user.buy_lev}","sellLeverage": "{user.sell_lev}"}}'
HTTP_Request(user.endpoint_lev, method_post, leverage_params, "Leverage") # Set Leverage

cancel_all_stop_params = f'{{"category":"linear","symbol": "{user.symbol}"}}'
HTTP_Request(user.endpoint_cancel_all, method_post, cancel_all_stop_params, "Cancel All Unfilled Orders")
the response from the user.endpoint_get_ballance contains an "equity" value which I would like to replace the "total_equity" with

here is an example of the ballance responce

{"retCode":0,"retMsg":"OK","result":{"list":[{"accountType":"CONTRACT","accountIMRate":"","accountMMRate":"","totalEquity":"","totalWalletBalance":"","totalMarginBalance":"","totalAvailableBalance":"","totalPerpUPL":"","totalInitialMargin":"","totalMaintenanceMargin":"","accountLTV":"","coin":[{"coin":"USDT","equity":"3023.68687057","usdValue":"","walletBalance":"3023.68687057","borrowAmount":"","availableToBorrow":"","availableToWithdraw":"3023.68687057","accruedInterest":"","totalOrderIM":"0","totalPositionIM":"0","totalPositionMM":"","unrealisedPnl":"0","cumRealisedPnl":"-6976.31312943"}]}]},"retExtInfo":{},"time":1701021698927} Ballance