qate
A quantitative trading library, built to be backtested. It provides the event loop, order lifecycle, strategy base class, charts and indicators, inventory and PnL tracking, and a simulator that fills orders against recorded order books.
It reaches no exchange. That is a property of the install, not a promise in a README: there is no HTTP client and no WebSocket client anywhere in its dependency tree, no venue endpoint in its source, and no request-signing or account code. A venue arrives only as a separate package that registers an adapter, and without one there is no code here that could connect anywhere.
It also does not know where market data lives, or what format it is in. That
belongs to whoever owns the data. qate defines what an order book and a trade
are; something else reads them and hands them over.
pip install kamakuraquantlab-qate
For Kamakura Quant Lab data: Komachi downloads it, Hase derives features from it, and Enoshima backtests over it. This is the library Enoshima sits on.
It also has no notion of a deployment — no run directory, no host, no credential. That is qate-env, which both Enoshima and a live runner use to turn a directory of JSON into a run.
Layout
| Package | Holds |
|---|---|
qate.core |
Event loop, models, order lifecycle, and the interfaces a venue implements |
qate.trading |
Strategy base class and its config contract, gateways (live and simulated), the replay queue, bars and charts, indicators, inventory, PnL, the metric log, and the Runtime a live process runs in |
qate.strategy |
Two worked strategies, shipped to be read |
qate.exchange |
The adapter contract and registry. No venue lives here |
qate.util |
Date ranges, counters, encoding, replay-aware logging |
Run directories, credentials and the loader that reads them are not here; they are
qate-env. Nothing in this package names a path, a host or a key.
Two worked strategies
An abstract base class is a poor teacher, so qate ships two complete strategies:
| Strategy | Is | Shows |
|---|---|---|
qate.strategy.corvus |
Read a list of orders, place them, exit | The order lifecycle alone — place, reprice, cancel, fill, stop |
qate.strategy.pisces |
Cross-exchange arbitrage, maker one side and taker the other | A real idea, plus what startup, inventory and shutdown actually cost |
Read corvus first: it has no signal, no inventory and no schedule, so what is left is the machinery every strategy needs and the part that is fiddly.
pisces is the same framework carrying a real trading idea, and its largest file does no trading at all — it works out whether the strategy can start, because exchanges have no sub-accounts and a strategy cannot assume the balance it left behind. That ratio is the lesson, and it is what example strategies usually omit.
Neither is tuned and neither is a recommendation. Backtesting them needs nothing
but qate; trading them live needs an exchange adapter, which is a separate
install by design.
See knowledge/05_corvus.md and
knowledge/04_pisces.md, and
knowledge/03_writing_strategy.md for the
Variant contract to write your own.
Market data comes from outside
There is no reader here, deliberately. Reading recorded data means knowing a
storage layout, and a layout has an owner — for Kamakura Quant Lab data that is
komachi, which writes it. A trading library that also knew the layout would be a
second implementation of one question, and the day the two disagree is the day a
backtest silently skips a date the downloader thinks it has.
So a replayer hands qate events. Enoshima is the one that joins the two: it
asks komachi where the files are, reads them, and produces
qate.core.model.OrderBook and Trade. Anything that can produce those objects
works the same way.
qate.util.dt_range.DtRange is the shared vocabulary for when: it yields the ISO
date partition keys the bronze layer is laid out by, so a range maps onto files
with no conversion.
Running a backtest
A replay is single-threaded on purpose: the events already exist, in order, and
two runs of the same data must give the same result. One queue in place of the
live ones collapses the threading into a single loop, so the same Trader,
Strategy and gateway code runs unchanged:
from qate.trading.gateways import SimulatorGateway
from qate.trading.replay import ReplayQueue
from qate.trading.trader import Trader
# events: an iterable of (EventType, OrderBook | Trade), in timestamp order.
# Where they come from is not qate's business — see above.
gateway = SimulatorGateway(ExchangeName.GMO, slippage_rate=0.0) # fills in place
trader = Trader(strategy, ReplayQueue(events)) # market data + own events
trader.add_gateway(gateway)
trader.register(EventType.MARKET_ORDER_BOOK, gateway.handle_order_book)
trader.run() # returns when the data ends
Two behaviours are worth knowing before reading a result:
- An order fills on the book after the one it was created on. The simulator matches against the next snapshot, never the one the strategy was looking at when it decided. That is the latency model, and it is why a strategy cannot trade on information it could not have had.
Traderruns a warmup pass first, draining events intoStrategy.warmup_*until the strategy reportsis_ready. Indicators get their history before anything trades, and the warmup events are not traded on.
tests/test_backtest_end_to_end.py is this whole path in one file, from parquet
on disk to results on disk, and is the shortest complete example.
Reporting a run as it happens
A Reporter receives every result of a live run. The application decides whether
that destination is a local file, a chat service, or something else.
from qate.trading.reporter import Reporter
from qate.trading.runtime import Runtime
class Printer(Reporter):
def report_order(self, order_response):
print(order_response.summary)
runtime = Runtime(strategy)
runtime.add_reporter(Printer())
The interface is start, stop, report_order, report_metrics, report_pnl,
report_exception, and report_message. Every method is a no-op by default, so
implement only what the destination needs. Several reporters can be added and each
sees everything. A reporter that raises is logged and ignored: a run does not
depend on anyone being told.
No implementation ships here — a destination is a dependency, and a chat client in this package would be one nobody backtesting asked for. A live runner adds its own.
qate has no storage implementation or serialization dependency. Applications that need durable results add a reporter supplied by their storage package.
Supplying an exchange
Live trading needs an adapter package. It declares an entry point and registers
one ExchangeAdapter per venue:
[project.entry-points."qate.exchanges"]
my_venues = "my_venues:register"
from qate.core.model import ExchangeName
from qate.exchange import ExchangeAdapter, register
def register_all():
register(ExchangeAdapter(
exchange_name=ExchangeName.GMO,
create_api=GMOApi,
create_gateway=GMOGateway,
create_public_connection=GMOPublicConn,
create_private_connection=GMOPrivateConn,
))
Every hook is optional, and a venue is resolved lazily on first use. Asking for
one that is not installed raises UnknownExchange naming what is; asking an
adapter for something it does not provide raises
UnsupportedExchangeCapability naming the hook. Set QATE_EXCHANGE_PLUGINS to
load an adapter from a checkout that is not installed.
What a fill costs
An adapter carries what its venues charge, alongside the hooks — a fee schedule is
venue knowledge in exactly the way an endpoint is, and qate ships the shape of a rate
and no rate:
register(ExchangeAdapter(
exchange_name=ExchangeName.GMO,
create_api=GMOApi,
...
fee_rates={Symbol.BTC_SPOT: FeeSchedule(maker=-0.0001, taker=0.0005)},
))
Fractions of notional, and a negative maker rate is a rebate — the fee comes back
negative and a PnlUpdate that subtracts it is correct.
factory.get_fee_rate(market) is how a run asks, and it is the one call in factory
that builds nothing: it reads a number off an adapter, so a replay may use it. A
PnlTracker resolves a rate per market, once, at setup:
tracker = PnlTracker()
tracker.register_fee(maker_market) # bitbank, say
tracker.register_fee(taker_market) # and GMO
One tracker covers several markets deliberately — pisces shares one between a maker
venue and a taker venue, which is what makes its round-trip PnL a round trip — so the
rate is per market and a fill is costed with the rate of the market it happened on. An
Inventory registers its own market, so a strategy built the usual way needs none of
this.
A market no rate was found for is costed at zero, with one warning: a venue whose fees a run does not know is a configuration gap, not a reason to kill a live strategy mid-position. It does mean a run with no adapter installed reports no fees at all, which flatters any strategy whose edge is thinner than its costs. Rates were hardcoded here once, and the price of their being right is that the package that speaks to a venue is the one that has to say.
Settings
There are none. qate reads no configuration file, consults no environment
variable, and holds no default path — a Strategy is handed its config object and
its params dict by whatever constructed it, and that is the whole of it.
Run directories, credential files and the loader that turns them into those objects are qate-env. A backtest therefore asks for no credential because there is nothing here that could ask: an unauthenticated fallback is not a thing this package can express.
There is no market-data setting either. qate does not read market data, so it has
no opinion about where it is.
Documentation
| Document | Read it when |
|---|---|
| knowledge/01_philosophy.md | Deciding whether to add a check, a test, or a comment |
| knowledge/03_writing_strategy.md | Writing a strategy: the Variant contract, config vs params |
| knowledge/04_pisces.md | Cross-exchange arbitrage: startup, rebalance, shutdown |
| knowledge/05_corvus.md | Single-shot order execution — the order lifecycle alone |
Environments — the directory, the lock, config discovery — are
qate-env's knowledge/01_env.md.
They were knowledge/02_env.md here, which is why the numbering skips.
Development
pip install -e '.[dev]'
pytest
Licence
Apache 2.0. See LICENSE.md.
Metadata
Release files for kamakuraquantlab-qate 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kamakuraquantlab_qate-0.3.0.tar.gz | 76.0 kB | Without provenance | Details for kamakuraquantlab_qate-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kamakuraquantlab_qate-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for kamakuraquantlab_qate-0.3.0-py3-none-any.whl |
Total release size: 152.9 kB
Release files / kamakuraquantlab_qate-0.3.0.tar.gz
| Download URL | kamakuraquantlab_qate-0.3.0.tar.gz |
|---|---|
| Size | 76.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52dab86b55cc1ee7ad33e334034d7db0f4317ddf527ef3207d2dfb2c0415cd41
|
|
BLAKE2b-256 checksum How to use checksums |
3f28cc5e5597bb5bd4b0e1b578980f97bb416f6a99599617334c6de085b2f8e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / kamakuraquantlab_qate-0.3.0-py3-none-any.whl
| Download URL | kamakuraquantlab_qate-0.3.0-py3-none-any.whl |
|---|---|
| Size | 77.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
080b35d382998e1c15f907d69b2abeea8cd27089f1cd9703dab86c95de5fc5c3
|
|
BLAKE2b-256 checksum How to use checksums |
48f967d7c6f13cbfedf1859d91df9b6d2763ca611cbf3affb7206e4fc34a8fb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for kamakuraquantlab-qate 0.3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.