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); }
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); } }