Exemplo n.º 1
0
    private void ClientMarketDataLogger(object sender, TWSMarketDataEventArgs e)
    {
      if (e.Snapshot.Contract.SecurityType == IBSecurityType.Index)
      {
        if (e.TickType != IBTickType.LastPrice)
          return;
      }
      else if (e.TickType != IBTickType.LastSize &&
               e.TickType != IBTickType.AskSize &
               e.TickType != IBTickType.BidSize)
        return;

      var s = e.Snapshot;

      string symbol = e.Snapshot.Contract.Symbol + "-" + e.Snapshot.Contract.SecurityType;
      TextWriter sw;
      if (!_logFiles.TryGetValue(symbol, out sw))
      {
        _logFiles.Add(symbol, sw = new StreamWriter(symbol + ".log"));
        sw.WriteLine("ts,price,size,type");
      }

      if (e.TickType == IBTickType.LastSize)
        WriteToLog(sw, s.TradeTimeStamp, s.Last, s.LastSize, e.TickType);
      if (e.TickType == IBTickType.AskSize)
        WriteToLog(sw, s.AskTimeStamp, s.Ask, s.AskSize, e.TickType);
      if (e.TickType == IBTickType.BidSize)
        WriteToLog(sw, s.BidTimeStamp, s.Bid, s.BidSize, e.TickType);
      if (e.TickType == IBTickType.LastPrice)
        WriteToLog(sw, s.TradeTimeStamp, s.Last, 0, e.TickType);

    }
Exemplo n.º 2
0
    private void ClientMarketData(object sender, TWSMarketDataEventArgs e)
    {
      if (InvokeRequired)
      {
        TWSMarketDataSnapshot s = e.Snapshot.Clone() as TWSMarketDataSnapshot;
        BeginInvoke(_updateGridRowDelegate, s, e.TickType);

      }
      else
        _updateGridRowDelegate(e.Snapshot, e.TickType);
    }