Martingale42/nautilus-dev / skills/nt-adapters
nt-adapters
VerifiedUse when working with exchange or data provider adapters, HTTP/WebSocket clients, instrument providers, or venue integration in NautilusTrader.
references/examples/interactive_brokers/connect_with_dockerized_gateway.py
View on GitHub#!/usr/bin/env python3
# -------------------------------------------------------------------------------------------------
# Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
# https://nautechsystems.io
#
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------------------------------------
import os
from nautilus_trader.adapters.interactive_brokers.common import IB
from nautilus_trader.adapters.interactive_brokers.common import IBContract
from nautilus_trader.adapters.interactive_brokers.config import DockerizedIBGatewayConfig
from nautilus_trader.adapters.interactive_brokers.config import IBMarketDataTypeEnum
from nautilus_trader.adapters.interactive_brokers.config import InteractiveBrokersDataClientConfig
from nautilus_trader.adapters.interactive_brokers.config import InteractiveBrokersExecClientConfig
from nautilus_trader.adapters.interactive_brokers.config import (
InteractiveBrokersInstrumentProviderConfig,
)
from nautilus_trader.adapters.interactive_brokers.factories import (
InteractiveBrokersLiveDataClientFactory,
)
from nautilus_trader.adapters.interactive_brokers.factories import (
InteractiveBrokersLiveExecClientFactory,
)
from nautilus_trader.config import LiveDataEngineConfig
from nautilus_trader.config import LoggingConfig
from nautilus_trader.config import RoutingConfig
from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.examples.strategies.subscribe import SubscribeStrategy
from nautilus_trader.examples.strategies.subscribe import SubscribeStrategyConfig
from nautilus_trader.live.node import TradingNode
from nautilus_trader.model.identifiers import InstrumentId
# *** THIS IS A TEST STRATEGY WITH NO ALPHA ADVANTAGE WHATSOEVER. ***
# *** IT IS NOT INTENDED TO BE USED TO TRADE LIVE WITH REAL MONEY. ***
# *** THIS INTEGRATION IS STILL UNDER CONSTRUCTION. ***
# *** CONSIDER IT TO BE IN AN UNSTABLE BETA PHASE AND EXERCISE CAUTION. ***
ib_contracts = [
IBContract(
secType="STK",
symbol="SPY",
exchange="SMART",
primaryExchange="ARCA",
build_options_chain=True,
min_expiry_days=7,
max_expiry_days=14,
),
IBContract(
secType="CONTFUT",
exchange="CME",
symbol="ES",
build_futures_chain=True,
),
IBContract(secType="FUT", exchange="NYMEX", localSymbol="CLV7", build_futures_chain=False),
]
dockerized_gateway = DockerizedIBGatewayConfig(
username=os.environ["TWS_USERNAME"],
password=os.environ["TWS_PASSWORD"],
trading_mode="paper",
read_only_api=True,
)
instrument_provider = InteractiveBrokersInstrumentProviderConfig(
build_futures_chain=False,
build_options_chain=False,
min_expiry_days=10,
max_expiry_days=60,
load_ids=frozenset(
[
"EUR/USD.IDEALPRO",
"BTC/USD.PAXOS",
"SPY.ARCA",
"V.NYSE",
"YMH4.CBOT",
"CLZ7.NYMEX",
"ESZ7.CME",
],
),
load_contracts=frozenset(ib_contracts),
)
# Configure the trading node
config_node = TradingNodeConfig(
trader_id="TESTER-001",
logging=LoggingConfig(log_level="INFO"),
data_clients={
IB: InteractiveBrokersDataClientConfig(
ibg_client_id=1,
handle_revised_bars=False,
use_regular_trading_hours=True,
market_data_type=IBMarketDataTypeEnum.DELAYED_FROZEN, # If unset default is REALTIME
instrument_provider=instrument_provider,
dockerized_gateway=dockerized_gateway,
),
},
exec_clients={
IB: InteractiveBrokersExecClientConfig(
ibg_client_id=1,
account_id="DU123456", # This must match with the IB Gateway/TWS node is connecting to
dockerized_gateway=dockerized_gateway,
instrument_provider=instrument_provider,
routing=RoutingConfig(
default=True,
),
),
},
data_engine=LiveDataEngineConfig(
time_bars_timestamp_on_close=False, # Will use opening time as `ts_event` (same like IB)
validate_data_sequence=True, # Will make sure DataEngine discards any Bars received out of sequence
),
timeout_connection=90.0,
timeout_reconciliation=5.0,
timeout_portfolio=5.0,
timeout_disconnection=5.0,
timeout_post_stop=2.0,
)
# Instantiate the node with a configuration
node = TradingNode(config=config_node)
# Configure your strategy
strategy_config = SubscribeStrategyConfig(
instrument_id=InstrumentId.from_str("EUR/USD.IDEALPRO"),
# book_type=None,
# snapshots=True,
trade_ticks=False,
quote_ticks=True,
# bars=True,
)
# Instantiate your strategy
strategy = SubscribeStrategy(config=strategy_config)
# Add your strategies and modules
node.trader.add_strategy(strategy)
# Register your client factories with the node (can take user-defined factories)
node.add_data_client_factory(IB, InteractiveBrokersLiveDataClientFactory)
node.add_exec_client_factory(IB, InteractiveBrokersLiveExecClientFactory)
node.build()
# Stop and dispose of the node with SIGINT/CTRL+C
if __name__ == "__main__":
try:
node.run()
finally:
node.dispose()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |