live-eth-nextgen-micro-deployment.md 4.1 KB

ETH nextgen micro live observer deployment

Scope

This deployment is read-only. It continuously refreshes local OKX candles, rebuilds the ETH nextgen+micro signal intent, records account/position snapshots when credentials are present, writes heartbeat files, and submits no orders.

Order execution remains blocked until the persistent virtual state and target-position reconciliation are implemented.

Files

  • scripts/run_eth_nextgen_micro_observer.py
  • deploy/eth-nextgen-micro-observer.service
  • deploy/install_eth_nextgen_micro_observer.sh

Server

Target host: 66.253.42.170

Install path: /opt/okx-codex-trader

Environment file: /etc/okx-codex-trader/okx.env

Service: eth-nextgen-micro-observer.service

Deploy

rsync -a --delete --exclude .git --exclude .venv --exclude .pytest_cache --exclude var ./ ubuntu@66.253.42.170:/tmp/okx-codex-trader/
ssh ubuntu@66.253.42.170 'cd /tmp/okx-codex-trader && bash deploy/install_eth_nextgen_micro_observer.sh'

Then edit credentials on the server:

sudo nano /etc/okx-codex-trader/okx.env
sudo systemctl restart eth-nextgen-micro-observer.service

Monitor

systemctl status eth-nextgen-micro-observer.service --no-pager
journalctl -u eth-nextgen-micro-observer.service -f
cat /opt/okx-codex-trader/var/eth-nextgen-micro/heartbeat.json
tail -f /opt/okx-codex-trader/var/eth-nextgen-micro/observer-events.jsonl

Live execution gate

Do not add live order submission to this service until all of these are true:

  • Persistent virtual nextgen and micro state is maintained.
  • Target position is expressed as one net ETH position with units 0, 0.5, or 1.0.
  • Close/reduce-only order support is implemented and tested.
  • The daemon is idempotent by completed candle timestamp and client order id.
  • A hard max_margin_usdt cap is enforced.

Execution design

The live executor should be a separate service from this observer. The observer answers only: latest completed candles, selected engine, intended signal, and current account snapshot.

The executor should process only completed 15m candles. For each candle it should:

  1. Rebuild the strategy state from persisted last state plus the new candle.
  2. Convert virtual legs to one target ETH position: flat, long 0.5, long 1.0, short 0.5, or short 1.0.
  3. Read current OKX ETH swap position.
  4. Submit only the delta needed to reach the target position.
  5. Persist candle timestamp, target position, submitted client order id, fills, fee, and resulting position.

The first live version should use a hard small margin cap and market/reduce-only orders only. Price-distributed TWAP entry can be added after target reconciliation and fill logging are proven live.

Current implementation boundary

The strategy logic is moving out of ad hoc scripts into package modules:

  • okx_codex_trader.eth_nextgen_micro builds the ETH nextgen+micro signal payload.
  • okx_codex_trader.live_execution maintains runtime strategy state, converts nextgen virtual legs into one net target position, normalizes OKX positions into strategy units, and builds a pure delta plan.
  • okx_codex_trader.live_execution.render_market_order_bodies converts a tested delta plan into OKX market order bodies with deterministic client order ids and a hard new-margin cap.
  • okx_codex_trader.okx_client.submit_market_order_body can submit a prebuilt market order body, but no deployed service or CLI calls it yet.
  • scripts/run_eth_nextgen_micro_observer.py remains read-only. It writes runtime state and target-position diagnostics, but it still submits no orders.
  • scripts/run_eth_nextgen_micro_executor.py builds a dry-run execution snapshot. It reads the strategy payload and OKX account state, renders order bodies only when current and target positions are known, and always reports orders_submitted: 0.

Live order submission is still intentionally unreachable from the daemon. The next required boundary is an executor command or service that calls the submit method, records client order ids, and verifies fills.

Dry-run executor example:

python scripts/run_eth_nextgen_micro_executor.py --margin-per-unit-usdt 5 --max-new-margin-usdt 5