Economy API
The economy API exists so that a third-party application can drive a dynamic economy: read prices, stock and the trade log, decide new multipliers and stock levels from supply and demand, and push them back. Everything is JSON over HTTP, on api.listen (default port 8080).
Model
Each market entry is a good at a base, both identified by their case-insensitive nicknames from the game data (for example Br01_01_base and commodity_gold).
- price =
base_price(fromgoods.ini) ×multiplier(frommarket_*.ini, or your override). - stock defaults to the entry’s
max_stockand is always clamped to0…max_stock. A player buying lowers stock; selling raises it. - Overrides (multiplier and stock) are saved to
<storage.dir>/economy-overrides.jsonafter each successful write and restored at start-up.
The meaning of the MarketGood fields after the good name (rank, reputation, min and max stock, buy-only, multiplier) is inferred from the data files and community documentation, not yet confirmed against the original server.
Authentication
Reads are open. PUT POST DELETE need Authorization: Bearer <api.token>. Without a configured token, writes return 403; with a wrong or missing token, 401.
Endpoints
| Request | Purpose |
|---|---|
GET /economy/overview | Counts of bases and market entries, and the latest trade seq. |
GET /economy/bases | All base nicknames that have a market. |
GET /economy/bases/{base}/prices | Every good at a base: price, multiplier, stock, min/max stock, buy-only, overridden. |
GET /economy/bases/{base}/prices/{good} | One entry. |
PUT /economy/bases/{base}/prices/{good} | Body {"multiplier": 1.2, "stock": 300}; either field may be omitted. |
DELETE /economy/bases/{base}/prices/{good} | Clear both overrides, back to the data-file values. |
POST /economy/batch | Apply many updates atomically (max 5,000). If any entry is invalid, none are applied. |
POST /economy/trades | Record a trade: {"base","good","side":"buy"|"sell","quantity"}. Moves stock and logs it. The game will do this itself once trading exists; until then it lets you inject traffic. |
GET /economy/trades?since=N&limit=M | Trades with seq greater than N, oldest first (default limit 100, max 1000). The reply carries last_seq: use it as the next cursor. |
GET /metrics | Prometheus text format. |
GET / | The built-in dashboard. |
Examples
TOKEN=change-me; API=http://127.0.0.1:8080
# read one price
curl $API/economy/bases/Br01_01_base/prices/commodity_gold
# {"base":"br01_01_base","good":"commodity_gold","base_price":425.0,"multiplier":1.08,
# "price":459.00003,"stock":500,"min_stock":150,"max_stock":500,"buy_only":false,"overridden":false}
# raise a price and set stock
curl -X PUT -H "Authorization: Bearer $TOKEN" \
-d '{"multiplier": 1.5, "stock": 120}' \
$API/economy/bases/Br01_01_base/prices/commodity_gold
# atomic batch
curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"updates":[
{"base":"Br01_01_base","good":"commodity_gold","multiplier":1.4},
{"base":"Li01_01_base","good":"commodity_water","stock":50}]}' $API/economy/batch
# follow trades
curl "$API/economy/trades?since=0&limit=50"
A dynamic-economy loop
- Poll
GET /economy/trades?since=<cursor>every few seconds (or scrape/metrics) and keep the returnedlast_seqas the cursor. - From recent buys and sells and current stock, compute a new multiplier and stock target per good: scarce goods get dearer, glutted goods cheaper.
- Send all changes in one
POST /economy/batch, so players never see a half-updated market.
The trade log keeps the last 10,000 trades in memory only; a restart resets it (overrides survive).
Metrics
/metrics exposes relioncross_price{base,good}, relioncross_stock{base,good} and relioncross_last_trade_seq. Scrape it with Prometheus and chart it in Grafana. The full retail market is about 13,000 entries, so use a scrape interval of 15 seconds or more.
Dashboard
Open / on the API port. It is built into the binary and needs no external assets. It shows the prices and stock of a chosen base, a price chart and recent trades for the selected good, and refreshes every five seconds. Enter the API token (kept for the browser session only) to edit a multiplier or stock inline.
Relioncross is unofficial and not affiliated with Microsoft or the IONCROSS community. It contains no Microsoft or IONCROSS files; bring your own copy of Freelancer.