private void OnLogin(TWSClientInfo clientInfo, TWSClientId clientId) { if (Server != null) { Server.OnLogin(this, clientInfo, clientId); } }
private void OnLogin(TWSClientInfo clientInfo, TWSClientId clientId) { if (Server != null) Server.OnLogin(this, clientInfo, clientId); }
/// <summary> /// Connect to the specified IB Trader Workstation Endpoint /// </summary> /// <param name="clientId">The client id to use when connecting</param> public void Connect(int clientId) { lock (this) { if (IsConnected) { OnError(TWSErrors.ALREADY_CONNECTED); return; } try { _tcpClient = new TcpClient(); _tcpClient.NoDelay = true; _tcpClient.Connect(_endPoint); lock (_socketLock) { if (RecordForPlayback) { if (_recordStream == null) _recordStream = SetupDefaultRecordStream(); _enc = new TWSPlaybackRecorderEncoding(new BufferedReadStream(_tcpClient.GetStream()), _recordStream); } else _enc = new TWSEncoding(new BufferedReadStream(_tcpClient.GetStream())); _enc.Encode(ClientInfo); _enc.Flush(); _doWork = true; // Only create a reader thread if this Feed IS NOT reconnecting if (!_reconnect) { _thread = new Thread(ProcessMessages) { IsBackground = true, Name = "IBReader" }; } // Get the server version ServerInfo = _enc.DecodeServerInfo(); if (ServerInfo.Version >= 20) { _twsTime = _enc.DecodeString(); } if (ServerInfo.Version < TWSServerInfo.SERVER_VERSION) { Disconnect(); throw new Exception("Server version is too low, please update the TWS server"); } // Send the client id if (ServerInfo.Version >= 3) { if (clientId == -1) { if (_tcpClient.Client.LocalEndPoint is IPEndPoint) { var p = _tcpClient.Client.LocalEndPoint as IPEndPoint; byte[] ab = p.Address.GetAddressBytes(); clientId = ab[ab.Length - 1] << 16 | p.Port; } else clientId = new Random().Next(); } var id = new TWSClientId(clientId); _enc.Encode(id); } } // Only start the thread if this Feed IS NOT reconnecting if (!_reconnect) _thread.Start(); _clientId = clientId; OnStatusChanged(Status = TWSClientStatus.Connected); } catch (Exception e) { Disconnect(); throw; } } }
public virtual void OnLogin(TWSServerClientHandler clientState, TWSClientInfo clientInfo, TWSClientId clientId) { if (Login != null) Login(this, new TWSServerLoginEventArgs(clientState)); }
public virtual void OnLogin(TWSServerClientState clientState, TWSClientInfo clientInfo, TWSClientId clientId) { if (Login != null) { Login(this, new TWSServerEventArgs(clientState)); } }
void OnLogin(TWSClientInfo clientInfo, TWSClientId clientId) { Server?.OnLogin(this, clientInfo, clientId); }
void OnLogin(TWSClientInfo clientInfo, TWSClientId clientId) { Server?.OnLogin(this, clientInfo, clientId); Login?.Invoke(this, new TWSServerEventArgs(this)); }
public virtual void OnLogin(TWSServerClientHandler clientState, TWSClientInfo clientInfo, TWSClientId clientId) { Login?.Invoke(this, new TWSServerLoginEventArgs(clientState)); }
/// <summary> /// Connect to the specified IB Trader Workstation Endpoint /// </summary> /// <param name="clientId">The client id to use when connecting</param> public void Connect(int clientId) { lock (this) { if (IsConnected) { OnError(TWSErrors.ALREADY_CONNECTED); return; } try { _tcpClient = new TcpClient(); _tcpClient.Connect(_endPoint); _tcpClient.NoDelay = true; if (RecordForPlayback) { if (_recordStream == null) _recordStream = SetupDefaultRecordStream(); _enc = new TWSPlaybackEncoding(new BufferedReadStream(_tcpClient.GetStream()), _recordStream); } else _enc = new TWSEncoding(new BufferedReadStream(_tcpClient.GetStream())); _enc.Encode(ClientInfo); _doWork = true; // Only create a reader thread if this Feed IS NOT reconnecting if (!_reconnect) { _thread = new Thread(new ThreadStart(ProcessMessages)); _thread.Name = "IB Reader"; } // Get the server version ServerInfo = _enc.DecodeServerInfo(); if (ServerInfo.Version >= 20) { _twsTime = _enc.DecodeString(); } // Send the client id if (ServerInfo.Version >= 3) { if (clientId == -1) { if (_tcpClient.Client.LocalEndPoint is IPEndPoint) { IPEndPoint p = _tcpClient.Client.LocalEndPoint as IPEndPoint; byte[] ab = p.Address.GetAddressBytes(); clientId = ab[ab.Length - 1] << 16 | p.Port; } else clientId = new Random().Next(); } TWSClientId id = new TWSClientId(clientId); _enc.Encode(id); } // Only start the thread if this Feed IS NOT reconnecting if (!_reconnect) _thread.Start(); _clientId = clientId; OnStatusChanged(Status = TWSClientStatus.Connected); } catch (Exception e) { OnError(e.Message); OnError(TWSErrors.CONNECT_FAIL); } } }