Foxtrod89

python template for import to TradeNote

Oct 4th, 2025
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | Source Code | 0 0
  1. import requests
  2. import csv
  3.  
  4. # Define the base URL and API key
  5. base_url = "http://localhost:8080/api/trades"
  6. api_key = "KEY"
  7.  
  8. # Prepare the data in the required format
  9. # Example CSV parsing, assuming you've already read the file into `csv_data`
  10. csv_data = [
  11.     {
  12.         "Account": "1011463",
  13.         "T/D": "04/24/2025",
  14.         "S/D": "04/24/2025",
  15.         "Currency": "USD",
  16.         "Type": "stock",
  17.         "Side": "S",
  18.         "Symbol": "APPL",
  19.         "Qty": 10,
  20.         "Price": 169.679,
  21.         "Exec Time": "00:01:04",
  22.         "Comm": 1,
  23.         "SEC": 0,
  24.         "TAF": 0,
  25.         "NSCC": 0,
  26.         "Nasdaq": 0,
  27.         "ECN Remove": 0,
  28.         "ECN Add": 0,
  29.         "Gross Proceeds": 2494,
  30.         "Net Proceeds": 2494.93,
  31.         "Clr Broker": "",
  32.         "Liq": "",
  33.         "Note": ""
  34.     }
  35. ]
  36.  
  37. # Prepare the request body
  38. payload = {
  39.     "data": csv_data,
  40.     "selectedBroker": "template",
  41.     "uploadMfePrices": False,
  42. }
  43.  
  44. # Set headers including the API key
  45. headers = {
  46.     "api-key": api_key,
  47.     "Content-Type": "application/json"
  48. }
  49.  
  50. # Send POST request
  51. response = requests.post(base_url, json=payload, headers=headers)
  52.  
  53. # Check the response status
  54. if response.status_code == 200:
  55.     print("Trades successfully imported!")
  56. else:
  57.     print(f"Failed to import trades: {response.status_code}, {response.text}")
  58.  
Tags: trading
Advertisement