LongTrader Strategies¶
22 built-in strategies, every one of them using only ports::{TradingGateway, MarketDataSource}. No hidden domain coupling, no "this one only runs on venue X" special cases.
Selecting one is a single line of config:
1. Grid & Market Making (7)¶
Quote both sides, capture the spread, and stop inventory from quietly turning into a directional bet.
strategy.type |
In one line |
|---|---|
simple_grid |
Evenly spaced grid inside a range. The backend is chosen by config, not by strategy type |
boll_grid |
Grid inside Bollinger Bands; no grid when bandwidth is too narrow or on a breakout |
hedge_grid |
Grid on the primary venue, market hedge on the hedge venue when fills imbalance; net exposure trends to zero |
fixed_maker |
Quotes both sides at a fixed spread around mid. No inventory protection — use with care |
cross_maker |
Hedge-venue pricing plus Avellaneda-style inventory skew; bigger position, bigger quote on the reducing side |
cross_depth_maker |
Uses the hedge venue's book mid as fair value and quotes ±spread on the primary venue |
cross_fixed_maker |
Uses the hedge venue's last price as fair value; hedges with a market order when one leg fills |
The "use with care" on fixed_maker is not a disclaimer. Unconditional two-sided quoting means that when the market runs one way, you get eaten the whole way. The hard part of market making was never quoting. It is knowing when not to quote.
2. Trend Following (2)¶
strategy.type |
In one line |
|---|---|
ema_cross |
Fast/slow EMA crossover: cross above is a market buy, below is a market sell. Edge-triggered |
supertrend |
Dual Supertrend plus DEMA confirmation; opens only when both agree, closes first on reversal |
Edge triggering matters more than it sounds. After a restart it will not replay a signal that already expired, so it does not wake up and chase a local high.
3. Portfolio & Rebalancing (3)¶
strategy.type |
In one line |
|---|---|
rebalance |
Values each symbol by targets weights; market-orders back to target when drift exceeds band_pct |
market_cap |
Market-cap weighted variant; weights maintained by hand, otherwise identical to rebalance |
dca_scheduler |
One market order every interval_secs; the first one fires immediately on startup |
is_buy = false on dca_scheduler is not a way to express a bearish view. It exists for restocking fee assets and batch distribution. Do not turn it into inverse DCA.
4. Risk & Operations (5)¶
Not glamorous. Without it, the first three categories do not survive long.
strategy.type |
In one line |
|---|---|
sentinel |
Connectivity guard: N consecutive failures trips the kill switch and cancels orders; the counter resets on recovery |
autoborrow |
Borrows when free balance drops below min_balance, repays when it exceeds repay_above |
balance_align |
Cross-venue balance alignment: transfers when deviation from the primary_share target exceeds the threshold |
convert |
Periodically converts anything above min_amount of one asset into another |
deposit_transfer |
Deposit sweep: polls completed deposits and transfers them out, deduplicated in memory, dust filtered |
Money across venues is always on the side you do not need it on. balance_align is the answer to that.
5. Signals & Analytics (5)¶
strategy.type |
In one line |
|---|---|
irr |
Reads an external signal file (last line is predicted yield); long above the entry threshold, flat below the negative one |
nav_recorder |
Periodically snapshots NAV, converting each asset to the quote asset via ticker |
premium_monitor |
Computes the premium of the same symbol across two venues and alerts above a threshold |
xfunding_lite |
Funding-rate timing: short while the rate is above enter_threshold, close when it falls back |
random_entry |
Connectivity test — reproducible random-direction market orders from a seed |
irr deserves a note. Model inference does not run inside the trading process; it only reads the last line of a signal file. If inference crashes, it does not take your position with it. That isolation is deliberate.
random_entry is explicitly not a profitable strategy. Its README says so. Use it to prove the pipeline is alive. Do not use it to trade.
Writing your own¶
A strategy is a struct that implements two traits and returns orders. No framework base class, no global singleton, no lifecycle to inherit.
If you want something to copy: simple_grid is the shortest complete example, irr shows how to consume an external signal, and cross_maker shows cross-venue hedging.
Run it on the mock venue first, then in Shadow mode against live data to see what it would actually do, and only then talk about real size. Reverse that order and the market will reverse it for you.
Next¶
- Quick Start — get a strategy running
- Architecture — where a strategy gets called in the state machine
- CLI Reference — starting, stopping and watching