/// <summary>
        /// Checks if RawDeal is later than Open posittion.
        /// Disabled 2017-10-19
        /// </summary>
        /// <param name="botID"></param>
        /// <param name="instrument"></param>
        /// <param name="rdTimeMili">Time in millisecs of raw deal</param>
        /// <returns></returns>
        private bool IsRawDealLaterThenOpenedPos(int botID, string instrument, long rdTimeMili)
        {
            lock (LckDictPositionsOfBots)
            {
                CBotPos bp = GetBotPos(botID, instrument);



                //no opened pos rd is later
                if (bp.Amount == 0)
                {
                    return(true);
                }


                long botposTimeMili = CUtilTime.GetUnixTimestampMillis(bp.DtOpen);

                if (rdTimeMili > botposTimeMili)
                {
                    return(true);
                }



                return(false);
            }
        }
        public void ProcessManualClearing()
        {
            LogMethEntry("ProcessManualClearing");
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");

            ProcessClearingDataBlock(CUtilTime.GetUnixTimestampMillis(_client.ServerTime), 0, 2, (int)_client.StockExchId);

            _client.UpdateMoneyData();
            CleanPosAndDeals();

            LogMethExit("ProcessManualClearing");
        }
        protected virtual bool IsNeedUpdateUserDealsLog(CRawUserDeal rd, Dictionary <int, Dictionary <string, CLatestTradeData> > dataWithTime)
        {
            int iExt_id_buy  = (int)rd.Ext_id_buy;
            int iExt_id_sell = (int)rd.Ext_id_sell;

            if (iExt_id_buy == 0 && iExt_id_sell == 0)
            {
                Error("Non user deal ! replId=" + rd.ReplId);
                return(false);;
            }



            long rdTimeMili = CUtilTime.GetUnixTimestampMillis(rd.Moment);

            int userId;

            if (dataWithTime.ContainsKey(iExt_id_buy) && iExt_id_buy != 0)
            {
                userId = iExt_id_buy;  //continue check
            }
            else if (dataWithTime.ContainsKey(iExt_id_sell) && iExt_id_sell != 0)
            {
                userId = iExt_id_sell; //continue check
            }
            else
            {
                return(true);                  //out
            }
            string instrument = rd.Instrument; //UserDealsPosBoxClient.  GetTicker(rd.Isin_Id);

            if (!dataWithTime[userId].ContainsKey(instrument))
            {
                return(true);
            }



            if ((rdTimeMili > dataWithTime[userId][instrument].Dt_timestamp_ms)
                ||
                (rdTimeMili == dataWithTime[userId][instrument].Dt_timestamp_ms &&
                 rd.ReplId > dataWithTime[userId][instrument].ReplId)

                )
            {
                return(true);
            }



            return(false);
        }
Beispiel #4
0
        private static void  GenMillis()
        {
            DateTime dt1 = DateTime.Now.AddHours(-2);
            // DateTime dt2 = dt1.AddSeconds(1);


            long t = CUtilTime.GetUnixTimestampMillis(dt1);

            if (t != 0)
            {
                System.Threading.Thread.Sleep(0);
            }
        }
        /// <summary>
        /// Updates latest botpos
        /// </summary>
        /// <param name="botId"></param>
        /// <param name="instrument"></param>
        /// <param name="botPos"></param>
        private void UpdateLatestBotPos(int botId, string instrument, CBotPos botPos)
        {
            try
            {
                long timeMili = CUtilTime.GetUnixTimestampMillis(botPos.DtClose);


                LatestBotPosData.Update(botId, instrument,
                                        new CLatestTradeData
                {
                    Dt_timestamp_ms = timeMili,
                    ReplId          = botPos.ReplIdClosed
                }
                                        );
            }
            catch (Exception e)
            {
            }
        }
        private void CheckSpecialTimeStamp(string col, object obj)
        {
            if (!col.Contains("_timestamp_ms"))    //special case for time
            {
                return;
            }

            int num = col.IndexOf("_timestamp_ms");

            if (num > -1)
            {
                string colDt = col.Substring(0, num);
                var    prop  = obj.GetType().GetProperty(colDt);
                if (prop != null)
                {
                    string val = CMySQLConv.ToMySQLFormat(CUtilTime.GetUnixTimestampMillis((DateTime)prop.GetValue(obj, null)));

                    _sqlInsertQuery._2_SetColumns.Add(col, val);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Add new "position change" fragment to closed  list.
        /// 2018-03-11 added idDeal
        /// </summary>
        public void AddClosedCostHist(long idDeal, decimal price, decimal amount,
                                      decimal fee, decimal feeDealing, decimal feeStock, EnmDealDir dir, DateTime moment, long replId)
        {
            long bpDtOpenTimeStampMs = CUtilTime.GetUnixTimestampMillis(DtOpen);

            //TODO check add fee ?
            ListClosingPosChanges.Add(new CPosChangeFrag
            {
                IdDeal                 = idDeal,
                Dir                    = dir,
                Moment                 = moment,
                ReplId                 = replId,
                Price                  = price,
                Amount                 = amount,
                Fee                    = fee,
                FeeDealing             = feeDealing,
                Fee_Stock              = feeStock,
                BP_DtOpen_timestamp_ms = bpDtOpenTimeStampMs
            });

            m_userDealsPosBox.BindDealBotPos(idDeal, bpDtOpenTimeStampMs);
        }
Beispiel #8
0
        public static void TestDateTime()
        {
            DateTime dt = DateTime.Now;


            long ltm = CUtilTime.GetUnixTimestampMillis(dt) + 1;


            if (ltm != null)
            {
                System.Threading.Thread.Sleep(0);
            }

            DateTime dt2 = CUtilTime.DateTimeFromUnixTimestampMillis(ltm);



            if (CUtilTime.IsEqualTimesMillisAcc(dt, dt2))    //(DateTime.Equals(dt,dt2))//(dt == dt2)
            {
                System.Threading.Thread.Sleep(0);
            }
        }
        /// <summary>
        /// Update deal's history log
        /// </summary>
        /// <param name="instrument"></param>
        /// <param name="rd"></param>
        private void UpdateDealsData(string instrument, CRawUserDeal rd)
        {
            CUserDeal userDeal = null;
            long      timeMili = 0;

            CUserDeal dealWithSameId = null;

            int botId = (int)(rd.Ext_id_buy > 0 ? rd.Ext_id_buy : rd.Ext_id_sell);

            lock (DictUserDealsLog)
            {
                if (!DictUserDealsLog.ContainsKey(botId))
                {
                    DictUserDealsLog[botId] = new Dictionary <string, List <CUserDeal> >();
                }

                if (!DictUserDealsLog[botId].ContainsKey(instrument))
                {
                    DictUserDealsLog[botId][instrument] = new List <CUserDeal>();
                }

                dealWithSameId = DictUserDealsLog[botId][instrument].FirstOrDefault(a => a.ReplId == rd.ReplId);

                //deal doesn't have the same id
                if (dealWithSameId == null)
                {
                    EnmDealDir dd = rd.Ext_id_buy > 0 ? EnmDealDir.Buy : EnmDealDir.Sell;

                    userDeal = new CUserDeal
                    {
                        ReplId  = rd.ReplId,
                        Amount  = rd.Amount,
                        Moment  = rd.Moment,
                        Price   = rd.Price,
                        BuySell = dd,
                        Fee     = rd.Fee_buy + rd.Fee_sell,
                        DealId  = rd.Id_Deal //2018-06-13
                    };

                    DictUserDealsLog[botId][instrument].Add((CUserDeal)userDeal);
                    // Plaza2Connector.TriggerRecalculateBot(botId, EnmBotEventCode.OnUserDeal,



                    timeMili = CUtilTime.GetUnixTimestampMillis(userDeal.Moment);

                    LatestDealsData.Update(botId, instrument,
                                           new CLatestTradeData
                    {
                        Dt_timestamp_ms = timeMili,
                        ReplId          = rd.ReplId,
                        Dt = rd.Moment
                    }

                                           );


                    CDBUserDeal dbUSerDeal = new CDBUserDeal();
                    CUtil.CopyObjProperties(userDeal, dbUSerDeal);
                    dbUSerDeal.Instrument       = instrument;
                    dbUSerDeal.account_trade_Id = (int)botId;
                    dbUSerDeal.stock_exch_id    = UserDealsPosBoxClient.StockExchId; //StockExchangeId;
                    dbUSerDeal.ReplId           = rd.ReplId;
                    dbUSerDeal.DealId           = rd.Id_Deal;                        //2018-05-31
                    dbUSerDeal.Fee = rd.Fee_buy + rd.Fee_sell;                       //2018-05-31


                    UserDealsPosBoxClient.UpdateDBUserDealsLog(dbUSerDeal);
                }
            }
        }
        protected bool IsNeedProcessPos(CRawUserDeal rd,
                                        Dictionary <int, Dictionary <string, CLatestTradeData> > dictLatestBotPos,
                                        bool isASTSRecieveFromStock)
        {
            int iExt_id_buy  = (int)rd.Ext_id_buy;
            int iExt_id_sell = (int)rd.Ext_id_sell;


            if (iExt_id_buy == 0 && iExt_id_sell == 0)
            {
                Error("Non user deal ! replId=" + rd.ReplId);
                return(false);;
            }



            long rdTimeMili = CUtilTime.GetUnixTimestampMillis(rd.Moment);

            int userId;

            if (dictLatestBotPos.ContainsKey(iExt_id_buy) && iExt_id_buy != 0)
            {
                userId = iExt_id_buy;  //continue check
            }
            else if (dictLatestBotPos.ContainsKey(iExt_id_sell) && iExt_id_sell != 0)
            {
                userId = iExt_id_sell; //continue check
            }
            else
            {
                return(true);   //out
            }
            //string instrument = UserDealsPosBoxClient.GetTicker(rd.Isin_Id);
            string instrument = rd.Instrument;

            if (!dictLatestBotPos[userId].ContainsKey(instrument))
            {
                return(true);
            }

            bool isNewerLastTimestamp      = rdTimeMili > dictLatestBotPos[userId][instrument].Dt_timestamp_ms;
            bool equalTimeStampButGtaterId = rdTimeMili == dictLatestBotPos[userId][instrument].Dt_timestamp_ms &&
                                             rd.ReplId > dictLatestBotPos[userId][instrument].ReplId &&
                                             dictLatestBotPos[userId][instrument].ReplId != 0;

            bool isLaterThanOpenedPos = IsRawDealLaterThenOpenedPos(userId, instrument, rdTimeMili);

            //bool isSpecASTSConditionPast = (isASTSRecieveFromStock && !isLaterThanOpenedPos && !_client.IsOnlineUserDeals) ? false : true;

            //Only if ASTS and if not online processing (not from DB) we NOT passed condition.
            //because for ASTS we loading data from Database
            bool isSpecASTSConditionPast = true;

            if (isASTSRecieveFromStock)
            {
                if (!_client.IsOnlineUserDeals)
                {
                    //if (isLaterThanOpenedPos)
                    isSpecASTSConditionPast = false;
                }
            }


            if ((isNewerLastTimestamp || equalTimeStampButGtaterId) &&
                isSpecASTSConditionPast)
            {
                return(true);
            }

            //Modification of 2017-10-19. Remove isLaterTanOpenedPos condition.
            //Reason: when opening position and than adding position on exact have
            //time algorithm doesn't work


            return(false);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            TestMail();


            //3854
            //   TestStockClassOriginal tsc = new TestStockClassOriginal();
            //  tsc.Test();

            //   TestStockSnapshoterSmart tss = new TestStockSnapshoterSmart();
            //  tss.Test();

            return;

            TestStockClassMod1 tsc = new TestStockClassMod1();

            tsc.Test();


            TestLoadingTestBitfinexWebSockConn();

            TestBitfeinxWebSockConnector();


            TestBitfinexRestConnector();

            var tst = new TestCryptoDealingServer();


            tst.TestGetPriceFromVolume();
            tst.TestGetOrderStatus();
            tst.TestGetRoundTo();
            tst.TestGetIntVolume();
            tst.TestBfxTimes();
            tst.TestPriceDecimals();
            tst.TestStepPrice();
            tst.TestGetDecimalVolume();



            TestConvPerf();

            return;


            //int val =   Int32.MaxValue;

            //if (val != 0)
            //  System.Threading.Thread.Sleep(0);

            //TestUserOrderLog();
            //TestS
            TestBitfeinxWebSockConnector();
            System.Threading.Thread.Sleep(100000000);
            return;

            TestCPUPerf();
            return;

            TestDBRouter();
            TestTradeManagerServer();

            TestSessionBox();


            //TestOrderTracker();



            //TestBitfeinxWebSockConnector();
            //TestBitfinexRestConnector();
            TestCryptoDealingServer();



            Console.ReadKey();
            return;


            TestWebScoketSharp();
            return;


            TestBlkQueue();


            new TestDataSyncher(new MockAlarmable());
            Console.ReadKey();


            TestTradeMgrServ();
            Console.ReadKey();


            TestNamedPipe();


            TestForceCPULoad();

            return;

            TestSyncroTwoValues();

            TestElseIf();


            TestReportDispatcher();
            return;


            TestUserDealPoxBox udpb = new TestUserDealPoxBox();


            TestMail();

            long m = CUtilTime.GetUnixTimestampMillis(DateTime.Now.AddHours(-2));

            //DateTime dt = new DateTime(2017,8,15,13,44



            if (m != null)
            {
                System.Threading.Thread.Sleep(0);
            }


            TestParseSec();


            return;

            TestASTSConverter();
            return;


            TestEncryptor();
            return;


            TestGlyth tg = new TestGlyth();

            tg.Test();
            return;


            TestClusterProcessor tcprc = new TestClusterProcessor();

            tcprc.Test2();


            return;

            tcprc.Test1();
            return;

            TestTime();


            CTestRadius tr = new CTestRadius();

            tr.DoTest();

            return;

            DOSer D = new DOSer();

            return;



            //var r = CUtilPerfCounter.GetCathegoryByName(".NET CLR Memory");
            // var r = CUtilPerfCounter.GetCountersList("zTest.vshost", ".NET CLR Memory");

            // PerformanceCounter r = new PerformanceCounter(".NET CLR Memory", "# Bytes in all Heaps");
            //  CPerfCounter r = new CPerfCounter(".NET CLR Memory", "# Bytes in all Heaps");

            //   if (r != null)
            //      System.Threading.Thread.Sleep(1);



            TestDealsAggregator da = new TestDealsAggregator();


            TestSynchroDBs();
            return;

            //    TestMail();
            //  return;


            //   TestVMDynProcessor();

            TestDBCommunicator t = new TestDBCommunicator();


            TestConv();



            TestSynchroDBs();
            return;


            TestReportDispatcher();
            return;

            TestPDFGenerator();
            return;

            TestSynchroDBs();
            //return;


            GenMillis();


            //TestDateTime();
            //return;


            //TestTF t = new TestTF();
            //     TestDictL2();



            return;


            //   TestUserDealsPosBox udpb = new TestUserDealsPosBox();

            //         GenMillis();

            //       TestSynchroDBs();
            //       return;

            //      TestUserDealPoxBox test = new TestUserDealPoxBox();

            //     return;

            //    TestPDFGenerator();
            //  return;

            //  TryStackFrame tsf = new TryStackFrame();
            //  tsf.MyMethod();
            //  return;


            //TestSQLCreateBuilder();

            // TestDateTime();



            //  StubUserDealsPosBox stubUserDealsPosBox = new StubUserDealsPosBox("RTS-6.16", 10, 13.16974M);
            //TestUserDealsPosBox t = new TestUserDealsPosBox();
        }