ARBITRAGE
Buys energy when prices are low and sells when they are high, using day-ahead spot prices.
| Mode string | ARBITRAGE (EMS_OP_ARBITRAGE) |
| Dispatcher | ems_main.py → control_logic_updated.control_step_arbitrage |
| Config block | functions.Arbitrage |
| Queue source tag | control_logic (the writer's default) |
| Status | Implemented |
This is the currently selected mode (
ems_operation_mode: "ARBITRAGE") but it isenabled: false.
Purpose
Fetches today's and tomorrow's 15-minute spot prices, decides a direction (charge/sell/idle), and writes per-PCS setpoints. Between ticks it deliberately holds the last setpoints rather than recomputing, to avoid churn on a 2 Hz loop.
How it decides
- Tick gate.
_arb_tick_gate(ar)allows a recompute only everytick.interval_seconds(300 s). If the gate is closed the function returns early and holds — withtick.run_on_startandtick.zero_power_on_skipinfluencing the start-up case. - Fetch prices. Downloads the provider feed described by
price_source.url_template, parsingformat: json_arrayand the field mapping inprice_source.fields.resolution_minutes: 15andslot_mode: current_onlyselect the active slot. Failure is non-fatal — the last setpoints are held. - Decide direction, in priority order:
- Tomorrow plan (
strategy.tomorrow_plan.enabled) — rank tomorrow's slots and charge in thecharge_cheapest_slotscheapest, discharge in thedischarge_most_expensive_slotsmost expensive, atcharge_power_kw/discharge_power_kw, tie-broken bytie_breaker(earlier_first). Uses_pick_cheapest_slots/_pick_most_expensive_slots. - Threshold engine —
buy_threshold/sell_thresholdwithmin_spreadguarding the round trip. prefer_next_slotprefers the upcoming slot over the current one.- Apply SOC gating and per-PCS caps, then write.
Configuration
functions.Arbitrage
| Key | Live value | Meaning |
|---|---|---|
enabled |
false |
Master switch. |
timezone |
Europe/Stockholm |
Local time for slot matching. |
tick.interval_seconds |
300 |
Minimum seconds between recomputes. |
tick.run_on_start |
true |
Compute immediately on start. |
tick.skip_cycles_log |
true |
Log skipped cycles. |
tick.zero_power_on_skip |
true |
Force 0 kW on skipped cycles. |
price_zone |
SE4 |
Bidding zone. |
price_currency |
SEK |
Currency for thresholds. |
price_source.provider |
elprisetjustnu |
Provider name. |
price_source.url_template |
https.gess.se |
Fetch URL. |
price_source.timeout_ms |
4000 |
HTTP timeout. |
price_source.format |
json_array |
Response parsing mode. |
price_source.fields |
time_start, time_end, price_sek, price_eur |
Field mapping. |
price_source.resolution_minutes |
15 |
Price slot length. |
price_source.slot_mode |
current_only |
Slot selection mode. |
strategy.prefer_next_slot |
true |
Prefer the upcoming slot. |
strategy.min_spread |
0 |
Minimum spread required to trade. |
strategy.buy_threshold |
0.1 |
Buy below this price. |
strategy.sell_threshold |
0.12 |
Sell above this price. |
strategy.buy_power_kw |
20 |
Charge power. |
strategy.sell_power_kw |
20 |
Discharge power. |
strategy.tomorrow_plan |
enabled: true |
charge_cheapest_slots: 8, discharge_most_expensive_slots: 8, charge_power_kw: 20, discharge_power_kw: 20, tie_breaker: earlier_first. |
optional.hysteresis |
0 |
Price hysteresis. |
optional.hysteresis_kw |
0 |
Power hysteresis. |
Safety
- Returns when
is_external_control_active(), whenenabledis false, or when the tick gate is closed. - A failed price fetch holds the previous setpoints — it never trades on stale or empty data.
- SOC gating is direction-aware: charge against
max_soc_pct, discharge againstmin_soc_pct. - Final per-PCS clamp in
_pcs_connect_and_set_power_kw.
Check:
price_source.url_templateis set tohttps.gess.se, which does not look like a real elprisetjustnu endpoint. Verify this before enabling.
Outputs
_pcs_connect_and_set_power_kw(cfg, pcs_id, ±kw) → queue action set_power_kw, source control_logic.