Skip to content
All library documents

Using Script Engines for Multi-Instrument Trading and Data Queries

Article Quant course library

Summary

This guide explains how a Python script engine can connect to trading gateways, subscribe to market data, query account and instrument records, and submit or cancel orders. It describes both an interactive notebook workflow and a continuously running script workflow, where a loop can monitor the engine’s active state and periodically retrieve ticks. The examples show how the engine can work across multiple interfaces and instruments, supporting tasks such as portfolio hedging, cross-market arbitrage, and automated stock screening.

The reference also outlines single-item, multi-item, and full-account queries, including historical bars when a data client is initialized. Returned records can optionally be converted to DataFrames for analysis. Order types and email notifications are covered as operational features. This is an API usage guide rather than a trading strategy or performance study: it provides no backtest or evidence of profitability. Gateway settings and supported order types vary by interface, and the examples do not address execution risk, credential security, or production monitoring.

Key ideas

  • A script engine can connect to multiple trading gateways and subscribe to multiple instruments.
  • Interactive notebooks and persistent scripts offer different ways to run trading logic.
  • The API provides methods to query ticks, bars, contracts, orders, trades, positions, and accounts.
  • Orders can be submitted using supported order types and later canceled by their local identifiers.
  • Gateway capabilities and order support depend on the connected interface.

Tags

From a private course collection; the original is not published.