IBKR.Net.Contracts
0.12.0
dotnet add package IBKR.Net.Contracts --version 0.12.0
NuGet\Install-Package IBKR.Net.Contracts -Version 0.12.0
<PackageReference Include="IBKR.Net.Contracts" Version="0.12.0" />
<PackageVersion Include="IBKR.Net.Contracts" Version="0.12.0" />
<PackageReference Include="IBKR.Net.Contracts" />
paket add IBKR.Net.Contracts --version 0.12.0
#r "nuget: IBKR.Net.Contracts, 0.12.0"
#:package IBKR.Net.Contracts@0.12.0
#addin nuget:?package=IBKR.Net.Contracts&version=0.12.0
#tool nuget:?package=IBKR.Net.Contracts&version=0.12.0
IBKR.Net
A .NET 10 client for the Interactive Brokers TWS / IB Gateway socket API — written from scratch, with no Interactive Brokers code inside, under the MIT license.
Early development (
0.x): the API is not stable yet.
Why
IB's own API client is licensed by IB (non-commercial in older releases, GPL-3.0 from 10.50), and every .NET wrapper we know of bundles it. IBKR.Net talks to TWS / IB Gateway over its local socket itself, so an app built on it is free to choose its own license.
You still need TWS or IB Gateway running and logged in: it is the program that connects to
IB's servers, and IBKR.Net connects to it on 127.0.0.1 (Gateway: 4001 live / 4002 paper).
Packages
| Package | Purpose |
|---|---|
IBKR.Net.Contracts |
Models and options; no dependencies |
IBKR.Net |
The client |
Quick start
await using var client = await IbkrClient.ConnectAsync(
new IbkrClientOptions { Host = "127.0.0.1", Port = 4002, ClientId = 1 }
);
var spy = (await client.GetContractDetailsAsync(
new Contract { Symbol = "SPY", SecurityType = "STK", Exchange = "SMART", Currency = "USD" }
))[0].Contract;
await client.SetMarketDataTypeAsync(MarketDataType.Delayed);
await foreach (var tick in client.SubscribeMarketDataAsync(spy))
Console.WriteLine($"{tick.Field}: {tick.Price} {tick.Size}");
Streams cancel their IB request when you stop reading; errors IB reports for a request throw
IbkrException, informational messages arrive on client.Notice.
What it covers (0.12.0)
IbkrClient |
IB request |
|---|---|
ConnectAsync, ManagedAccounts, Disconnected, Notice |
session, managedAccounts, errors |
GetServerTimeAsync |
reqCurrentTime |
GetContractDetailsAsync |
reqContractDetails |
GetOptionChainParametersAsync |
reqSecDefOptParams |
SetMarketDataTypeAsync, SubscribeMarketDataAsync |
reqMarketDataType, reqMktData (options: greeks from tickOptionComputation, open interest with generic tick 101) |
GetMarketDataSnapshotAsync |
reqMktData snapshot (never the paid regulatory snapshot), until tickSnapshotEnd |
GetHistoricalBarsAsync |
reqHistoricalData |
SubscribeRealtimeBarsAsync |
reqRealTimeBars |
GetPositionsAsync, SubscribePositionsAsync |
reqPositions |
SubscribeAccountSummaryAsync |
reqAccountSummary |
SubscribeAccountPnlAsync, SubscribePositionPnlAsync |
reqPnL, reqPnLSingle |
PlaceOrderAsync, ModifyOrderAsync, CancelOrderAsync (version 178 only) |
placeOrder, placeOrder with the order's id, cancelOrder |
GetOpenOrdersAsync |
reqAllOpenOrders |
GetExecutionsAsync |
reqExecutions with commission reports |
GetNewsProvidersAsync, GetHistoricalNewsAsync, GetNewsArticleAsync |
reqNewsProviders, reqHistoricalNews, reqNewsArticle |
SubscribeNewsAsync, GetBroadTapeContractsAsync |
reqMktData news ticks (292), broad tape contracts |
SubscribeMarketDepthAsync, GetMarketDepthExchangesAsync |
reqMktDepth (one exchange, Level 2, SMART depth), reqMktDepthExchanges |
SubscribeTickByTickAsync |
reqTickByTickData (Last, AllLast, BidAsk, MidPoint; optional history first) |
GetHistoricalTicksAsync |
reqHistoricalTicks (trades, bid / ask or midpoint, up to 1000 a request, before an end or from a start) |
GetWshMetaDataAsync, GetWshEventDataAsync |
reqWshMetaData, reqWshEventData (Wall Street Horizon corporate events as JSON; needs IB's WSH subscription, else error 10276) |
It speaks protocol version 187 (text messages), which current TWS / IB Gateway still accept.
Orders trade for real on a live account. They need a connection capped at
IbkrClient.OrderProtocolVersion (178); what-if orders are not built.
Not yet: option greeks, scanners.
Building
dotnet build IBKR.Net.slnx
dotnet test # offline; never connects to TWS / IB Gateway
csharpier format .
Contributing
Work happens on the current advance/X.Y.Z branch; main only receives releases, and a push to
main publishes the packages. See CLAUDE.md for the rules — especially the
clean-room rule: never copy or translate Interactive Brokers' source code.
License
MIT. Not affiliated with or endorsed by Interactive Brokers. "Interactive Brokers", "IBKR", "TWS" and "IB Gateway" are trademarks of their owners.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on IBKR.Net.Contracts:
| Package | Downloads |
|---|---|
|
IBKR.Net
A from-scratch .NET client for the Interactive Brokers TWS / IB Gateway socket API. Contains no Interactive Brokers code. |
GitHub repositories
This package is not used by any popular GitHub repositories.