项目作者: dshe

项目描述 :
Interactive Brokers reactive C# API.
高级语言: C#
项目地址: git://github.com/dshe/InterReact.git
创建时间: 2019-01-18T13:55:04Z
项目社区:https://github.com/dshe/InterReact

开源协议:

下载


InterReact Version License Ukraine

Reactive C# API to Interactive Brokers Trader Workstation (TWS)

  • .NET 8.0 library
  • supports IB TWS API Stable 10.19 (Mar 25 2024 )
  • dependencies: RxSockets, Stringification, NodaTime
  • demo applications: Console, WPF
  1. interface IInterReactClient : IAsyncDisposable
  2. {
  3. IPEndPoint RemoteIpEndPoint { get; }
  4. Request Request { get; }
  5. IObservable<object> Response { get; }
  6. Service Service { get; }
  7. }

Example

  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Reactive.Linq;
  4. using InterReact;
  1. // Create the InterReact client by connecting to TWS/Gateway on the local host.
  2. IInterReactClient client = await InterReactClient.ConnectAsync();
  3. // Create a contract object.
  4. Contract contract = new()
  5. {
  6. SecurityType = ContractSecurityType.Stock,
  7. Symbol = "AMZN",
  8. Currency = "USD",
  9. Exchange = "SMART"
  10. };
  11. // Create and then subscribe to the observable which can observe ticks for the contract.
  12. IDisposable subscription = client
  13. .Service
  14. .CreateMarketDataObservable(contract)
  15. .OfTickClass(selector => selector.PriceTick)
  16. .Where(tick => tick.TickType == TickType.LastPrice)
  17. .Subscribe(onNext: priceTick => Console.WriteLine($"Last Price = {priceTick.Price}"));
  18. Console.WriteLine(Environment.NewLine + "press a key to exit...");
  19. Console.ReadKey();
  20. Console.Clear();
  21. // Dispose the subscription to stop receiving ticks.
  22. subscription.Dispose();
  23. // Disconnect from TWS/Gateway.
  24. await client.DisposeAsync();

Notes

Interactive Brokers Trader Workstation (TWS) or Gateway must be running with API access enabled. In TWS, navigate to Edit / Global Configuration / API / Settings. Ensure the option “Enable ActiveX and Socket Clients” is selected.