예제 #1
0
 public void AccSumEnd(int p_reqId)
 {
     if (m_getAccountSummaryMres != null)
     {
         m_getAccountSummaryMres.Set();  // Sets the state of the event to signaled, which allows one or more threads waiting on the event to proceed.
     }
     // if you don't cancel it, all the data update come every 1 minute, which might be good, because we can give it to user instantenously....
     // However, it would be an unnecessary traffic all the time... So, better to Cancel the data streaming.
     BrokerWrapper.CancelAccountSummary(p_reqId);
 }
예제 #2
0
        public List <BrAccSum>?GetAccountSums()
        {
            List <BrAccSum>?result   = null;
            int             accReqId = -1;

            try
            {
                Stopwatch sw1 = Stopwatch.StartNew();
                lock (m_getAccountSummaryLock)         // IB only allows one query at a time, so next client has to wait
                {
                    m_accSums = new List <BrAccSum>(); // delete old values
                    if (m_getAccountSummaryMres == null)
                    {
                        m_getAccountSummaryMres = new ManualResetEventSlim(false);  // initialize as unsignaled
                    }
                    else
                    {
                        m_getAccountSummaryMres.Reset();        // set to unsignaled, which makes thread to block
                    }
                    accReqId = BrokerWrapper.ReqAccountSummary();

                    bool wasLightSet = m_getAccountSummaryMres.Wait(5000);     // timeout at 5sec
                    if (!wasLightSet)
                    {
                        Utils.Logger.Error("ReqAccountSummary() ended with timeout error.");
                    }
                    //m_getAccountSummaryMres.Dispose();    // not necessary. We keep it for the next sessions for faster execution.
                    result = m_accSums; // save it before releasing the lock, so other threads will not overwrite the result
                }
                sw1.Stop();
                Utils.Logger.Info($"ReqAccountSummary() ends in {sw1.ElapsedMilliseconds}ms GatewayId: '{this.GatewayId}', Thread Id= {Thread.CurrentThread.ManagedThreadId}");
            }
            catch (Exception e)
            {
                Utils.Logger.Error($"ReqAccountSummary() ended with exception: {e.Message}. BrokerYF is only replaced by BrokerIB after the IB connection had been established.");
                return(null);
            }
            finally
            {
                if (accReqId != -1)
                {
                    BrokerWrapper.CancelAccountSummary(accReqId);
                }
            }
            return(result);
        }