Beispiel #1
0
        private void doFetchAMEXImbalance(TCLIService.Client client, TSessionHandle sessHandle, DateTime QueryDate)
        {
            #region Construct Query
            double st = StartTime.TotalMilliseconds;
            double et = EndTime.TotalMilliseconds;

            var q = string.Format("select * from {1}.imb_amex where imb_amex.day={0:yyyyMMdd}",
                    QueryDate, db);

            string symbolArry = "";
            if (Symbols != null)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

            if (StartTime.TotalMilliseconds != 0)
            {
                q = q + " and time >=" + st.ToString();
            }

            if (EndTime.TotalMilliseconds != 0)
            {
                q = q + " and time <=" + et.ToString();
            }
            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);
            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {
                #region Fetch Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                do
                {
                    var resultsResp = client.FetchResults(fetchReq);

                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    int datet = 0;
                    DateTime dateti = DateTime.Now;
                    foreach (var row in resultSet.Rows)
                    {
                        TimeSpan t = TimeSpan.FromMilliseconds((double)row.ColVals[3].I32Val.Value);

                        if (datet != row.ColVals[0].I32Val.Value)
                        {
                            datet = row.ColVals[0].I32Val.Value;
                            dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                        }

                        uint buyv = 0;
                        uint sellv = 0;
                        var sidej = API.Imbalance.ImbSide.NONE;
                        if (row.ColVals[4].I32Val.Value == 0)
                        {
                            sidej = API.Imbalance.ImbSide.NONE;
                            buyv = 0;
                            sellv = 0;
                        }
                        else if (row.ColVals[4].I32Val.Value == 1)
                        {
                            sidej = API.Imbalance.ImbSide.BUY;
                            buyv = (uint)row.ColVals[9].I32Val.Value;
                            sellv = 0;
                        }
                        else if (row.ColVals[4].I32Val.Value == 2)
                        {
                            sidej = API.Imbalance.ImbSide.SELL;
                            sellv = (uint)row.ColVals[9].I32Val.Value;
                            buyv = 0;
                        }

                        var typej = API.Imbalance.ImbType.OTHER;
                        if (row.ColVals[5].I32Val.Value == 3)
                        { typej = API.Imbalance.ImbType.OTHER; }
                        else if (row.ColVals[5].I32Val.Value == 1)
                        { typej = API.Imbalance.ImbType.OPEN; }
                        else if (row.ColVals[5].I32Val.Value == 2)
                        { typej = API.Imbalance.ImbType.CLOSE; }

                        var data = new Data
                        {
                            type = Data.DataType.IMBALANCE,
                            imbalance = new API.Imbalance
                            {
                                Symbol = row.ColVals[2].StringVal.Value,
                                Date = dateti,
                                PairedVolume = (uint)row.ColVals[7].I32Val.Value,
                                Type = typej,
                                Time = t,
                                NetImbalance = (uint)row.ColVals[9].I32Val.Value,
                                BuyVolume = buyv,
                                SellVolume = sellv,
                                ReferencePrice = (decimal)row.ColVals[10].DoubleVal.Value,
                                Side = sidej,
                                ClearingPrice = (decimal)row.ColVals[13].DoubleVal.Value
                            }

                        };
                        Observer.OnNext(data); // notify observer...
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify(1.0m); /// TODO: send a report of the pct of job completed...
                } while (bMore);
                Observer.OnCompleted(); // we're done
                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #2
0
        private void doFetchTradeNo(TCLIService.Client client, TSessionHandle sessHandle, DateTime StartDate,DateTime EndDate)
        {
            #region Construct Query

            double st = StartTime.TotalMilliseconds;
            double et = EndTime.TotalMilliseconds;

            var q = string.Format("select * from {1}.trades where day >= {0:yyyyMMdd} and day <= {2:yyyyMMdd}",
                    StartDate,  db , EndDate);

            string symbolArry = "";
            if (Symbols != null)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

            if (StartTime.TotalMilliseconds != 0)
            {
                q = q + " and time >=" + st.ToString();
            }

            if (EndTime.TotalMilliseconds != 0)
            {
                q = q + " and time <=" + et.ToString();
            }

            q = q + "  order by day,seqno limit " + Maxrows;

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);

            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {

                #region Process Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                var stshow = true;
                var stfetchshow = true;
                double fetchstart = 0.0;
                do
                {
                    if (_cancellationSource.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    var resultsResp = new TFetchResultsResp();
                    if (stshow)
                    {
                        var stbegin = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        resultsResp = client.FetchResults(fetchReq);
                        var stend = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        Console.WriteLine("Marketdata1 running query time: " + ((stend - stbegin) / 1000.0).ToString());
                        stshow = false;
                    }
                    else
                    {
                        resultsResp = client.FetchResults(fetchReq);
                    }
                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    if (stfetchshow)
                    {
                        fetchstart = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        stfetchshow = false;
                    }
                    foreach (var row in resultSet.Rows)
                    {
                        TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[16].I32Val.Value);

                        var data = new Data
                        {
                            type = Data.DataType.TRADE,
                            trade = new API.Tick
                            {
                                Symbol = row.ColVals[2].StringVal.Value,
                                Date = DateTime.ParseExact(row.ColVals[19].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                Price = (decimal)row.ColVals[3].DoubleVal.Value,
                                Size = (uint)row.ColVals[7].I32Val.Value,
                                Open = (decimal)row.ColVals[9].DoubleVal.Value,
                                High = (decimal)row.ColVals[10].DoubleVal.Value,
                                Low = (decimal)row.ColVals[11].DoubleVal.Value,
                                Last = (decimal)row.ColVals[12].DoubleVal.Value,
                                TotalVolume = (ulong)row.ColVals[14].I64Val.Value,
                                BestBidSize = (uint)row.ColVals[0].I32Val.Value,
                                Time = t

                            }
                        };

                        Observer.OnNext(data); // notify observer...
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify((decimal)resultsResp.Results.Rows.Count); /// send a report of the pct of job completed...
                } while (bMore); // We're fetching 100 at a time.
                Console.WriteLine("Marketdata1 fetch data time: " + ((DateTime.Now.TimeOfDay.TotalMilliseconds - fetchstart) / 1000.0).ToString());
                Observer.OnCompleted(); // we're done

                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #3
0
        private void doFetchUnion(TCLIService.Client client, TSessionHandle sessHandle, string query)
        {
            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = query
            };
            var execResp = client.ExecuteStatement(execReq);

            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {
                #region test order file
                 FileStream fs = new FileStream("KMB.csv", FileMode.OpenOrCreate);
                 StreamWriter m_streamWriter = new StreamWriter(fs);
                #endregion

                #region Process Results

                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                do
                {
                    if (_cancellationSource.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    var resultsResp = client.FetchResults(fetchReq);
                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    int datet = 0;
                    DateTime dateti = DateTime.Now;

                    #region fetch union data

                    foreach (var row in resultSet.Rows)
                    {
                        #region TQI

                        if (unionType == "TQI")
                        {
                            #region T
                            if (row.ColVals[4].StringVal.Value == "T")
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                var data = new Data
                                {
                                    type = Data.DataType.TRADE,
                                    trade = new API.Tick
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                        Price = (decimal)row.ColVals[6].DoubleVal.Value,
                                        Size = (uint)row.ColVals[11].I32Val.Value,
                                        Open = (decimal)row.ColVals[7].DoubleVal.Value,
                                        High = (decimal)row.ColVals[8].DoubleVal.Value,
                                        Low = (decimal)row.ColVals[9].DoubleVal.Value,
                                        Last = (decimal)row.ColVals[10].DoubleVal.Value,
                                        TotalVolume = (ulong)row.ColVals[18].I64Val.Value,
                                        Time = t
                                    }
                                };
                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion

                            #region Q

                            else if (row.ColVals[4].StringVal.Value == "Q")
                             {
                                 TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                 if (datet != row.ColVals[0].I32Val.Value)
                                 {
                                  datet = row.ColVals[0].I32Val.Value;
                                  dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                 }

                                  var typej = API.Quote.QuoteType.NONE;
                                  if (row.ColVals[31].DoubleVal.Value == row.ColVals[34].DoubleVal.Value)
                                  {
                                      typej = API.Quote.QuoteType.BEST_ASK;
                                  }
                                  else if (row.ColVals[40].DoubleVal.Value == row.ColVals[37].DoubleVal.Value)
                                  {
                                      typej = API.Quote.QuoteType.BEST_BID;
                                  }
                                // string askexch = row.ColVals[11].StringVal.Value;

                                 var data = new Data
                                 {
                                  type = Data.DataType.QUOTE,
                                  quote = new API.Quote
                                   {
                                     Symbol = row.ColVals[2].StringVal.Value,
                                     Date = dateti,
                                     AskSize = (uint)row.ColVals[32].I32Val.Value,
                                     BidSize = (uint)row.ColVals[41].I32Val.Value,
                                     Ask = (decimal)row.ColVals[31].DoubleVal.Value,
                                     Bid = (decimal)row.ColVals[40].DoubleVal.Value,
                                     AskExchange = row.ColVals[35].StringVal.Value[0],
                                     BidExchange = row.ColVals[38].StringVal.Value[0],
                                     Type = typej,
                                     Time = t
                                    }
                                  };
                                 Observer.OnNext(data); // notify observer...
                             }

                            #endregion

                            #region I

                            else
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                if (datet != row.ColVals[0].I32Val.Value)
                                {
                                    datet = row.ColVals[0].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                uint buyv = 0;
                                uint sellv = 0;
                                var sidej = API.Imbalance.ImbSide.NONE;
                                if (row.ColVals[27].I32Val.Value == 0)
                                {
                                    sidej = API.Imbalance.ImbSide.NONE;
                                    buyv = 0;
                                    sellv = 0;
                                }
                                else if (row.ColVals[27].I32Val.Value == 1)
                                {
                                    sidej = API.Imbalance.ImbSide.BUY;
                                    buyv = (uint)row.ColVals[29].I32Val.Value;
                                    sellv = 0;
                                }
                                else if (row.ColVals[27].I32Val.Value == 2)
                                {
                                    sidej = API.Imbalance.ImbSide.SELL;
                                    sellv = (uint)row.ColVals[29].I32Val.Value;
                                    buyv = 0;
                                }

                                var typej = API.Imbalance.ImbType.OTHER;
                                if (row.ColVals[30].I32Val.Value == 3)
                                { typej = API.Imbalance.ImbType.OTHER; }
                                else if (row.ColVals[30].I32Val.Value == 1)
                                { typej = API.Imbalance.ImbType.OPEN; }
                                else if (row.ColVals[30].I32Val.Value == 2)
                                { typej = API.Imbalance.ImbType.CLOSE; }

                                var data = new Data
                                {
                                    type = Data.DataType.IMBALANCE,
                                    imbalance = new API.Imbalance
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = dateti,
                                        PairedVolume = (uint)row.ColVals[25].I32Val.Value,
                                        Type = typej,
                                        Time = t,
                                        NetImbalance = (uint)row.ColVals[29].I32Val.Value,
                                        BuyVolume = buyv,
                                        SellVolume = sellv,
                                        ReferencePrice = (decimal)row.ColVals[26].DoubleVal.Value,
                                        Side = sidej,
                                        ClearingPrice = (decimal)row.ColVals[19].DoubleVal.Value
                                    }

                                };
                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion
                        }

                        #endregion

                        #region TI

                        if (unionType == "TI")
                        {
                            #region T

                            if (row.ColVals[4].StringVal.Value == "T")
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                var data = new Data
                                {
                                    type = Data.DataType.TRADE,
                                    trade = new API.Tick
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                        Price = (decimal)row.ColVals[6].DoubleVal.Value,
                                        Size = (uint)row.ColVals[11].I32Val.Value,
                                        Open = (decimal)row.ColVals[7].DoubleVal.Value,
                                        High = (decimal)row.ColVals[8].DoubleVal.Value,
                                        Low = (decimal)row.ColVals[9].DoubleVal.Value,
                                        Last = (decimal)row.ColVals[10].DoubleVal.Value,
                                        TotalVolume = (ulong)row.ColVals[18].I64Val.Value,
                                        Time = t
                                    }
                                };
                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion

                            #region I

                            else
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                if (datet != row.ColVals[0].I32Val.Value)
                                {
                                    datet = row.ColVals[0].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                uint buyv = 0;
                                uint sellv = 0;
                                var sidej = API.Imbalance.ImbSide.NONE;
                                if (row.ColVals[27].I32Val.Value == 0)
                                {
                                    sidej = API.Imbalance.ImbSide.NONE;
                                    buyv = 0;
                                    sellv = 0;
                                }
                                else if (row.ColVals[27].I32Val.Value == 1)
                                {
                                    sidej = API.Imbalance.ImbSide.BUY;
                                    buyv = (uint)row.ColVals[29].I32Val.Value;
                                    sellv = 0;
                                }
                                else if (row.ColVals[27].I32Val.Value == 2)
                                {
                                    sidej = API.Imbalance.ImbSide.SELL;
                                    sellv = (uint)row.ColVals[29].I32Val.Value;
                                    buyv = 0;
                                }

                                var typej = API.Imbalance.ImbType.OTHER;
                                if (row.ColVals[30].I32Val.Value == 3)
                                { typej = API.Imbalance.ImbType.OTHER; }
                                else if (row.ColVals[30].I32Val.Value == 1)
                                { typej = API.Imbalance.ImbType.OPEN; }
                                else if (row.ColVals[30].I32Val.Value == 2)
                                { typej = API.Imbalance.ImbType.CLOSE; }

                                var data = new Data
                                {
                                    type = Data.DataType.IMBALANCE,
                                    imbalance = new API.Imbalance
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = dateti,
                                        PairedVolume = (uint)row.ColVals[25].I32Val.Value,
                                        Type = typej,
                                        Time = t,
                                        NetImbalance = (uint)row.ColVals[29].I32Val.Value,
                                        BuyVolume = buyv,
                                        SellVolume = sellv,
                                        ReferencePrice = (decimal)row.ColVals[26].DoubleVal.Value,
                                        Side = sidej,
                                        ClearingPrice = (decimal)row.ColVals[19].DoubleVal.Value
                                    }

                                };
                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion

                        }

                        #endregion

                        #region QI

                        if (unionType == "QI")
                        {
                            #region Q

                            if (row.ColVals[4].StringVal.Value == "Q")
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                if (datet != row.ColVals[0].I32Val.Value)
                                {
                                    datet = row.ColVals[0].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                var typej = API.Quote.QuoteType.NONE;
                                if (row.ColVals[16].DoubleVal.Value == row.ColVals[19].DoubleVal.Value)
                                {
                                    typej = API.Quote.QuoteType.BEST_ASK;
                                }
                                else if (row.ColVals[25].DoubleVal.Value == row.ColVals[22].DoubleVal.Value)
                                {
                                    typej = API.Quote.QuoteType.BEST_BID;
                                }
                                // string askexch = row.ColVals[11].StringVal.Value;

                                var data = new Data
                                {
                                    type = Data.DataType.QUOTE,
                                    quote = new API.Quote
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = dateti,
                                        AskSize = (uint)row.ColVals[17].I32Val.Value,
                                        BidSize = (uint)row.ColVals[26].I32Val.Value,
                                        Ask = (decimal)row.ColVals[16].DoubleVal.Value,
                                        Bid = (decimal)row.ColVals[25].DoubleVal.Value,
                                        AskExchange = row.ColVals[20].StringVal.Value[0],
                                        BidExchange = row.ColVals[23].StringVal.Value[0],
                                        Type = typej,
                                        Time = t
                                    }
                                };
                                Observer.OnNext(data); // notify observer...
                            }

                            #endregion

                            #region I
                            else
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                if (datet != row.ColVals[0].I32Val.Value)
                                {
                                    datet = row.ColVals[0].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                uint buyv = 0;
                                uint sellv = 0;
                                var sidej = API.Imbalance.ImbSide.NONE;
                                if (row.ColVals[12].I32Val.Value == 0)
                                {
                                    sidej = API.Imbalance.ImbSide.NONE;
                                    buyv = 0;
                                    sellv = 0;
                                }
                                else if (row.ColVals[12].I32Val.Value == 1)
                                {
                                    sidej = API.Imbalance.ImbSide.BUY;
                                    buyv = (uint)row.ColVals[14].I32Val.Value;
                                    sellv = 0;
                                }
                                else if (row.ColVals[12].I32Val.Value == 2)
                                {
                                    sidej = API.Imbalance.ImbSide.SELL;
                                    sellv = (uint)row.ColVals[14].I32Val.Value;
                                    buyv = 0;
                                }

                                var typej = API.Imbalance.ImbType.OTHER;
                                if (row.ColVals[15].I32Val.Value == 3)
                                { typej = API.Imbalance.ImbType.OTHER; }
                                else if (row.ColVals[15].I32Val.Value == 1)
                                { typej = API.Imbalance.ImbType.OPEN; }
                                else if (row.ColVals[15].I32Val.Value == 2)
                                { typej = API.Imbalance.ImbType.CLOSE; }

                                var data = new Data
                                {
                                    type = Data.DataType.IMBALANCE,
                                    imbalance = new API.Imbalance
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = dateti,
                                        PairedVolume = (uint)row.ColVals[10].I32Val.Value,
                                        Type = typej,
                                        Time = t,
                                        NetImbalance = (uint)row.ColVals[14].I32Val.Value,
                                        BuyVolume = buyv,
                                        SellVolume = sellv,
                                        ReferencePrice = (decimal)row.ColVals[11].DoubleVal.Value,
                                        Side = sidej,
                                        ClearingPrice = (decimal)row.ColVals[4].DoubleVal.Value
                                    }

                                };
                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion
                        }

                        #endregion

                        #region TQ

                        if (unionType == "TQ")
                        {
                            #region T
                            if (row.ColVals[4].StringVal.Value == "T")
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[2].I32Val.Value);

                                var data = new Data
                                {
                                    type = Data.DataType.TRADE,
                                    trade = new API.Tick
                                    {
                                        Symbol = row.ColVals[3].StringVal.Value,
                                        Date = DateTime.ParseExact(row.ColVals[1].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                        Price = (decimal)row.ColVals[7].DoubleVal.Value,
                                        Size = (uint)row.ColVals[12].I32Val.Value,
                                        Open = (decimal)row.ColVals[8].DoubleVal.Value,
                                        High = (decimal)row.ColVals[9].DoubleVal.Value,
                                        Low = (decimal)row.ColVals[10].DoubleVal.Value,
                                        Last = (decimal)row.ColVals[11].DoubleVal.Value,
                                        TotalVolume = (ulong)row.ColVals[19].I64Val.Value,
                                        Time = t
                                    }
                                };

                          #region test oreder file
                                m_streamWriter.WriteLine("OnTrade: " + data.trade.Symbol + ","  + data.trade.Date.ToShortDateString()+","+ data.trade.Time.ToString() + "," + data.trade.Price.ToString() + "," + data.trade.Size.ToString() + "," + data.trade.Open.ToString() + "," + data.trade.High.ToString() + "," + data.trade.Low.ToString() + "," + data.trade.Last.ToString() + "," + data.trade.TotalVolume.ToString());
                          #endregion

                                Observer.OnNext(data); // notify observer...
                            }
                            #endregion

                            #region Q

                            else if (row.ColVals[4].StringVal.Value == "Q")
                            {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[2].I32Val.Value);

                                if (datet != row.ColVals[1].I32Val.Value)
                                {
                                    datet = row.ColVals[1].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[1].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                var typej = API.Quote.QuoteType.NONE;
                                if (row.ColVals[20].DoubleVal.Value == row.ColVals[23].DoubleVal.Value)
                                {
                                    typej = API.Quote.QuoteType.BEST_ASK;
                                }
                                else if (row.ColVals[29].DoubleVal.Value == row.ColVals[26].DoubleVal.Value)
                                {
                                    typej = API.Quote.QuoteType.BEST_BID;
                                }
                                // string askexch = row.ColVals[11].StringVal.Value;

                                var data = new Data
                                {
                                    type = Data.DataType.QUOTE,
                                    quote = new API.Quote
                                    {
                                        Symbol = row.ColVals[3].StringVal.Value,
                                        Date = dateti,
                                        AskSize = (uint)row.ColVals[21].I32Val.Value,
                                        BidSize = (uint)row.ColVals[30].I32Val.Value,
                                        Ask = (decimal)row.ColVals[20].DoubleVal.Value,
                                        Bid = (decimal)row.ColVals[29].DoubleVal.Value,
                                        AskExchange = (char)row.ColVals[24].I32Val.Value,
                                        BidExchange = (char)row.ColVals[27].I32Val.Value,
                                        Type = typej,
                                        Time = t
                                    }
                                };

                                #region test oreder file
                        //        m_streamWriter.WriteLine("OnQuote: " + data.quote.Symbol + "," + data.quote.Time.ToString() + "," + data.quote.Ask.ToString() + "," + data.quote.AskSize.ToString() + "," + data.quote.Bid.ToString() + "," + data.quote.BidSize.ToString() + "," + data.quote.AskExchange.ToString() + "," + data.quote.BidExchange.ToString() + "," + data.quote.Type.ToString());
                                #endregion

                                Observer.OnNext(data); // notify observer...
                            }

                            #endregion
                        }

                        #endregion

                        #region I

                        if (unionType == "I")
                        {
                                TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].DoubleVal.Value);

                                if (datet != row.ColVals[0].I32Val.Value)
                                {
                                    datet = row.ColVals[0].I32Val.Value;
                                    dateti = DateTime.ParseExact(row.ColVals[0].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                uint buyv = 0;
                                uint sellv = 0;
                                var sidej = API.Imbalance.ImbSide.NONE;
                                if (row.ColVals[12].I32Val.Value == 0)
                                {
                                    sidej = API.Imbalance.ImbSide.NONE;
                                    buyv = 0;
                                    sellv = 0;
                                }
                                else if (row.ColVals[12].I32Val.Value == 1)
                                {
                                    sidej = API.Imbalance.ImbSide.BUY;
                                    buyv = (uint)row.ColVals[14].I32Val.Value;
                                    sellv = 0;
                                }
                                else if (row.ColVals[12].I32Val.Value == 2)
                                {
                                    sidej = API.Imbalance.ImbSide.SELL;
                                    sellv = (uint)row.ColVals[14].I32Val.Value;
                                    buyv = 0;
                                }

                                var typej = API.Imbalance.ImbType.OTHER;
                                if (row.ColVals[15].I32Val.Value == 3)
                                { typej = API.Imbalance.ImbType.OTHER; }
                                else if (row.ColVals[15].I32Val.Value == 1)
                                { typej = API.Imbalance.ImbType.OPEN; }
                                else if (row.ColVals[15].I32Val.Value == 2)
                                { typej = API.Imbalance.ImbType.CLOSE; }

                                var data = new Data
                                {
                                    type = Data.DataType.IMBALANCE,
                                    imbalance = new API.Imbalance
                                    {
                                        Symbol = row.ColVals[2].StringVal.Value,
                                        Date = dateti,
                                        PairedVolume = (uint)row.ColVals[10].I32Val.Value,
                                        Type = typej,
                                        Time = t,
                                        NetImbalance = (uint)row.ColVals[14].I32Val.Value,
                                        BuyVolume = buyv,
                                        SellVolume = sellv,
                                        ReferencePrice = (decimal)row.ColVals[11].DoubleVal.Value,
                                        Side = sidej,
                                        ClearingPrice = (decimal)row.ColVals[4].DoubleVal.Value
                                    }

                                };
                                Observer.OnNext(data); // notify observer...

                        }
                        #endregion

                    }
                    #endregion

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify((decimal)resultsResp.Results.Rows.Count); /// send a report of the pct of job completed...
                } while (bMore); // We're fetching 100 at a time.
                Observer.OnCompleted(); // we're done

               #region test oder file
                m_streamWriter.Close();
                m_streamWriter.Dispose();
                fs.Close();
                fs.Dispose();
               #endregion

                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #4
0
        private void doFetchShowDate(TCLIService.Client client, TSessionHandle sessHandle)
        {
            #region Construct Query
            string table = "";
            switch (Tablesource)
            {
                case Table.DAILY:
                    {
                        table = db + ".daily";
                    }
                    break;
                case Table.QUOTE:
                    {
                        table = db + ".quotes";
                    }
                    break;
                case Table.TRADE:
                    {
                        table = db + ".trades";
                    }
                    break;
                case Table.AMEX_IMB:
                    {
                        table = db + ".imb_amex";
                    }
                    break;
                case Table.ARCA_IMB:
                    {
                        table = db + ".imb_arca";
                    }
                    break;
                case Table.NASD_IMB:
                    {
                        table = db + ".imb_nasd";
                    }
                    break;
                case Table.NYSE_IMB:
                    {
                        table = db + ".imb_nyse";
                    }
                    break;

            }

            var q = string.Format("show partitions {0}",
                    table);

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);
            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {
                #region Process Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                do
                {
                    var resultsResp = client.FetchResults(fetchReq);

                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    foreach (var row in resultSet.Rows)
                    {
                        // Construct the object

                        var data = new Data
                        {
                            type = Data.DataType.PARTITIONS,
                            dates = new Data.Partitions
                            {
                                Dates = row.ColVals[0].StringVal.Value
                            }
                        };
                        Observer.OnNext(data); // notify observer...
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify(1.0m); /// TODO: send a report of the pct of job completed...
                } while (bMore);
                Observer.OnCompleted(); // we're done
                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #5
0
        private void doFetchQuote(TCLIService.Client client, TSessionHandle sessHandle, DateTime QueryDate, bool lastQuery = false)
        {
            #region Construct Query
            double st = StartTime.TotalMilliseconds;
            double et = EndTime.TotalMilliseconds;

            var q = string.Format("select * from {1}.quotes where day={0:yyyyMMdd}",
                   QueryDate, db);

            string symbolArry = "";
            if (Symbols != null && Symbols.Count() < 400)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

            if (StartTime.TotalMilliseconds != 0)
            {
                q = q + " and time >=" + st.ToString();
            }

            if (EndTime.TotalMilliseconds != 0)
            {
                q = q + " and time <=" + et.ToString();
            }

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);
            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {

                #region Fetch Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                do
                {

                    var resultsResp = client.FetchResults(fetchReq);
                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    int datet = 0;
                    DateTime dateti = DateTime.Now;
                    foreach (var row in resultSet.Rows)
                    {

                        bool symExi = false;

                        string str = row.ColVals[2].StringVal.Value;
                        foreach (var sym in Symbols)
                        {
                            if (str == sym || Symbols.Count() < 400)
                            {
                                symExi = true;
                                break;
                            }
                        }

                        if (symExi)
                        {
                            TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[16].I32Val.Value);

                            if (datet != row.ColVals[19].I32Val.Value)
                            {
                                datet = row.ColVals[19].I32Val.Value;
                                dateti = DateTime.ParseExact(row.ColVals[19].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                            }

                            var typej = API.Quote.QuoteType.NONE;
                            if (row.ColVals[5].DoubleVal.Value == row.ColVals[8].DoubleVal.Value)
                            { typej = API.Quote.QuoteType.BEST_ASK; }
                            else if (row.ColVals[6].DoubleVal.Value == row.ColVals[9].DoubleVal.Value)
                            { typej = API.Quote.QuoteType.BEST_BID; }

                            string askexch = row.ColVals[11].StringVal.Value;

                            var data = new Data
                            {
                                type = Data.DataType.QUOTE,
                                quote = new API.Quote
                                {
                                    Symbol = row.ColVals[2].StringVal.Value,
                                    Date = dateti,
                                    AskSize = (uint)row.ColVals[3].I32Val.Value,
                                    BidSize = (uint)row.ColVals[4].I32Val.Value,
                                    Ask = (decimal)row.ColVals[5].DoubleVal.Value,
                                    Bid = (decimal)row.ColVals[6].DoubleVal.Value,
                                    AskExchange = Convert.ToChar(row.ColVals[12].I32Val.Value),
                                    BidExchange = Convert.ToChar(row.ColVals[13].I32Val.Value),
                                    Type = typej,
                                    Time = t

                                }

                            };

                            Observer.OnNext(data); // notify observer...
                        }
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify(1.0m); /// TODO: send a report of the pct of job completed...
                } while (bMore);
                if (lastQuery)
                {
                    Observer.OnCompleted(); // we're done
                }

                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #6
0
        private void doFetchNews(TCLIService.Client client, TSessionHandle sessHandle, DateTime QueryDate, bool lastQuery = false)
        {
            #region Construct Query

            double st = StartTime.TotalMilliseconds;
            double et = EndTime.TotalMilliseconds;

            var q = string.Format("select * from {1}.news where day={0:yyyyMMdd}",
                    QueryDate, db);

            string symbolArry = "";
            if (Symbols != null && Symbols.Count() < 400)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

               if (StartTime.TotalMilliseconds != 0)
               {
                   q = q + " and msofday >= " + st.ToString();
               }

               if (EndTime.TotalMilliseconds != 0)
               {
                   q = q + " and msofday <= " + et.ToString();
               }

            // q = q + "  order by timestamp limit " + Maxrows;

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);

            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {
                #region Process Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                var stshow = true;
                var stfetchshow = true;
                double fetchstart = 0.0;
                do
                {
                    if (_cancellationSource.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    var resultsResp = new TFetchResultsResp();
                    if (stshow)
                    {
                        var stbegin = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        resultsResp = client.FetchResults(fetchReq);
                        var stend = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        Console.WriteLine("Marketdata1 running query time: " + ((stend - stbegin) / 1000.0).ToString());
                        stshow = false;
                    }
                    else
                    {
                        resultsResp = client.FetchResults(fetchReq);
                    }
                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    if (stfetchshow)
                    {
                        fetchstart = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        stfetchshow = false;
                    }
                    foreach (var row in resultSet.Rows)
                    {

                        bool symExi = false;

                        string str = row.ColVals[1].StringVal.Value;
                        foreach (var sym in Symbols)
                        {
                            if (str == sym || Symbols.Count() < 400)
                            {
                                symExi = true;
                                break;
                            }
                        }
                        if (symExi)
                        {
                            TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[2].I32Val.Value);

                        var data = new Data
                        {
                            type = Data.DataType.NEWS,
                            news = new API.News
                            {
                                Symbol = row.ColVals[1].StringVal.Value,
                                Day = DateTime.ParseExact(row.ColVals[9].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                Seqno = (uint)row.ColVals[0].I32Val.Value,
                                Category=row.ColVals[3].StringVal.Value,
                                Source=row.ColVals[4].StringVal.Value,
                                Headline=Regex.Replace(row.ColVals[5].StringVal.Value,"\"",""),
                                Resourceid=row.ColVals[6].StringVal.Value,
                                Story = Regex.Replace(row.ColVals[7].StringVal.Value, "\"", ""),
                                Tags = Regex.Replace(row.ColVals[8].StringVal.Value, "\"", ""),
                                Msofday = t

                            }
                        };
                        Observer.OnNext(data); // notify observer...
                        }
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify((decimal)resultsResp.Results.Rows.Count); /// send a report of the pct of job completed...
                } while (bMore); // We're fetching 100 at a time.
                Console.WriteLine("Marketdata1 fetch data time: " + ((DateTime.Now.TimeOfDay.TotalMilliseconds - fetchstart) / 1000.0).ToString());
                if (lastQuery)
                {
                    Observer.OnCompleted(); // we're done
                }
                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #7
0
        private void doFetchExgprints(TCLIService.Client client, TSessionHandle sessHandle, DateTime QueryDate, bool lastQuery = false)
        {
            #region Construct Query

            double st = StartTime.TotalMilliseconds;
            double et = EndTime.TotalMilliseconds;

            var q = string.Format("select * from {1}.exgprints where day={0:yyyyMMdd}",
                    QueryDate, db);

            string symbolArry = "";
            if (Symbols != null && Symbols.Count()<400)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);

            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {

                #region test order file
                /*FileStream fs = new FileStream("Exgprints.csv", FileMode.OpenOrCreate);
                StreamWriter m_streamWriter = new StreamWriter(fs);*/
                #endregion

                #region Process Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                var stshow = true;
                var stfetchshow = true;
                double fetchstart = 0.0;
                do
                {
                    if (_cancellationSource.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    var resultsResp =new TFetchResultsResp();
                    if (stshow)
                    {
                         var stbegin = DateTime.Now.TimeOfDay.TotalMilliseconds;
                         resultsResp = client.FetchResults(fetchReq);
                         var stend = DateTime.Now.TimeOfDay.TotalMilliseconds;
                         Console.WriteLine("Marketdata1 running query time: "+((stend-stbegin)/1000.0).ToString());
                        stshow = false;
                    }
                    else
                    {
                         resultsResp = client.FetchResults(fetchReq);
                    }
                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    if (stfetchshow)
                    {
                        fetchstart = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        stfetchshow = false;
                    }

                    #region Dic research
                    /*  var DicSym = new Dictionary<string, int>();
                    foreach (var symbol in Symbols)
                    {
                        DicSym.Add(symbol, 0);
                    }*/
                    #endregion

                    foreach (var row in resultSet.Rows)
                    {

                        bool symExi = false;

                        #region Dic Research
                        // symExi = DicSym.ContainsKey(row.ColVals[0].StringVal.Value);
                        #endregion

                        string str = row.ColVals[0].StringVal.Value;
                        foreach (var sym in Symbols)
                        {
                            if (str == sym || Symbols.Count()<400)
                            {
                                symExi = true;
                                break;
                            }
                        }

                        if(symExi)
                        {
                            TimeSpan t = TimeSpan.FromMilliseconds(row.ColVals[1].I32Val.Value);
                          var data = new Data
                          {
                            type = Data.DataType.EXGPRINTS,
                            exgPrints = new API.Exgprints
                            {
                                Symbol = row.ColVals[0].StringVal.Value,
                                Date = DateTime.ParseExact(row.ColVals[7].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
                                Price = (decimal)row.ColVals[5].DoubleVal.Value,
                                Size = (uint)row.ColVals[6].I32Val.Value,
                                ListedExchange = (short)row.ColVals[2].I32Val.Value,
                                ReportingExchange = (short)row.ColVals[3].I32Val.Value,
                                printtype = (short)row.ColVals[4].I32Val.Value,
                                Time = t

                            }
                         };

                          #region test oreder file
                     /*   m_streamWriter.WriteLine(data.exgPrints.Symbol + ","
                            + data.exgPrints.Date.ToShortDateString() + ","
                            + data.exgPrints.Time.ToString() + ","
                            + data.exgPrints.Price.ToString() + ","
                            + data.exgPrints.Size.ToString() + ","
                            + data.exgPrints.ListedExchange.ToString() + ","
                            + data.exgPrints.printtype.ToString() + ","
                            + data.exgPrints.ReportingExchange.ToString());*/
                        #endregion

                          Observer.OnNext(data); // notify observer...
                        }
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify((decimal)resultsResp.Results.Rows.Count); /// send a report of the pct of job completed...
                } while (bMore); // We're fetching 100 at a time.
                Console.WriteLine("Marketdata1 fetch data time: " + ((DateTime.Now.TimeOfDay.TotalMilliseconds - fetchstart) / 1000.0).ToString());
                if (lastQuery)
                {
                    Observer.OnCompleted(); // we're done
                }

                #region test oder file
              /*  m_streamWriter.Close();
                m_streamWriter.Dispose();
                fs.Close();
                fs.Dispose();*/
                #endregion

                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }
Beispiel #8
0
        private void doFetchDaily(TCLIService.Client client, TSessionHandle sessHandle, DateTime QueryDate, bool lastQuery = false)
        {
            #region Construct Query

            var q = string.Format("select * from {1}.daily where day={0:yyyyMMdd}",
                    QueryDate, db);

            string symbolArry = "";
            if (Symbols != null && Symbols.Count()<400)
            {
                foreach (string s in Symbols)
                {
                    symbolArry = symbolArry + "','" + s;
                }
                symbolArry = "(" + symbolArry.Remove(0, 2) + "')";

                q = q + " and symbol in " + symbolArry;

            }

            #endregion

            TExecuteStatementReq execReq = new TExecuteStatementReq
            {
                SessionHandle = sessHandle,
                Statement = q
            };
            var execResp = client.ExecuteStatement(execReq);
            if (execResp.Status.StatusCode == TStatusCode.SUCCESS_STATUS || execResp.Status.StatusCode == TStatusCode.SUCCESS_WITH_INFO_STATUS)
            {
                #region Fetch Results
                var stmtHandle = execResp.OperationHandle;

                var fetchReq = new TFetchResultsReq
                {
                    OperationHandle = stmtHandle,
                    Orientation = TFetchOrientation.FETCH_NEXT,
                    MaxRows = Maxrows
                };

                var bMore = false;
                do
                {
                    var resultsResp = client.FetchResults(fetchReq);

                    var resultSet = resultsResp.Results;
                    bMore = resultsResp.HasMoreRows;
                    int datet = 0;
                    DateTime dateti = DateTime.Now;
                    foreach (var row in resultSet.Rows)
                    {

                        bool symExi = false;

                        string str = row.ColVals[1].StringVal.Value;
                        foreach (var sym in Symbols)
                        {
                            if (str == sym || Symbols.Count() < 400)
                            {
                                symExi = true;
                                break;
                            }
                        }

                        if (symExi)
                        {

                            if (datet != row.ColVals[7].I32Val.Value)
                            {
                                datet = row.ColVals[7].I32Val.Value;
                                dateti = DateTime.ParseExact(row.ColVals[7].I32Val.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                            }
                            var data = new Data
                            {
                                type = Data.DataType.DAILY,
                                daily = new API.OHLC
                                {
                                    Symbol = row.ColVals[1].StringVal.Value,
                                    Date = dateti,
                                    Open = (decimal)row.ColVals[2].DoubleVal.Value,
                                    High = (decimal)row.ColVals[3].DoubleVal.Value,
                                    Low = (decimal)row.ColVals[4].DoubleVal.Value,
                                    Close = (decimal)row.ColVals[5].DoubleVal.Value,
                                    Volume = (ulong)row.ColVals[6].I32Val.Value,
                                    Time = TimeSpan.Parse("0")

                                }
                            };
                            Observer.OnNext(data); // notify observer...
                        }
                    }

                    fetchReq.Orientation = TFetchOrientation.FETCH_NEXT;
                    Observer.Notify(1.0m); /// TODO: send a report of the pct of job completed...
                } while (bMore);
                if (lastQuery)
                {
                    Observer.OnCompleted(); // we're done
                }
                #endregion
            }
            else
            {
                Observer.OnError(new Exception(string.Format("{0}: {1}", execResp.Status.ErrorCode, execResp.Status.ErrorMessage)));
            }
        }