trading-engine-interface
The strategy contract of the Martian Mobile trading engine. A strategy written against this package is written against the contract the engine itself runs: same StrategyProtocol, same input and output models, same venue and symbol enums.
What is in it:
| Module | What it is |
|---|---|
trading_engine_interface.runtime |
StrategyProtocol (the type the engine checks every strategy against), register_strategy, the strategy registry |
trading_engine_interface.trading_engine.models |
StrategyInput (order books, klines, public trades, positions, open orders, balances), StrategyOutput (orders to create, cancel, replace), configs, positions, fills |
trading_engine_interface.domain |
The maker-fill kernel (trade-through, OPTIMISTIC / CONSERVATIVE band), fill simulator, position math |
trading_engine_interface.common |
Enums (VenueName, Symbol, Asset, TimeInterval), errors, base model |
The fill kernel is mechanism only. Calibrated fill curves are not part of this package.
Install
pip install trading-engine-interface
Python 3.12 or later.
Quickstart
A strategy is any class that structurally satisfies StrategyProtocol: a VERSION, a fees attribute, and decide, close_position and flush_output. Register it with @register_strategy(config=...) so the engine can find the class and its config.
The smallest complete one is installed with the package, as trading_engine_interface.examples.touch_bid_strategy. It rests one limit buy at the best bid on every venue its config allows:
class TouchBidConfig(BaseStrategyConfig):
class_type: str = "TouchBidStrategy"
position: PositionParams = PositionParams()
quantity: Decimal = Decimal("0.001")
@register_strategy(config=TouchBidConfig)
class TouchBidStrategy:
VERSION: int = 1
def decide(self, input_data: StrategyInput, predictions: Optional[StrategyPredictions] = None) -> StrategyOutput:
if input_data.open_orders:
return self.flush_output(skip_reason=SkipReason.OPEN_ORDERS)
for symbol, venues in self.config.symbol_to_venues.items():
for venue in venues:
book = input_data.market_data.order_books.get(symbol, {}).get(venue)
bid = book.best_bid_price if book else None
if bid is not None:
self._output.create_orders.append(
CreateOrderRequest(venue=venue, symbol=symbol, order_type=OrderType.LIMIT,
side=Side.BUY, quantity=self.config.quantity, price=bid)
)
return self.flush_output(skip_reason=None if self._output.create_orders else SkipReason.NO_DATA)
...
Run it once against a hand-built order book:
python -m trading_engine_interface.examples.touch_bid_strategy
Type-check it the way the engine does. mypy --strict fails if the class drifts from StrategyProtocol:
mypy --strict -m trading_engine_interface.examples.touch_bid_strategy
Backtest it
A backtest runner builds your config itself, from the venues, symbols and risk limits you pass on the command line. Two things in the config class make that possible, and the example has both:
class_typedefaults to the strategy's class name. That is how a runner finds the config that belongs to a strategy.positionhas a default.BaseStrategyConfigrequires it, and a runner does not supply one.
The runner replays public market data through the same decide the engine calls, on simulated time, and fills orders with the kernel in trading_engine_interface.domain. The runner is not part of this package. It is coming as bt2live run in backtest2live; until that release, this package gives you the contract and the example, not a backtest command.
Rules a strategy must follow
- A strategy is constructed once with its config. Each
decidecall receives everything it may use: market data, its position, its open orders and its balances. - No network calls and no files. A strategy that needs data it is not given cannot run on a hosted engine.
- Keep no state of your own between calls. Decide from the
StrategyInputyou are given. decideis synchronous. Read time throughtrading_engine_interface.now(), never the system clock: the backtest replays on simulated time by patching it. Everything else a decision needs arrives inStrategyInputandStrategyPredictions.- Set
StrategyOutput.skip_reasonon every path that returns no orders. A quiet strategy without a reason reads as uninstrumented, not as "found nothing". - Bump
VERSIONwhen the decision logic changes.
Versioning
The version number is the version of the contract the engine runs. Before 1.0 the contract can change between releases, so pin the exact version you build against.
Licence
MIT. The licence text is installed with the package.
Metadata
Release files for trading-engine-interface 0.56.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trading_engine_interface-0.56.25-py3-none-any.whl | Python 3 | none | any | Details for trading_engine_interface-0.56.25-py3-none-any.whl |
Release files / trading_engine_interface-0.56.25-py3-none-any.whl
| Download URL | trading_engine_interface-0.56.25-py3-none-any.whl |
|---|---|
| Size | 82.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d14514c3c4fc0bf1a579f45b1cc42f61d1c46db0bfc073b9db14ec537518bf4c
|
|
BLAKE2b-256 checksum How to use checksums |
bf498007d23a0feb7cd1179bf13c69320a2c7ba3632bdf42c19c4b2d45c8161b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for trading-engine-interface 0.56.25
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for trading_engine_interface-0.56.25-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.