please optimize the following already working python script, so that it runs faster and is less consuming.
import os

import time

import datetime

import pandas as pd

import json

import random

from dotenv import load_dotenv

from pyokx import OKXClient, Account, Trade, Publicdata

load_dotenv()

True

client = OKXClient(

    key = os.getenv('OKXapikey'),

    secret = os.getenv('OKXsecretkey'),

    passphrase = os.getenv('PASSPHRASE'),

)

account = Account(client)

tradeacc = Trade(client)

public = Publicdata(client)

while True:

    time.sleep(random.randint(60, 180)) 

    api_response = account.get_positions() 

    positions = api_response.to_df() 

    positive_upl_trade_ids = []

    resultsToReopen = []

    positions['upl'] = positions['upl'].astype(float)

    positions['uplRatio'] = positions['uplRatio'].astype(float)

    for index, row in positions.iterrows():

        if row['uplRatio'] > 0.08 and row['upl'] > 0.005:

            positive_upl_trade_ids.append({'markPx': row['markPx'],'lever': row['lever'],'instType': row['instType'],'tradeId': row['tradeId'],'upl': row['upl'],'uplRatio': row['uplRatio'],'ccy': row['ccy'], 'posCcy': row['posCcy'], 'instId': row['instId'], 'mgnMode': row['mgnMode'], 'posSide': row['posSide'] })

​

            

    for trade in positive_upl_trade_ids:

        trade_id = trade['tradeId']

        upl = trade['upl']

        inst_id = trade['instId']

        mgnMode = trade['mgnMode']

        posSide = trade['posSide']

        instType = trade['instType']

        lever = trade['lever']

        markPx = trade['markPx']

        ccy = trade['ccy'] 

        api_response = tradeacc.close_positions(inst_id,mgnMode, "", "","", posSide ) 

        print("S ",inst_id, " ",datetime.datetime.now(), " ---->PX: ", markPx, " ---->PL: ", upl) 

        time.sleep(random.randint(183, 1167))

        api_response = account.get_maximum_available_tradable_amount(inst_id, mgnMode)

        df_response = api_response.to_df()

        availBuy = float(df_response['availBuy'])

        api_response = public.get_instruments(instType,inst_id)

        df_response = api_response.to_df()

        minSz = float(df_response['minSz'])

        tickSz = float(df_response['tickSz'])

        ctMult = float(df_response['ctMult'])

        ctVal = float(df_response['ctVal'])

        lotSz = float(df_response['lotSz'])  

        settleCcy = df_response['settleCcy']

        lever = float(lever)

        markPx = float(markPx)

        amount_of_coins = ((availBuy/markPx)*lever/10*ctMult) Avoid using the following keywords: publicdata, posside, datetime, availbuy
user