Welcome
Data & API Access
Download historical market data to train your models.
API Client Examples
import requests
import websocket # pip install websocket-client
import threading
import json
BASE_URL = "http://localhost:7070"
WS_URL = "ws://localhost:7070/ws"
TEAM_CODE = "TEST"
HEADERS = {"X-Team-Code": TEAM_CODE}
def on_message(ws, message):
data = json.loads(message)
if data['type'] == 'TICK':
print(f"Date: {data['date']}")
print(f"Cash: {data['portfolio']['cash']}")
print(f"Valuation: {data['valuation']}")
print(f"Positions: {data['portfolio']['positions']}")
# Get Market Data for BNPQY
for item in data['marketData']:
if item['symbol'] == 'BNPQY':
print(f"BNPQY - Close: {item['close']}, Volume: {item['volume']}")
# Start WebSocket listener
ws = websocket.WebSocketApp(f"{WS_URL}?teamCode={TEAM_CODE}", on_message=on_message)
threading.Thread(target=ws.run_forever).start()
# Start Simulation
requests.post(f"{BASE_URL}/api/simulation/start", headers=HEADERS)
# Place Order
order = {"symbol": "BNPQY", "action": "BUY", "quantity": 10}
requests.post(f"{BASE_URL}/api/order", json=order, headers=HEADERS)
const BASE_URL = "http://localhost:7070";
const WS_URL = "ws://localhost:7070/ws";
const TEAM_CODE = "TEST";
const HEADERS = {"X-Team-Code": TEAM_CODE, "Content-Type": "application/json"};
// Connect to WebSocket
const socket = new WebSocket(`${WS_URL}?teamCode=${TEAM_CODE}`);
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'TICK') {
console.log("Date:", data.date);
console.log("Cash:", data.portfolio.cash);
console.log("Valuation:", data.valuation);
console.log("Positions:", data.portfolio.positions);
// Get Market Data for BNPQY
const bnp = data.marketData.find(m => m.symbol === 'BNPQY');
if (bnp) {
console.log(`BNPQY - Close: ${bnp.close}, Volume: ${bnp.volume}`);
}
}
};
// Start Simulation
fetch(`${BASE_URL}/api/simulation/start`, { method: "POST", headers: HEADERS });
// Place Order
const order = { symbol: "BNPQY", action: "BUY", quantity: 10 };
fetch(`${BASE_URL}/api/order`, {
method: "POST",
headers: HEADERS,
body: JSON.stringify(order)
});
HttpClient client = HttpClient.newHttpClient();
String baseUrl = "http://localhost:7070";
String wsUrl = "ws://localhost:7070/ws";
String teamCode = "TEST";
// Connect to WebSocket
WebSocket ws = client.newWebSocketBuilder()
.buildAsync(URI.create(wsUrl + "?teamCode=" + teamCode), new WebSocket.Listener() {
@Override
public CompletionStage> onText(WebSocket webSocket, CharSequence data, boolean last) {
System.out.println("Received JSON: " + data);
// Parse JSON to get portfolio:
// double cash = jsonObject.get("portfolio").get("cash").asDouble();
// double valuation = jsonObject.get("valuation").asDouble();
// Parse market data for BNPQY:
// JsonNode marketData = jsonObject.get("marketData");
// for (JsonNode item : marketData) {
// if ("BNPQY".equals(item.get("symbol").asText())) {
// double close = item.get("close").asDouble();
// long volume = item.get("volume").asLong();
// System.out.println("BNPQY: " + close + " / " + volume);
// }
// }
return WebSocket.Listener.super.onText(webSocket, data, last);
}
}).join();
// Start Simulation
HttpRequest startReq = HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/api/simulation/start"))
.header("X-Team-Code", teamCode)
.POST(HttpRequest.BodyPublishers.noBody())
.build();
client.send(startReq, HttpResponse.BodyHandlers.ofString());
// Place Order
String json = "{\"symbol\":\"BNPQY\",\"action\":\"BUY\",\"quantity\":10}";
HttpRequest orderReq = HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/api/order"))
.header("X-Team-Code", teamCode)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
client.send(orderReq, HttpResponse.BodyHandlers.ofString());
Controls
Place Order
Portfolio Status
Date: -
Cash: -
Valuation: -