Exemplo n.º 1
0
        public void TradeBegin(DoubleArbitrage1B2A item)
        {
            Task.Factory.StartNew(() =>
            {
                string key = GetKey(item.FirstArbitrage.BankBidGAsk, item.FirstArbitrage.Symbol, false);
                lock (syncObj)
                {
                    if (listLockedQuotes.Contains(key))
                    {
                        return;
                    }
                    listLockedQuotes.Add(key);
                }

                try
                {
                    System.Threading.Thread.Sleep(1000);
                    if (item.FirstArbitrage.IsFinished || item.SecondArbitrage.IsFinished)
                    {
                        return;
                    }

                    //item.ExpectedBid = item.FirstArbitrage.ArbitrageDetails.Last().B1Bid1;
                    //item.ExecutedAsk = item.FirstArbitrage.ArbitrageDetails.Last().B1Bid1;
                    //item.ExecutedBid = Math.Max(item.ExecutedBid, item.SecondArbitrage.ArbitrageDetails.Last().B1Bid1);


                    item.TradeDate = DateTime.UtcNow;

                    using (Model.ArbitrageContext arbContext = new Model.ArbitrageContext())
                    {
                        arbContext.DoubleArbitrage1B2A.Add(item);
                        arbContext.SaveChanges();
                    }
                }
                finally
                {
                    lock (syncObj)
                    {
                        listLockedQuotes.Remove(key);
                    }
                }
            }
                                  , TaskCreationOptions.LongRunning);
        }
Exemplo n.º 2
0
        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");
            }
        }
Exemplo n.º 3
0
Arquivo: Program.cs Projeto: 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");
            }

        }
Exemplo n.º 4
0
        public void TradeBegin(DoubleArbitrage2B1A item)
        {
            Task.Factory.StartNew(() =>
                {
                    string key = GetKey(item.FirstArbitrage.BankAskLBid, item.FirstArbitrage.Symbol, false);
                    lock (syncObj)
                    {
                        if (listLockedQuotes.Contains(key))
                            return;
                        listLockedQuotes.Add(key);
                    }

                    try
                    {
                        System.Threading.Thread.Sleep(1000);
                        if (item.FirstArbitrage.IsFinished || item.SecondArbitrage.IsFinished)
                            return;

                        item.ExpectedAsk = item.FirstArbitrage.ArbitrageDetails.Last().B2Ask1;
                        item.ExecutedBid = item.FirstArbitrage.ArbitrageDetails.Last().B1Bid1;
                        item.ExecutedBid = Math.Max(item.ExecutedBid, item.SecondArbitrage.ArbitrageDetails.Last().B1Bid1);


                        item.TradeDate = DateTime.UtcNow;

                        using (Model.ArbitrageContext arbContext = new Model.ArbitrageContext())
                        {
                            arbContext.DoubleArbitrage2B1A.Add(item);
                            arbContext.SaveChanges();
                        }
                    }
                    finally
                    {
                        lock (syncObj)
                        {
                            listLockedQuotes.Remove(key);
                        }
                    }

                }
            , TaskCreationOptions.LongRunning);
        }