6
REST API
samantha edited this page 2026-03-27 11:17:54 +00:00

REST API

The server listens on port 8080. All request bodies are JSON (Content-Type: application/json).


Health

GET /health

Returns server status, DB connection info, memory usage, and uptime.

curl http://localhost:8080/health
{
  "status": "ok",
  "uptime": "4m32s",
  "database": {
    "status": "ok",
    "latency": "121µs",
    "open_connections": 1,
    "in_use": 0,
    "idle": 1
  },
  "memory": {
    "alloc_mb": 2.31,
    "sys_mb": 9.44,
    "num_gc": 3
  },
  "go_version": "go1.22.0",
  "goroutines": 4
}

Returns 503 with "status": "degraded" if the database is unreachable.


Companies

POST /company/add

curl -X POST http://localhost:8080/company/add \
  -H "Content-Type: application/json" \
  -d '{"name":"Novo Nordisk","shares_outstanding":4442064180,"price":251.00,"currency_id":1}'

GET /company/list

curl http://localhost:8080/company/list

GET /company/revenue/categories

Returns all distinct revenue categories for a company.

curl "http://localhost:8080/company/revenue/categories?company_id=1"

Currencies

POST /currency/add

curl -X POST http://localhost:8080/currency/add \
  -H "Content-Type: application/json" \
  -d '{"code":"DKK","name":"Danish Krone"}'

GET /currency/list

curl http://localhost:8080/currency/list

Trades

POST /trade/add

Add a new trade. product is an integer enum and type is a boolean (see tables below).

curl -X POST http://localhost:8080/trade/add \
  -H "Content-Type: application/json" \
  -d '{
    "symbol":        "NOVO",
    "currency_code": "DKK",
    "shares":        100,
    "product":       0,
    "type":          true,
    "price":         251.00,
    "date":          "2025-03-01T00:00:00Z"
  }'

product values:

Value Meaning
0 StockTrade
1 OptionCallTrade
2 OptionPutTrade
3 CurrencyTrade
4 BondTrade

GET /trade/list

getting a list of trades in the db

curl -X POST http://localhost:8080/trade/list 
return:

[{ "Symbol":"NOVOBc", "CurrencyCode":"DKK"
"Shares":15, "Product":0, "Type":true, "Price":505, "Date":"2025-03-26T00:00:00Z" },{ "Symbol":"NOVOBc", "CurrencyCode":"DKK", "Shares":15, "Product":0, "Type":true, "Price":505, "Date":"2025-03-26T00:00:00Z" } ]

GET /positions/list

getting a list of all position

curl -X POST http://localhost:8080/positions/list 
return:

{

"Symbol":"NOVOBc", "CurrencyCode":"DKK", "Shares":15, "Product":0, "Type":true, "Price":505, "Date":"2025-03-26T00:00:00Z" }