import requests
import csv

# Define the base URL and API key
base_url = "http://localhost:8080/api/trades"
api_key = "KEY"

# Prepare the data in the required format
# Example CSV parsing, assuming you've already read the file into `csv_data`
csv_data = [
    {
        "Account": "1011463",
        "T/D": "04/24/2025",
        "S/D": "04/24/2025",
        "Currency": "USD",
        "Type": "stock",
        "Side": "S",
        "Symbol": "APPL",
        "Qty": 10,
        "Price": 169.679,
        "Exec Time": "00:01:04",
        "Comm": 1,
        "SEC": 0,
        "TAF": 0,
        "NSCC": 0,
        "Nasdaq": 0,
        "ECN Remove": 0,
        "ECN Add": 0,
        "Gross Proceeds": 2494,
        "Net Proceeds": 2494.93,
        "Clr Broker": "",
        "Liq": "",
        "Note": ""
    }
]

# Prepare the request body
payload = {
    "data": csv_data,
    "selectedBroker": "template",
    "uploadMfePrices": False,
}

# Set headers including the API key
headers = {
    "api-key": api_key,
    "Content-Type": "application/json"
}

# Send POST request
response = requests.post(base_url, json=payload, headers=headers)

# Check the response status
if response.status_code == 200:
    print("Trades successfully imported!")
else:
    print(f"Failed to import trades: {response.status_code}, {response.text}")
