Skip to content

Conversation

caio-northfleet
Copy link
Contributor

Added a mock TWS IB Gateway to /sandbox

  • Mimics a real TWS IB Gateway
  • Contains a simplified and minimum set of functions for unit tests to run
  • START_MOCK_TWS=1 environment variable used to activate it
  • No support for protobuf added, it responds with server version 200

Fixed remaining race in EClient

  • Although not catastrophic, fixed Disconnect phase issues
  • All unit tests now PASS using -race flag
  • Checked only with the mock TWS IB Gateway
  • Pending execution of unit tests with real TWS IB Gateway

- Add sandbox/mock_tws.go: legacy serverVersion=200 mock.
- Implements handshake and initial time events.
- Replies (legacy) for: market data, positions, positions multi,
  account updates, account summary, account updates multi, user info,
  scanner params (safe XML), scanner data (end), historical data,
  soft dollar tiers (zero tiers).
- client_test.go: IBAPI_HOST/PORT env; optional START_MOCK_TWS.
- Full suite passes without -race via sandbox.
- -race surfaces EClient shutdown races (to fix next).
- EClient: add single-flight guard for Disconnect(); avoid watcher calling
  Disconnect; capture ctx in watcher to prevent races with reset; reset guard
  in reset().
- Sandbox: flesh out legacy mock responses and fix formats (scanner XML,
  TickPrice attrMask) so full suite runs without real TWS.
- Verified TestAccountOperations passes under -race with sandbox.
@caio-northfleet
Copy link
Contributor Author

Note: I am using this TWS sandbox in my project, but I believe it might be of good use if shared here.

@pchavanne
Copy link
Contributor

Hello Caio,
Thank you very much for your contribution.
I think your mock tws gateway is great ! I am just wondering if ibapi is the right place to put it as this package's purpose is to stay as close as possible to the official api. Maybe ibsync could be a good fit. Also i will add very soon the last rounds of protobuf so if the mock tws doesn't support it, I am afraid that it won't be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants