public override int GetHashCode() { int hash = 1; if (Countdown != 0) { hash ^= Countdown.GetHashCode(); } if (LastTick != false) { hash ^= LastTick.GetHashCode(); } hash ^= changes_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void SetQuote(Quote quote, ILogger logger = null) { if (quote.IsValidQuote()) { if (!LastTick.QuoteEqual(quote)) { bool filtered = false; // фильтр расширения спреда по сигмам. Сравнивается исходный спред if (SigmaSpread != 0) { if (LastTicks.Size != NumberLastTicks) { LastTicks.Size = NumberLastTicks; } if (LastTicks.Count >= NumberLastTicks) { var s = LastTicks.Sigma(quote, q => (q.Ask - q.Bid)); if (s > SigmaSpread) { logger?.LogWarning("SigmaSpread. source quote: {0} was filtered out because sigma ({1} > {2})", quote, s, SigmaSpread); var standartDeviation = LastTicks.StandardDeviationAndAverage(q => q.Ask - q.Bid); logger?.LogWarning("SigmaSpread. Current Spread: {0:f5} ; Standart Deviation {1:f5} ; Average {2:f5} ; Sigma {3} ; Sigma in options {4}", quote.Ask - quote.Bid, standartDeviation.Item1, standartDeviation.Item2, s, SigmaSpread); logger?.ToLogQuotes(LogLevel.Warning, LastTicks, Digits); filtered = true; } } } // фильтр шага по сигмам. Сравнивается исходный спред if (SigmaStep != 0) { if (LastSteps.Size != NumberLastSteps) { LastSteps.Size = NumberLastSteps; } if (LastSteps.Count >= NumberLastSteps) { var askStep = Math.Abs(quote.Ask - LastTick.Ask); var bidStep = Math.Abs(quote.Bid - LastTick.Bid); var keyValue = new KeyValuePair <double, double>(askStep, bidStep); var askSigma = LastSteps.Sigma(keyValue, q => q.Key); // Ask Sigma var bidSigma = LastSteps.Sigma(keyValue, q => q.Value); // Bid Sigma var askStandartDeviation = LastSteps.StandardDeviationAndAverage(q => q.Key); var bidStandartDeviation = LastSteps.StandardDeviationAndAverage(q => q.Value); if (askSigma > SigmaStep && askStep > askStandartDeviation.Item2 && askStep != 0) { logger?.LogWarning("SigmaStepAsk. source quote: {0} was filtered out because sigma ({1} > {2})", quote, askSigma, SigmaStep); logger?.LogWarning("SigmaStepAsk. Current Step: {0:f5} ; Standart Deviation {1:f5} ; Average {2:f5} ; Sigma {3} ; Sigma in options {4}", askStep, askStandartDeviation.Item1, askStandartDeviation.Item2, askSigma, SigmaStep); logger?.ToLogSteps(LogLevel.Warning, LastSteps, Digits); filtered = true; } if (bidSigma > SigmaStep && bidStep > bidStandartDeviation.Item2 && bidStep != 0) { logger?.LogWarning("SigmaStepBid. source quote: {0} was filtered out because sigma ({1} > {2})", quote, bidSigma, SigmaStep); logger?.LogWarning("SigmaStepBid. Current Step: {0:f5} ; Standart Deviation {1:f5} ; Average {2:f5} ; Sigma {3} ; Sigma in options {4}", bidStep, bidStandartDeviation.Item1, bidStandartDeviation.Item2, bidSigma, SigmaStep); logger?.ToLogSteps(LogLevel.Warning, LastSteps, Digits); filtered = true; } } } // если котировка не отфильтрована, то делаю модификацию этой котировки if (!filtered) { double last_bid = quote.Bid; double last_ask = quote.Ask; double point = Math.Pow(10, -Digits); double contract = Math.Pow(10, Digits); if (BidMarkup != 0) { last_bid += point * BidMarkup; } if (AskMarkup != 0) { last_ask += point * AskMarkup; } if (Percent != 0) { double pointModify = (last_ask - last_bid) * Percent / 100 / 2; last_bid -= pointModify; last_ask += pointModify; } if (Min != -1) { double spread = (last_ask - last_bid) * contract; if (spread < Min) { double last_mid = (last_ask + last_bid) / 2; last_bid = last_mid - (Min * point / 2); last_ask = last_mid + (Min * point / 2); } } if (Max != -1) { double spread = (last_ask - last_bid) * contract; if (spread > Max) { logger?.LogWarning("Max. source quote ({0}) => ({1:f5} {2:f5} {3:f0}) but maximum in option {4}", quote, last_ask, last_bid, spread, Max); double last_mid = (last_ask + last_bid) / 2; last_bid = last_mid - (Max * point / 2); last_ask = last_mid + (Max * point / 2); } } if (Fix != -1) { double last_mid = (last_bid + last_ask) / 2; last_bid = last_mid - (Fix * point / 2); last_ask = last_mid + (Fix * point / 2); } last_bid = Math.Round(last_bid, Digits, MidpointRounding.ToEven); last_ask = Math.Round(last_ask, Digits, MidpointRounding.ToEven); if (last_ask != LastAsk || last_bid != LastBid) { LastBid = last_bid; LastAsk = last_ask; Change = true; } } } if (SigmaStep != 0 && (LastTick.Ask != 0 && LastTick.Bid != 0) && (quote.Ask != LastTick.Ask && quote.Bid != LastTick.Bid)) { LastSteps.Enqueue(new KeyValuePair <double, double>(Math.Abs(quote.Ask - LastTick.Ask), Math.Abs(quote.Bid - LastTick.Bid))); } LastTick = quote; if (SigmaSpread != 0) { LastTicks.Enqueue(quote); } } }
internal void ChangeStateIn(int timeInSeconds) { TimeToChangeState = LastTick.AddSeconds(timeInSeconds); }
internal void ResumeStateIn(int timeInSeconds) { TimeToResumeState = LastTick.AddSeconds(timeInSeconds); }
internal void ShowFruit(int showForSeconds, FruitType fruitToShow) { _fruitVisibleUntil = LastTick.AddSeconds(showForSeconds); FruitTypeToShow = fruitToShow; }