Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,12 @@ criteria = "safe-to-deploy"
delta = "0.7.0 -> 0.7.1"
notes = "Adds a serde alias for Arbitrum Nitro's miscased L1BlockNumber receipt field plus regression fixtures. No new dependencies, unsafe, build script, filesystem, network, process, credential, or data-exfiltration behavior."

[[audits.ibapi]]
who = "Faysal Aberkane <faysal.aberkane@gmail.com>"
criteria = "safe-to-deploy"
version = "5.0.0"
notes = "Recorded at the PR author's direction, who states they vetted this release. Temporary acceptance so CI can run inside the 3 day cooldown; remove the cooldown allow entry once 5.0.0 is 3 days old."

[[audits.icu_collections]]
who = "Nautech Systems <info@nautechsystems.io>"
criteria = "safe-to-deploy"
Expand Down
2 changes: 1 addition & 1 deletion .supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ version = "0.1.65"
criteria = "safe-to-deploy"

[[exemptions.ibapi]]
version = "3.3.0"
version = "5.0.0"
criteria = "safe-to-deploy"

[[exemptions.icu_collections]]
Expand Down
6 changes: 3 additions & 3 deletions .supply-chain/crate-dates.json
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,9 @@
"published": "2026-01-28T08:40:52.528531Z",
"verified_at": "2026-09-13T06:09:27Z"
},
"ibapi@3.3.0": {
"published": "2026-07-17T03:34:20.383654Z",
"verified_at": "2026-09-13T06:09:27Z"
"ibapi@5.0.0": {
"published": "2026-10-04T23:16:47.621967Z",
"verified_at": "2026-10-05T06:55:41Z"
},
"icu_collections@2.3.0": {
"published": "2026-08-13T23:28:40.279341Z",
Expand Down
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ dydx-proto = { version = "0.4.0", default-features = false }
fallible-streaming-iterator = "0.1.9"
flate2 = "1.1.10"
hypersync-client = { version = "1.4.1" }
ibapi = "=3.3.0"
ibapi = "=5.0.0"
ryu = "1.0.23"
serde_repr = "0.1.21"
time = { version = "0.3.55", default-features = false, features = [
Expand Down Expand Up @@ -417,6 +417,9 @@ store = { path = '.supply-chain' }
days = 3
trusted-base = "origin/develop"

[workspace.metadata.cooldown.allow]
ibapi = "5.0.0"

# -----------------------------------------------------------------------------
# Profiles
# -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion crates/adapters/interactive_brokers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ nautilus-trading = { workspace = true }
rstest = { workspace = true }
rust_decimal_macros = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }

# Run live smoke with `cargo run --example ib-data-tester --package nautilus-interactive-brokers --features examples`.
# Run embedded config unit tests with `cargo test --example ib-data-tester --package nautilus-interactive-brokers --features examples`.
Expand All @@ -113,7 +114,8 @@ path = "examples/node_data_tester.rs"
required-features = ["examples"]
doc = false

# Run live smoke with `cargo run --example ib-exec-tester --package nautilus-interactive-brokers --features examples`.
# Build offline with `cargo run --example ib-exec-tester --package nautilus-interactive-brokers --features examples`.
# Set `NAUTILUS_IB_RUN=1` to connect and `NAUTILUS_IB_LIVE_ORDERS=1` to submit orders.
# Run embedded config unit tests with `cargo test --example ib-exec-tester --package nautilus-interactive-brokers --features examples`.
[[example]]
name = "ib-exec-tester"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// -------------------------------------------------------------------------------------------------
// 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.
// -------------------------------------------------------------------------------------------------

//! Resolves the live quarterly futures contract the testers trade, so they keep working after
//! a contract expires. Mirrors `active_quarterly_contract` in
//! `examples/live/interactive_brokers/_common.py`.

use jiff::{
Timestamp, ToSpan,
civil::{Date, Weekday},
tz::TimeZone,
};
use nautilus_interactive_brokers::common::futures::{format_futures_symbol, futures_month_code};
use nautilus_model::identifiers::InstrumentId;

const QUARTERLY_CONTRACT_MONTHS: [i8; 4] = [3, 6, 9, 12];
// Roll to the next contract this many days before expiry, so a run never lands in expiry week.
const MIN_DAYS_TO_EXPIRY: i64 = 45;

pub(crate) fn es_future_instrument_id() -> InstrumentId {
let today = Timestamp::now().to_zoned(TimeZone::UTC).date();
active_quarterly_contract("ES", "XCME", today)
}

/// Returns the first quarterly contract whose third-Friday expiry is at least
/// `MIN_DAYS_TO_EXPIRY` days after `today`.
pub(crate) fn active_quarterly_contract(root: &str, venue: &str, today: Date) -> InstrumentId {
let target_expiry = today
.checked_add(MIN_DAYS_TO_EXPIRY.days())
.expect("target expiry within the supported date range");
let mut year = today.year();

loop {
for month in QUARTERLY_CONTRACT_MONTHS {
if third_friday(year, month) < target_expiry {
continue;
}

let month_code = futures_month_code(month as u8).expect("quarterly month code");
let symbol = format_futures_symbol(root, month_code, i32::from(year), 1)
.expect("single-digit futures symbol");
return InstrumentId::from(format!("{symbol}.{venue}").as_str());
}
year += 1;
}
}

fn third_friday(year: i16, month: i8) -> Date {
Date::new(year, month, 1)
.expect("first day of a quarterly month")
.nth_weekday_of_month(3, Weekday::Friday)
.expect("every month has a third Friday")
}

#[cfg(test)]
mod tests {
use jiff::civil::date;
use rstest::rstest;

use super::*;

#[rstest]
#[case(2026, 3, date(2026, 3, 20))]
#[case(2026, 12, date(2026, 12, 18))]
#[case(2027, 3, date(2027, 3, 19))]
fn test_third_friday(#[case] year: i16, #[case] month: i8, #[case] expected: Date) {
assert_eq!(third_friday(year, month), expected);
}

#[rstest]
#[case(date(2026, 9, 21), "ESZ6.XCME")]
#[case(date(2026, 11, 3), "ESZ6.XCME")]
#[case(date(2026, 11, 4), "ESH7.XCME")]
#[case(date(2026, 12, 31), "ESH7.XCME")]
fn test_active_quarterly_contract_rolls_before_expiry(
#[case] today: Date,
#[case] expected: &str,
) {
assert_eq!(
active_quarterly_contract("ES", "XCME", today),
InstrumentId::from(expected)
);
}

#[rstest]
fn test_es_future_instrument_id_uses_xcme() {
assert_eq!(es_future_instrument_id().venue.as_str(), "XCME");
}
}
23 changes: 15 additions & 8 deletions crates/adapters/interactive_brokers/examples/node_data_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
//! Run embedded config unit tests with:
//! `cargo test --example ib-data-tester --package nautilus-interactive-brokers --features examples`
//!
//! Edit the constants below to change the TWS/Gateway connection, target
//! instrument, market data type, and data spec profile. The adapter connects to
//! a locally running TWS or IB Gateway, so no credential environment variables
//! are required.
//! Edit the constants below to change the TWS/Gateway connection, market data type,
//! and data spec profile. The tester streams the live quarterly ES contract so it
//! works outside stock market hours. The adapter connects to a locally running TWS
//! or IB Gateway, so no credential environment variables are required.

use std::{collections::HashSet, time::Duration};

Expand All @@ -44,6 +44,9 @@ use nautilus_model::{
};
use nautilus_testkit::testers::{DataTester, DataTesterConfig};

#[path = "contracts/active_future.rs"]
mod active_future;

// Each variant is exercised by the tests and selected by editing DATA_SPEC_PROFILE,
// but only the default is constructed in a non-test build
#[allow(dead_code)]
Expand All @@ -59,15 +62,19 @@ const NODE_NAME: &str = "IB-DATA-TESTER-001";
const HOST: &str = DEFAULT_HOST;
const PORT: u16 = DEFAULT_TWS_PORT;
const CLIENT_ID: i32 = DEFAULT_CLIENT_ID;
const INSTRUMENT_ID: &str = "AAPL=STK.SMART";
const MARKET_DATA_TYPE: &str = "realtime";
// Delayed data streams without a real-time subscription; override with
// `NAUTILUS_IB_MARKET_DATA_TYPE` when the account is entitled to real-time data.
const MARKET_DATA_TYPE: &str = "delayed";
const AUTO_STOP_SECS: u64 = 0;
const DATA_SPEC_PROFILE: IbDataSpecProfile = IbDataSpecProfile::Supported;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let instrument_id = InstrumentId::from(INSTRUMENT_ID);
let market_data_type = parse_market_data_type(MARKET_DATA_TYPE);
let instrument_id = active_future::es_future_instrument_id();
let market_data_type = parse_market_data_type(
&std::env::var("NAUTILUS_IB_MARKET_DATA_TYPE")
.unwrap_or_else(|_| MARKET_DATA_TYPE.to_string()),
);
let bar_type = BarType::from(format!("{instrument_id}-1-MINUTE-LAST-EXTERNAL").as_str());

let data_config = InteractiveBrokersDataClientConfig {
Expand Down
Loading