Conversation
…s with leverage (long-only) Phase 1 — exchanges - ExchangeSpec registry is the single source of truth (name, passphrase, ccxt config, keys URL, sandbox/candle notes); SUPPORTED_EXCHANGES derived - Added Bybit, Gate, Bitget, MEXC, HTX, BingX (13 exchanges total) - Frontend reads GET /api/keys/exchanges via api/exchanges.js everywhere (Settings, DataManager, builder); no hardcoded lists Phase 2 — market types / perpetual swaps - ExchangeSpec.markets with MarketCaps (max leverage, ccxt id, leverage in order params); build_exchange pins options.defaultType, auth cache keyed on market type, get_exchange_symbols(exchange, market_type) - engine/symbols.py: BASE/QUOTE:SETTLE helpers, market_type_for, leverage_for - Additive migrations: exchange_keys.market_type, positions.market_type/ leverage/contracts, orders.market_type/reduce_only - Backtest/forward: entry locks notional/leverage + fees, PnL on full notional, liquidation at entry*(1-(1-0.005)/lev), summary adds market_type/leverage/liquidations/funding:"ignored" - Live: create_order with reduceOnly/contracts on derivatives (spot path unchanged), ensure_leverage at startup and before the first buy, fetch_positions reconciliation for swaps, force-close reduce-only - Validator: key/bot market-type match, :SETTLE form rules, leverage caps (warn above 3x), margin mode; keys router enforces market type per key - Frontend: Market/Leverage/Margin controls in Exchange Routing, whitelist form hints, go-live checklist line, Perps chips on card/analytics/home, DataManager market select - Tests: test_exchange_registry.py, test_swap.py (13); goldens unchanged Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- engine/pnl.py: side-aware PnL, liquidation, order sides, short/cover legs - exits: mirrored short rules (SL above entry on high, TP below on low, trailing on lowest); long path untouched, goldens byte-identical - backtest/forward/live: SHORT/COVER actions, long-short conflict gate, short liquidation on the high, reduce-only cover orders, side-aware reconciliation and cooldown - validator: shorts refused on spot, short leg validated like entry - API: positions expose market_type/leverage, orders reduce_only, stats bySide - builder: SHORT/COVER action blocks, rebuild + serialize short legs only when present; chart markers, analytics side split, home short exposure - tests/test_shorts.py (28), docs README + STRATEGY_CONTEXT
Audit (coder/trader/UI) follow-up, all in one: - engine/contracts.py ContractSpec (spot|linear|inverse) + engine/capital.py CapitalPools per cash currency; one cash currency per bot (validator) - inverse (coin-margined) swaps end to end; registry kinds, binancecoinm - positions.cash_currency/contract_kind/contract_size, orders.fee_currency/ fee_cash; /stats by_currency, /symbols markets, keys valuation_currency - safety: side=None close, int coercion + per-bot tick isolation, live fee clamp, liquidation in forward + live detection, reconciliation failure refuses live, manual close under bot lock, leverage cache invalidation, bot_log_buffer push after commit (30s stall) - honesty: profit_pct on locked capital everywhere, SL/TP before liquidation, 1x short liquidation, forward DD group, unrealized at candle_ts, candle-based cooldown, reduce_only-aware dedup, forward close frictions, max_order_value in backtest (fingerprint) - exits.py single direction-parameterised body - UI: Modal portal above builder (Close/Esc fix), builder name/dirty fixes, per-exchange live prices, side-aware close + Side columns, per-mode analytics tiles, fmtMoney per currency (no bare $), linear/inverse chips, chart/DataManager/Home/CSV fixes - tests: 227 (parity modes, hypothesis properties, contracts, swap golden) - docs: README, STRATEGY_CONTEXT, BETA
…_examples currency-aware
… backtest and forward test - funding_rates/leverage_tiers tables, engine/funding.py + engine/tiers.py - Position.funding_paid/funding_until, forward_pool includes open funding - cross margin: account-level liquidation drains the pool (backtest + forward) - Supertrend long/short perp example, verify_examples currency-aware - swap goldens regenerated summary-only (orders unchanged)
…uting block width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release v2.3.0
Three phases in one release: more exchanges, perpetual swaps with leverage, and shorts — plus the simulation realism work that makes those bots comparable across backtest, forward test and live. Spot bots are unaffected: every golden backtest is byte-identical to v2.2.1.
Exchanges
ExchangeSpecregistry is the single source of truth (name, passphrase, ccxt config, market types, contract kinds); adding an exchange is one entry.GET /api/keys/exchanges; no hardcoded lists.Perpetual swaps & leverage
spot/swap); bots getmarket_type,leverage,margin_mode, validated against the key and the exchange's capabilities.ContractSpec(notional, margin, fees, PnL, liquidation price);Position.amountis base units on spot/linear and contracts on inverse.ensure_leverageat startup, position reconciliation throughfetch_positions, rejected closes probed and booked as liquidations.krakenfutures, KuCoin →kucoinfutures, Binance inverse →binancecoinm; MEXC swaps excluded.Shorts
Open short/Close shortaction blocks;short_node/cover_nodemirror the long leg.stats.bySide, "Buy to cover" force close.Per-currency capital
CapitalPoolskeyed by currency;cash_currencyon positions and orders; one cash currency per whitelist (validator)./statsreportsby_currencyand never sums across currencies; the UI renders money only throughfmtMoney.profit_pcteverywhere = realized PnL / locked capital (margin + entry fee).Simulation realism
funding_paidon positions; summaryfunding,funding_paid,funding_events,funding_by_symbol).mmr_source).Examples & tooling
Supertrend_LongShort_Perp_1dexample (1× BTC+ETH USDT perps), import test,verify_examples.pycurrency-aware.Fixes
dev).Migrations (additive, idempotent)
positions:market_type,leverage,contracts,cash_currency,contract_kind,contract_size,funding_paid,funding_until(+ currency backfill for existing rows).orders:market_type,reduce_only,fee_currency,fee_cash.exchange_keys:market_type.funding_rates,leverage_tiers.Tests
test_contracts.py,test_parity_modes.py,test_properties.py,test_swap.py,test_shorts.py,test_funding_tiers_cross.py,test_exchange_registry.py; two swap goldens added, all spot goldens unchanged.