please optimize and tidy up the following python script. Please ge back the complete rewritten code.
import os

import time

import random

import json

import hmac

import urllib

import base64

import hashlib

import requests

import datetime

import pandas as pd

from pandas import json_normalize

import numpy as np

import datetime

from urllib.parse import urlencode

from dotenv import load_dotenv

from decimal import Decimal, getcontext

import ccxt

from huobi.spot.rest.account import Account

from huobi.spot.rest.market import Market

from huobi.spot.rest.order import Order

from huobi.spot.rest.NAME_1 import NAME_1

# read information from .env file

load_dotenv()

True

# create a TradeClient instance

access_key = os.getenv('HUOBIapikey')

secret_key = os.getenv('HUOBIsecretkey')

clAccount = Account(access_key, secret_key)

clMarket = Market()

clOrder = Order(access_key, secret_key)

clWallet = NAME_1(access_key, secret_key)

exchange = ccxt.huobipro({'apiKey': access_key,'secret': secret_key,'options': {'defaultType': 'swap','defaultSubType': 'inverse','marginType': 'cross'}})

while True:

    time.sleep(random.randint(123, 963))

    def get_id_from_type(accounts, account_type):

        for account in accounts:

            if account['type'] == account_type:

                return account['id']

        return None

​

    data = clAccount.get_accounts()['data']

    spot_id = get_id_from_type(data, 'spot')

​

    params = {

        'account-id': spot_id,

        'accountType': 'spot',

        'valuationCurrency': 'USDT'

    }

​

    data = clAccount.get_balance(params)

    currency_data = data['data']['list']

​

    filtered_data = [

        {

            'currency': entry['currency'],

            'balance': float(entry['balance']),

            'available': float(entry.get('available', 0))

        }

        for entry in currency_data

        if 'available' in entry and float(entry.get('available', 0)) > 0

    ]

​

    df = pd.DataFrame(filtered_data)

​

    params = {

        'account-id': '29519016',

        'symbol': '',

        'states': 'filled'

    }

​

    # Iterate over each row in the DataFrame

    for index, row in df.iterrows():

        symbol = row['currency'] + 'usdt'

        params['symbol'] = symbol

​

        order_data = clOrder.get_orders(params)

​

        if order_data['status'] == 'ok' and len(order_data['data']) > 0:

            order = order_data['data'][0]

            if order['type'] == 'buy-market' and order['state'] == 'filled':

           Write exactly 6 paragraphs each separated with two new lines answering this question. The first paragraph must start with "thieves".
user