Esempio n. 1
0
        private void CloseSession()
        {
            var req = new TCloseSessionReq
            {
                SessionHandle = _Session
            };
            var resp = _Client.CloseSession(req);

            resp.Status.CheckStatus();
        }
Esempio n. 2
0
        public IDisposable Query()
        {
            Contract.Requires(Observer != null);
            Contract.Requires(StartDate != null);
            Contract.Requires(EndDate != null);

            // restrict to 1 concurrent active query
            mBarrier.Wait();
            mBarrier.Reset();

            if (Observer != null) // won't ever be null, we're using code contracts to check this!
            {
                try
                {
                    // create an observable to request the data and encapsulate all the processing logic
                    return Observable.Create<Data>(o =>
                    {
                        var tokenSource = new CancellationTokenSource();
                        var cancelToken = tokenSource.Token;
                        _cancellationSource = tokenSource;

                        var task = Task.Factory.StartNew(() =>
                        {
                            // create thrift client connection
                            var socket = new TSocket(mServer, 5049);
                            var transport = new TBufferedTransport(socket);
                            var protocol = new TBinaryProtocol(transport);
                            var client = new TCLIService.Client(protocol);

                            // open transport/establish server connection
                            transport.Open();
                            var req = new TOpenSessionReq()
                            {
                                Client_protocol = TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1,
                                Username = mUser,
                                Password = mPassword
                            };
                            var openResp = client.OpenSession(req);
                            var sessHandle = openResp.SessionHandle;

                            //-----------------QUERY---------------------------------
                            #region Query
                            //Perform actual query -- by switching on option from subscribe

                            #region  check UnionType
                            bool imbExist = false;

                          /*  if ((Options & SubscriptionOptions.IMBALANCE) == SubscriptionOptions.IMBALANCE)
                            {
                                //Console.WriteLine("IMBALANCES");
                                Options = Options
                                    | SubscriptionOptions.AMEX_IMBALANCE
                                    | SubscriptionOptions.ARCA_IMBALANCE
                                    | SubscriptionOptions.NYSE_IMBALANCE
                                    | SubscriptionOptions.NASD_IMBALANCE;
                            }*/

                            if ((Options & SubscriptionOptions.TRADE) == SubscriptionOptions.TRADE)
                            {
                                //Console.WriteLine("T");
                                unionType = "T";
                                unionNum++;
                            }
                            if ((Options & SubscriptionOptions.QUOTE) == SubscriptionOptions.QUOTE)
                            {
                                //Console.WriteLine("Q");
                                unionType = unionType + "Q";
                                unionNum++;
                            }
                            if ((Options & SubscriptionOptions.AMEX_IMBALANCE) == SubscriptionOptions.AMEX_IMBALANCE)
                            {
                                //Console.WriteLine("AMEX");
                                unionType = unionType + "I";
                                imbExist = true;
                                unionNum++;
                            }
                            if ((Options & SubscriptionOptions.ARCA_IMBALANCE) == SubscriptionOptions.ARCA_IMBALANCE)
                            {
                                //Console.WriteLine("ARCA");
                                if (imbExist == false)
                                {
                                    unionType = unionType + "I";
                                    imbExist = true;
                                }
                                unionNum++;
                            }
                            if ((Options & SubscriptionOptions.NYSE_IMBALANCE) == SubscriptionOptions.NYSE_IMBALANCE)
                            {
                                //Console.WriteLine("NYSE");
                                if (imbExist == false)
                                {
                                    unionType = unionType + "I";
                                    imbExist = true;
                                }
                                unionNum++;
                            }
                            if ((Options & SubscriptionOptions.NASD_IMBALANCE) == SubscriptionOptions.NASD_IMBALANCE)
                            {
                                //Console.WriteLine("NASD");
                                if (imbExist == false)
                                {
                                    unionType = unionType + "I";
                                    imbExist = true;
                                }
                                unionNum++;
                            }
                            #endregion

                            if ( unionNum == 1 || unionNum==0)
                            {
                                #region benchmark test

                                /*Console.WriteLine("no block marketdata 1");
                                doFetchTradeNo(client, sessHandle,StartDate,EndDate);
                                Console.WriteLine("no block marketdata 2");
                                doFetchTrade2No(client, sessHandle, StartDate, EndDate);
                                Console.WriteLine("block marketdata 1");
                                #region single table
                                for (DateTime QueryDate = StartDate; QueryDate <= EndDate; QueryDate = QueryDate.AddDays(1))
                                {
                                    if ((Options & SubscriptionOptions.TRADE) == SubscriptionOptions.TRADE)
                                    {
                                        doFetchTrade(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.QUOTE) == SubscriptionOptions.QUOTE)
                                    {
                                        doFetchQuote(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.AMEX_IMBALANCE) == SubscriptionOptions.AMEX_IMBALANCE)
                                    {
                                        doFetchAMEXImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.ARCA_IMBALANCE) == SubscriptionOptions.ARCA_IMBALANCE)
                                    {
                                        doFetchARCAImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.NYSE_IMBALANCE) == SubscriptionOptions.NYSE_IMBALANCE)
                                    {
                                        doFetchNYSEImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.NASD_IMBALANCE) == SubscriptionOptions.NASD_IMBALANCE)
                                    {
                                        doFetchNASDImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.DAILY) == SubscriptionOptions.DAILY)
                                    {
                                        doFetchDaily(client, sessHandle, QueryDate);
                                    }

                                }
                                #endregion
                                Console.WriteLine("block marketdata 2");*/

                                #endregion

                                #region single table
                                for (DateTime QueryDate = StartDate; QueryDate <= EndDate; QueryDate = QueryDate.AddDays(1))
                                {
                                    if ((Options & SubscriptionOptions.TRADE) == SubscriptionOptions.TRADE)
                                    {
                                        doFetchTrade2(client, sessHandle, QueryDate, QueryDate.Date==EndDate.Date);
                                    }
                                    if ((Options & SubscriptionOptions.QUOTE) == SubscriptionOptions.QUOTE)
                                    {
                                        doFetchQuote(client, sessHandle, QueryDate, QueryDate.Date == EndDate.Date);
                                    }
                                    if ((Options & SubscriptionOptions.AMEX_IMBALANCE) == SubscriptionOptions.AMEX_IMBALANCE)
                                    {
                                        doFetchAMEXImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.ARCA_IMBALANCE) == SubscriptionOptions.ARCA_IMBALANCE)
                                    {
                                        doFetchARCAImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.NYSE_IMBALANCE) == SubscriptionOptions.NYSE_IMBALANCE)
                                    {
                                        doFetchNYSEImbalance(client, sessHandle, QueryDate, QueryDate.Date==EndDate.Date);
                                    }
                                    if ((Options & SubscriptionOptions.NASD_IMBALANCE) == SubscriptionOptions.NASD_IMBALANCE)
                                    {
                                        doFetchNASDImbalance(client, sessHandle, QueryDate);
                                    }
                                    if ((Options & SubscriptionOptions.DAILY) == SubscriptionOptions.DAILY)
                                    {
                                        doFetchDaily(client, sessHandle, QueryDate, QueryDate.Date == EndDate.Date);
                                    }
                                    if ((Options & SubscriptionOptions.EXGPRINTS) == SubscriptionOptions.EXGPRINTS)
                                    {
                                        doFetchExgprints(client, sessHandle, QueryDate, QueryDate.Date == EndDate.Date);
                                    }
                                    if ((Options & SubscriptionOptions.NEWS) == SubscriptionOptions.NEWS)
                                    {
                                        doFetchNews(client, sessHandle, QueryDate, QueryDate.Date == EndDate.Date);
                                    }

                                }
                                #endregion
                            }
                            else
                            {
                                #region Union fetchdata

                                for (DateTime QueryDate = StartDate; QueryDate <= EndDate; QueryDate=QueryDate.AddDays(1))
                                {
                                    string query = "";
                                    bool firstUnion = false;
                                    if ((Options & SubscriptionOptions.TRADE) == SubscriptionOptions.TRADE)
                                    {
                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionTradeQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionTradeQuery(QueryDate);
                                        }
                                        firstUnion = true;
                                    }
                                    if ((Options & SubscriptionOptions.QUOTE) == SubscriptionOptions.QUOTE)
                                    {
                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionQuoteQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionQuoteQuery(QueryDate);
                                        }
                                        firstUnion = true;

                                    }
                                    if ((Options & SubscriptionOptions.AMEX_IMBALANCE) == SubscriptionOptions.AMEX_IMBALANCE)
                                    {
                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionAmexQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionAmexQuery(QueryDate);
                                        }
                                        firstUnion = true;
                                    }
                                    if ((Options & SubscriptionOptions.ARCA_IMBALANCE) == SubscriptionOptions.ARCA_IMBALANCE)
                                    {

                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionArcaQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionArcaQuery(QueryDate);
                                        }
                                        firstUnion = true;
                                    }
                                    if ((Options & SubscriptionOptions.NYSE_IMBALANCE) == SubscriptionOptions.NYSE_IMBALANCE)
                                    {
                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionNyseQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionNyseQuery(QueryDate);
                                        }
                                        firstUnion = true;
                                    }
                                    if ((Options & SubscriptionOptions.NASD_IMBALANCE) == SubscriptionOptions.NASD_IMBALANCE)
                                    {
                                        if (firstUnion == true)
                                        {
                                            query = query + " union all " + createUnionNasdQuery(QueryDate);
                                        }
                                        else
                                        {
                                            query = createUnionNasdQuery(QueryDate);
                                        }
                                        firstUnion = true;

                                    }
                                    if ((Options & SubscriptionOptions.DAILY) == SubscriptionOptions.DAILY)
                                    {
                                        doFetchDaily(client, sessHandle,QueryDate);
                                    }

                                    query = "select * from ( " + query + " ) log order by log.seqno limit " + Maxrows;
                                  //  query = "select * from ( " + query + " )";
                                    //Console.WriteLine(query);
                                    doFetchUnion(client, sessHandle, query);
                                }
                                #endregion
                            }
                            #endregion
                            //-------------------------------------------------------

                            // close the session/transport
                            var closeReq = new TCloseSessionReq
                            {
                                SessionHandle = sessHandle
                            };
                            client.CloseSession(closeReq);
                            transport.Close();
                        }, cancelToken);

                        return Disposable.Create(tokenSource.Cancel);
                    }).Subscribe(Observer);

                }
                catch (Exception ex)
                {
                    Observer.OnError(ex);
                }
                finally
                {
                    // reset barrier
                    mBarrier.Set();
                }
            }
            return null;
        }
Esempio n. 3
0
 public Task <TCloseSessionResp> CloseSessionAsync(TCloseSessionReq req, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Proxy(nameof(CloseSessionAsync), (client, ct) => client.CloseSessionAsync(req, ct), cancellationToken));
 }