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); }
internal void CheckDoubleArbitrage(int ArbBidTag, int ArbAskTag) { int counter = 0; Arbitrage a1 = null, a2 = null; foreach (var item in dictSPairs) { if (item.Value.m_firstBidSecondAskArbitrage != null && item.Value.m_firstBidSecondAskArbitrage.BankBidGAsk == ArbBidTag) { //continue if itself if (ArbAskTag == item.Value.m_firstBidSecondAskArbitrage.BankAskLBid) { a1 = item.Value.m_firstBidSecondAskArbitrage; continue; } counter++; a2 = item.Value.m_firstBidSecondAskArbitrage; } } if (counter == 1 && a1 != null && a2 != null) { //run trade for DoubleArbitrage1B2A da = new DoubleArbitrage1B2A(); da.Symbol = m_symbol; da.FirstArbitrage = a1; da.SecondArbitrage = a2; TradeDoubleArbitrage.Instance.TradeBegin(da); } counter = 0; a1 = null; a2 = null; foreach (var item in dictSPairs) { if (item.Value.m_firstBidSecondAskArbitrage != null && item.Value.m_firstBidSecondAskArbitrage.BankAskLBid == ArbAskTag) { //continue if itself if (ArbBidTag == item.Value.m_firstBidSecondAskArbitrage.BankBidGAsk) { a1 = item.Value.m_firstBidSecondAskArbitrage; continue; } counter++; a2 = item.Value.m_firstBidSecondAskArbitrage; } } if (counter == 1 && a1 != null && a2 != null) { //run trade for DoubleArbitrage2B1A da = new DoubleArbitrage2B1A(); da.Symbol = m_symbol; da.FirstArbitrage = a1; da.SecondArbitrage = a2; TradeDoubleArbitrage.Instance.TradeBegin(da); } }