コード例 #1
0
ファイル: Program.cs プロジェクト: ifzz/FDK
        static void Main(string[] args)
        {
            Arbitrage coldArb = null;
            List<Arbitrage> warmArbList = new List<Arbitrage>();

            for (int i = 0; i < 10000; i++)
            {
                Arbitrage newArb = new Arbitrage(DateTime.Now, 1, 2, "dfas");
                for (int j = 0; j < 10; j++)
                {
                    newArb.ArbitrageDetails.Add(new ArbitrageDetail(DateTime.Now));
                }
                warmArbList.Add(newArb);
                coldArb = newArb;
            }

            using (Model.ArbitrageContext arbContext = new Model.ArbitrageContext())
            {
                arbContext.Arbitrages.Add(coldArb);
                arbContext.SaveChanges();
            }

            Stopwatch sw = new Stopwatch();

            using (Model.ArbitrageContext arbContext = new Model.ArbitrageContext())
            {
                arbContext.Configuration.AutoDetectChangesEnabled = false;
                //arbContext.Configuration.ValidateOnSaveEnabled = false;

                sw.Start();

                foreach( var item in warmArbList )
                    arbContext.Arbitrages.Add(item);
                sw.Stop();
                Console.WriteLine("Time of adding 10000 elements : " + sw.ElapsedMilliseconds + " ms");

                sw.Reset();
                sw.Start();
                arbContext.SaveChanges();
                sw.Stop();
                Console.WriteLine("Time of saving 10000 elements : " + sw.ElapsedMilliseconds + " ms");
            }

        }
コード例 #2
0
ファイル: WatcherSymbol.cs プロジェクト: ifzz/FDK
		private void Run(SingleAdviser<int> first, SingleAdviser<int> second, Level2 f, Level2 s, ref  Arbitrage arb)
		{
			if ( f.Bids.Count == 0 || s.Asks.Count == 0 || s.Ask - f.Bid > -float.Epsilon)
			{
                if (null != arb)
				{
                    arb.EndDateTime = DateTime.UtcNow;
                    arb.Duration = (arb.EndDateTime - arb.StartDateTime).TotalMilliseconds;
                    ArbitrageDetail prevArbDetail = arb.ArbitrageDetails.Last();
                    prevArbDetail.EndTickTime = arb.EndDateTime;
                    prevArbDetail.duration = (prevArbDetail.EndTickTime - prevArbDetail.StartTickTime).TotalMilliseconds;

                    double test = Math.Abs(arb.ArbitrageDetails.Sum(p => p.duration));
                    if (test - arb.Duration > 0.0000000001)
                    {
                        Console.WriteLine("DurationError");
                    }

                    Arbitrage refArbitrage = arb;
                    //Task.Factory.StartNew(() =>
                    //{
                    //    using (Model.ArbitrageContext arbContext = new Model.ArbitrageContext())
                    //    {
                    //        arbContext.Arbitrages.Add(refArbitrage);
                    //        arbContext.SaveChanges();
                    //    }
                    //});

                    arb = null;

                    if (!dictSPairs.Any(p => p.Value.m_firstBidSecondAskArbitrage != null))
                    {
                        ArbitrageTimeStatistics ars = ArbitrageTimeStatistics.Instance(f.Symbol);
                        ars.TotalSecondsArbitradge += (DateTime.UtcNow - ars.StartArbitrageDateTime).TotalSeconds;
                        ars.StartArbitrageDateTime = DateTime.MinValue;

                        Console.WriteLine("Symbol={3}; ArbitrageTime={0} seconds; Percent={1}%; InHourSeconds={2}", ars.TotalSecondsArbitradge,
                            ars.TotalSecondsArbitradge * 100 / (DateTime.UtcNow - ArbitrageTimeStatistics.StartAppDateTime).TotalSeconds,
                            ars.TotalSecondsArbitradge * 3600 / (DateTime.UtcNow - ArbitrageTimeStatistics.StartAppDateTime).TotalSeconds,
                            f.Symbol);
                    }
				
                }
			}
			else
			{
                DateTime utcNow = DateTime.UtcNow;

                if (arb == null)
                    arb = new Arbitrage(utcNow, first.Tag, second.Tag, m_symbol);

                ArbitrageDetail arbDetail = new ArbitrageDetail(utcNow);
                if (f.Asks.Count > 0)
                {
                    arbDetail.B1Ask1 = f.Asks[0].Price;
                    arbDetail.B1Ask1Volume = f.Asks[0].Volume;
                }
                arbDetail.B1Bid1 = f.Bids[0].Price;
                arbDetail.B1Bid1Volume = f.Bids[0].Volume;
                arbDetail.B2Ask1 = s.Asks[0].Price;
                arbDetail.B2Ask1Volume = s.Asks[0].Volume;
                if (s.Bids.Count > 0)
                {
                    arbDetail.B2Bid1 = s.Bids[0].Price;
                    arbDetail.B2Bid1Volume = s.Bids[0].Volume;
                }
                if (arb.ArbitrageDetails.Count != 0)
                {
                    ArbitrageDetail previos = arb.ArbitrageDetails.Last();
                    previos.EndTickTime = arbDetail.StartTickTime;
                    previos.duration = (previos.EndTickTime - previos.StartTickTime).TotalMilliseconds;
                }
                arbDetail.spread = s.Ask - f.Bid;
                arb.ArbitrageDetails.Add(arbDetail);

                if (ArbitrageTimeStatistics.Instance(f.Symbol).StartArbitrageDateTime == DateTime.MinValue)
                    ArbitrageTimeStatistics.Instance(f.Symbol).StartArbitrageDateTime = DateTime.UtcNow;

                //CheckDoubleArbitrage(first.Tag, second.Tag);
			}
		}