import argparse
import eth_account
import utils
from eth_account.signers.local import LocalAccount
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants
from hyperliquid.info import Info
import json
import requests

def get_histories():
    config = utils.get_config()
    account: LocalAccount = eth_account.Account.from_key(config["secret_key"])
    # exchange = Exchange(account, constants.MAINNET_API_URL)
    info = Info(constants.MAINNET_API_URL, skip_ws=True)



    user_fills = info.user_fills(account.address)

    # print(user_fills)

    # print(json.dumps(user_fills, indent=4))

    url = "https://192.168.10.60/user/coin/history/update_histories"
    # method = "POST"
    # items = json.dumps(list)
    obj = {
        "items": json.dumps(user_fills),
        'user_id': 1
    }


    # response = requests.post(url, json=obj, verify=False)
    response = requests.post(url, json=obj,verify=False)
    print(response.status_code)
    print(response.text)

    # print(f"We try to Market {'Buy' if is_buy else 'Sell'} {sz} {coin}.")

    # order_result = exchange.market_open(coin, is_buy, sz)
    # if order_result["status"] == "ok":
    #     for status in order_result["response"]["data"]["statuses"]:
    #         try:
    #             filled = status["filled"]
    #             print(f'Order #{filled["oid"]} filled {filled["totalSz"]} @{filled["avgPx"]}')
    #         except KeyError:
    #             print(f'Error: {status["error"]}')

if __name__ == "__main__":

    print("get_trade_history")

    get_histories()
    # print(get_histories)
    # parser = argparse.ArgumentParser(description='Market Order Script')
    # parser.add_argument('coin', type=str, help='Cryptocurrency for the order (e.g., DOGE)')
    # parser.add_argument('order_type')
    # parser.add_argument('sz', type=float, help='Size of the order')
    # args = parser.parse_args()

    # place_market_order(args.coin, is_buy, args.sz)
