add MockExchange for offline development and testing#107
add MockExchange for offline development and testing#107mooncitydev wants to merge 3 commits intopmxt-dev:mainfrom
Conversation
implements issue pmxt-dev#19 - a fully offline mock exchange that generates realistic prediction market data without any network requests. uses @faker-js/faker with deterministic seeding so every market id always produces the same prices, titles and order books across runs. implements fetchMarkets, fetchEvents, fetchOrderBook, fetchOHLCV, fetchTrades, fetchBalance, fetchPositions, createOrder, cancelOrder, fetchOrder, fetchOpenOrders, fetchMyTrades, fetchClosedOrders, fetchAllOrders, buildOrder and submitOrder. in-memory order store and position tracking update on every createOrder so balance/positions reflect trades made during the session. configurable marketCount, starting balance and order latency via MockExchangeOptions constructor argument. exports pmxt.Mock alongside all other exchanges in index.ts. adds reset() helper to wipe session state between test cases. Made-with: Cursor
Made-with: Cursor
|
Thanks for this — the concept is solid and it covers the issue requirements well. A few things to address before this is ready to merge:
This is the main concern. faker is ~3.5MB and it would ship to every
Option 1 is probably the cleanest here since the data generation doesn't need faker's full feature set. No tests 610 lines of order lifecycle, balance accounting, and position tracking need test coverage. The position math (entry price averaging, PnL) and balance deductions are especially important to verify. Orders always fill immediately
Mutation Position tracking and Minor
The foundation here is good — deterministic seeding, proper BaseExchange contract, |
- Replace @faker-js/faker with local SeededRng (mulberry32 + string hash) - market orders price from same mid as fetchOrderBook (first float) - limitOrderMode: 'resting' for open/cancel/fill; fillOrder for partial/complete - Buy resting uses locked USDC; immutable position updates - Add core/test/unit/mockExchange.core.test.ts Made-with: Cursor
closes #19
what this does
adds
MockExchange— a fully offline, zero-network exchange implementation built on top of@faker-js/faker. it lets developers write and test application code against pmxt without real API keys or an internet connection, which is especially useful in CI/CD pipelines and during rapid prototyping.how it works
MockExchangeextendsPredictionMarketExchangeand overrides every relevant method with local in-memory implementations. faker is seeded deterministically from each market/outcome id, so the same call always returns the same data across runs — you can write stable assertions against it.features
fetchMarkets/fetchEvents— generates realistic binary and multi-outcome markets grouped into events, with prices, volumes, slugs, tags, and categoriesfetchOrderBook— produces a realistic CLOB-style bid/ask ladder centred around the mid pricefetchOHLCV— generates candlestick data for any resolution (1m through 1d) and any date rangefetchTrades— returns a list of fake historical trades for an outcomefetchBalance— returns a configurable starting USDC balancecreateOrder— records the order in-memory, updates balance and positions, simulates a configurable latency (default 100ms), always fillscancelOrder,fetchOrder,fetchOpenOrders,fetchClosedOrders,fetchAllOrders,fetchMyTradesfetchPositions— returns live position state derived from all trades placed so farbuildOrder/submitOrder— supportedreset()— clears all orders, positions and trades between test casesusage
made by mooncitydev