Esempio n. 1
0
 public virtual void OnMarketDataRequest(TWSServerClientHandler client, int reqId, IBContract contract)
 {
     if (MarketDataRequest != null)
     {
         MarketDataRequest(this, new TWSMarketDataRequestEventArgs(client, reqId, contract));
     }
 }
Esempio n. 2
0
        public virtual void OnTcpClientConnect(IAsyncResult asyn)
        {
            TcpClientConnected?.Invoke(this, new TWSTcpClientConnectedEventArgs(this, null));
            try {
                // Here we complete/end the BeginAccept() asynchronous call
                // by calling EndAccept() - which returns the reference to
                // a new Socket object
                var tc = _listener.EndAcceptTcpClient(asyn);
                _clientCount++;
                //var s = new BufferedReadStream(tc.GetStream(), DEFAULT_BUFFER_SIZE);
                var s = tc.GetStream();

                var connection = new TWSServerClientHandler(this, s);

                lock (_clients) {
                    _clients.Add(connection);
                }

                connection.Start();

                // Since the main Socket is now free, it can go back and wait for
                // other clients who are attempting to connect
                _listener.BeginAcceptTcpClient(_connectCallback, null);
            }
            catch (ObjectDisposedException) {
                Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
            }
            catch (SocketException se) {
                OnError(new TWSError(TWSErrors.NO_VALID_CODE, se.Message));
            }
        }
Esempio n. 3
0
 public virtual void OnLogin(TWSServerClientHandler clientState, TWSClientInfo clientInfo, TWSClientId clientId)
 {
     if (Login != null)
     {
         Login(this, new TWSServerLoginEventArgs(clientState));
     }
 }
Esempio n. 4
0
 public virtual void OnMarketDepthCancel(TWSServerClientHandler client, int reqId, IBContract contract)
 {
     if (MarketDataCancel != null)
     {
         MarketDataCancel(this, new TWSMarketDataCancelEventArgs(client, reqId, contract));
     }
 }
Esempio n. 5
0
 public virtual void OnMarketDepthRequest(TWSServerClientHandler clientState, int reqId, IBContract contract,
                                          int numRows)
 {
     if (MarketDepthRequest != null)
     {
         MarketDepthRequest(this, new TWSMarketDepthRequestEventArgs(clientState, reqId, contract, numRows));
     }
 }
 public TWSServerErrorEventArgs(TWSServerClientHandler clientState, TWSError error)
     : base(clientState)
 {
     Error = error;
 }
Esempio n. 7
0
 public virtual void OnLogin(TWSServerClientHandler clientState, TWSClientInfo clientInfo, TWSClientId clientId)
 {
   if (Login != null)
     Login(this, new TWSServerLoginEventArgs(clientState));
 }
Esempio n. 8
0
 public virtual void OnMarketDepthCancel(TWSServerClientHandler client, int reqId, IBContract contract)
 {
   if (MarketDataCancel != null)
     MarketDataCancel(this, new TWSMarketDataCancelEventArgs(client, reqId, contract));
 }
Esempio n. 9
0
 public virtual void OnTWSClientConnect(TWSServerClientHandler client, int clientId) {}
Esempio n. 10
0
 public TWSServerErrorEventArgs(TWSServerClientHandler clientState, TWSError error)
   : base(clientState)
 {
   Error = error;
 }
Esempio n. 11
0
 public TWSServerEventArgs(TWSServerClientHandler clientState)
 {
   ClientState = clientState;
   Server = clientState.Server;
 }
Esempio n. 12
0
 public virtual void OnMarketDataCancel(TWSServerClientHandler client, int reqId, IBContract contract)
 {
     MarketDataCancel?.Invoke(this, new TWSMarketDataCancelEventArgs(client, reqId, contract));
 }
Esempio n. 13
0
 public virtual void OnTWSClientConnect(TWSServerClientHandler client, int clientId)
 {
 }
Esempio n. 14
0
 public TWSMarketDepthRequestEventArgs(TWSServerClientHandler clientState, int reqId, IBContract contract,
                                       int numRows)
   : base(clientState, reqId, contract)
 {
   numRows = numRows;
 }
Esempio n. 15
0
 public virtual void OnContractDetailsRequest(TWSServerClientHandler client, IBContract contract)
 {
 }
Esempio n. 16
0
 public TWSMarketDataCancelEventArgs(TWSServerClientHandler clientState, int reqId, IBContract contract)
   : base(clientState)
 {
   Contract = contract;
   ReqId = reqId;
 }
Esempio n. 17
0
 public virtual void OnLogin(TWSServerClientHandler clientState, TWSClientInfo clientInfo, TWSClientId clientId)
 {
     Login?.Invoke(this, new TWSServerLoginEventArgs(clientState));
 }
Esempio n. 18
0
 public TWSServerLoginEventArgs(TWSServerClientHandler clientState) : base(clientState) {}
Esempio n. 19
0
 public TWSMarketDepthRequestEventArgs(TWSServerClientHandler clientState, int reqId, IBContract contract,
                                       int numRows)
     : base(clientState, reqId, contract)
 {
     numRows = numRows;
 }
Esempio n. 20
0
    public virtual void OnTcpClientConnect(IAsyncResult asyn)
    {
      if (TcpClientConnected != null)
        TcpClientConnected(this, new TWSTcpClientConnectedEventArgs(this, null));
      try {
        // Here we complete/end the BeginAccept() asynchronous call
        // by calling EndAccept() - which returns the reference to
        // a new Socket object
        TcpClient tc = _listener.EndAcceptTcpClient(asyn);
        _clientCount++;
        //var s = new BufferedReadStream(tc.GetStream(), DEFAULT_BUFFER_SIZE);
        NetworkStream s = tc.GetStream();

        var connection = new TWSServerClientHandler(this, s);

        lock (_clients) {
          _clients.Add(connection);
        }

        connection.Start();

        // Since the main Socket is now free, it can go back and wait for
        // other clients who are attempting to connect
        _listener.BeginAcceptTcpClient(_connectCallback, null);
      }
      catch (ObjectDisposedException) {
        Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
      }
      catch (SocketException se) {
        OnError(new TWSError(TWSErrors.NO_VALID_CODE, se.Message));
      }
    }
Esempio n. 21
0
 public TWSMarketDataCancelEventArgs(TWSServerClientHandler clientState, int reqId, IBContract contract)
     : base(clientState)
 {
     Contract = contract;
     ReqId    = reqId;
 }
Esempio n. 22
0
 public virtual void OnMarketDataRequest(TWSServerClientHandler client, int reqId, IBContract contract)
 {
   if (MarketDataRequest != null)
     MarketDataRequest(this, new TWSMarketDataRequestEventArgs(client, reqId, contract));
 }
Esempio n. 23
0
 public TWSServerEventArgs(TWSServerClientHandler clientState)
 {
     ClientState = clientState;
     Server      = clientState.Server;
 }
Esempio n. 24
0
 public virtual void OnContractDetailsRequest(TWSServerClientHandler client, IBContract contract) {}
Esempio n. 25
0
 public TWSServerLoginEventArgs(TWSServerClientHandler clientState) : base(clientState)
 {
 }
Esempio n. 26
0
 public virtual void OnMarketDepthRequest(TWSServerClientHandler clientState, int reqId, IBContract contract,
                                          int numRows)
 {
   if (MarketDepthRequest != null)
     MarketDepthRequest(this, new TWSMarketDepthRequestEventArgs(clientState, reqId, contract, numRows));
 }
Esempio n. 27
0
    private void Init()
    {
      // Create threads to handle the messages
      _clientThread = new Thread(ProcessClientMessages);
      _serverThread = new Thread(ProcessServerMessaages);

      // Create the suspend/resume mutexes, initially lock them
      _clientMutex = new Mutex();
      _serverMutex = new Mutex();
      _clientMutex.WaitOne();
      _serverMutex.WaitOne();

      // Start the running the threads
      _serverThread.Start();
      _clientThread.Start();

      // The encoding class controls which thread runs next
      // by inspecting the stream content
      _enc = new TWSPlaybackPlayerEncoding(_logStream, _clientMutex, _serverMutex);

      // The "local" loop-back server provides a "reversed engineered" view into
      // what API the client was using and how exactly
      _loopbackServer = new TWSLoopbackServer(_logStream, _enc);
      _loopbackServer.Login += LoopbackServer_Login;
      _loopbackServer.MarketDataRequest += LoopbackServer_MarketDataRequest;
      _loopbackServer.MarketDepthCancel += LoopbackServer_MarketDepthCancel;
    }