protected virtual OpenPositionInfo OpenShortPosition(Ticker ticker, string mark, double value, double amount, bool allowTrailing, bool checkForMinValue, double trailingStopLossPc, double minProfitPc) { double spent = ticker.SpentInBaseCurrency(value, amount); if (1.05 * spent > GetMaxAllowedShortDeposit()) { return(null); } if (checkForMinValue && spent < MinDepositForOpenPosition) { return(null); } TradingResult res = MarketSell(ticker, value, amount); if (res == null) { return(null); } OpenPositionInfo info = new OpenPositionInfo() { Ticker = ticker, DataItemIndex = StrategyData.Count - 1, Time = DataProvider.CurrentTime, Type = OrderType.Sell, Spent = spent + CalcFee(res.Total), AllowTrailing = allowTrailing, StopLossPercent = trailingStopLossPc, OpenValue = res.Value, OpenAmount = res.Amount, Amount = res.Amount, Mark = mark, AllowHistory = (DataProvider is SimulationStrategyDataProvider), Total = res.Total, MinProfitPercent = minProfitPc, CloseValue = value * (1 + minProfitPc * 0.01), }; info.UpdateCurrentValue(DataProvider.CurrentTime, res.Value); OpenedOrders.Add(info); OrdersHistory.Add(info); OnOpenShortPosition(info); UpdateMaxAllowedShortDeposit(-info.Spent); IOpenedPositionsProvider provider = (IOpenedPositionsProvider)StrategyData.Last(); provider.OpenedPositions.Add(info); provider.AddMark(mark); Save(); return(info); }
protected virtual OpenPositionInfo OpenLongPosition(string mark, double value, double amount, bool allowTrailing, bool checkForMinValue, double trailingStopLossPc, double minProfitPc) { if (1.05 * value * amount > MaxAllowedDeposit) { return(null); } if (checkForMinValue && value * amount < MinDepositForOpenPosition) { return(null); } TradingResult res = MarketBuy(value, amount); if (res == null) { return(null); } OpenPositionInfo info = new OpenPositionInfo() { DataItemIndex = StrategyData.Count - 1, Time = DataProvider.CurrentTime, Type = OrderType.Buy, Spent = res.Total + CalcFee(res.Total), AllowTrailing = allowTrailing, StopLossPercent = trailingStopLossPc, OpenValue = res.Value, OpenAmount = res.Amount, Amount = res.Amount, Mark = mark, AllowHistory = (DataProvider is SimulationStrategyDataProvider), Total = res.Total, MinProfitPercent = minProfitPc, CloseValue = value * (1 + minProfitPc * 0.01), }; info.UpdateCurrentValue(DataProvider.CurrentTime, res.Value); OpenedOrders.Add(info); OrdersHistory.Add(info); OnOpenLongPosition(info); MaxAllowedDeposit -= info.Spent; IOpenedPositionsProvider provider = (CombinedStrategyDataItem)StrategyData.Last(); provider.OpenedPositions.Add(info); provider.AddMark(mark); Save(); return(info); }