public static int RoundDealVolume(int srcVolume, VolumeRoundType roundType, int minVolume, int volumeStep) { if (srcVolume < minVolume) { var хренТорганешь = true; if (roundType != VolumeRoundType.Вниз) { var minThreshold = roundType == VolumeRoundType.Ближайшее ? minVolume * 3 / 4 : minVolume / 2; if (srcVolume > minThreshold) { хренТорганешь = false; } } if (хренТорганешь) { return(0); } } var surVolume = srcVolume - minVolume; var stepsCount = surVolume / (double)volumeStep; var stepsInt = roundType == VolumeRoundType.Вниз ? (int)stepsCount : roundType == VolumeRoundType.Вверх ? (int)Math.Ceiling(stepsCount) : (int)Math.Round(stepsCount); surVolume = stepsInt * volumeStep; srcVolume = minVolume + surVolume; return(srcVolume); }
protected int CalculateVolumeInBaseCurrency(decimal volumeDepo, string tradeTicker, VolumeRoundType roundType, QuoteData quoteByTicker = null) { var volumeBase = volumeDepo; var depoCurx = robotContext.AccountInfo.Currency; var quotes = QuoteStorage.Instance.ReceiveAllData(); bool inverse, pairsEqual; var tickerTrans = DalSpot.Instance.FindSymbol(tradeTicker, true, depoCurx, out inverse, out pairsEqual); if (!pairsEqual) { QuoteData quote; if (tickerTrans == tradeTicker && quoteByTicker != null) { quote = quoteByTicker; } else { quotes.TryGetValue(tickerTrans, out quote); } if (quote == null) { var msgError = string.Format( "Невозможно рассчитать объем - отсутствует котировка \"{0}\"", tickerTrans); Logger.Info(msgError); return(0); } var priceTrans = inverse ? 1 / quote.bid : quote.ask; volumeBase /= (decimal)priceTrans; } return(MarketOrder.RoundDealVolume((int)volumeBase, roundType, RoundMinVolume, RoundVolumeStep)); }
protected int CalculateVolumeInBaseCurrency(decimal volumeDepo, string tradeTicker, VolumeRoundType roundType, QuoteData quoteByTicker = null) { var volumeBase = volumeDepo; var depoCurx = robotContext.AccountInfo.Currency; var quotes = QuoteStorage.Instance.ReceiveAllData(); bool inverse, pairsEqual; var tickerTrans = DalSpot.Instance.FindSymbol(tradeTicker, true, depoCurx, out inverse, out pairsEqual); if (!pairsEqual) { QuoteData quote; if (tickerTrans == tradeTicker && quoteByTicker != null) quote = quoteByTicker; else quotes.TryGetValue(tickerTrans, out quote); if (quote == null) { var msgError = string.Format( "Невозможно рассчитать объем - отсутствует котировка \"{0}\"", tickerTrans); Logger.Info(msgError); return 0; } var priceTrans = inverse ? 1 / quote.bid : quote.ask; volumeBase /= (decimal)priceTrans; } return MarketOrder.RoundDealVolume((int)volumeBase, roundType, RoundMinVolume, RoundVolumeStep); }
public static int RoundDealVolume(int srcVolume, VolumeRoundType roundType, int minVolume, int volumeStep) { if (srcVolume < minVolume) { var хренТорганешь = true; if (roundType != VolumeRoundType.Вниз) { var minThreshold = roundType == VolumeRoundType.Ближайшее ? minVolume * 3 / 4 : minVolume / 2; if (srcVolume > minThreshold) хренТорганешь = false; } if (хренТорганешь) return 0; } var surVolume = srcVolume - minVolume; var stepsCount = surVolume / (double)minVolume; var stepsInt = roundType == VolumeRoundType.Вниз ? (int)stepsCount : roundType == VolumeRoundType.Вверх ? (int)Math.Ceiling(stepsCount) : (int)Math.Round(stepsCount); surVolume = stepsInt * volumeStep; srcVolume = minVolume + surVolume; return srcVolume; }