public NewPositionInfo ProcessMarketPosition(CurrencyPair currencyPair) { NewPositionInfo newPositionInfo; var conditionCheckingResult = CheckConditions(currencyPair); switch (conditionCheckingResult.ResultType) { case ConditionCheckingResultType.Passed: var buyPositionInfo = new NewOrderPositionInfo(NewMarketPositionType.Buy); buyPositionInfo.CurrencyPairId = currencyPair.Id; buyPositionInfo.OpenPrice = OrderBookLoadingService.GetTopMeaningfulBidPrice(currencyPair); buyPositionInfo.OpenStopPrice = OrderBookLoadingService.GetBottomAskPrice(currencyPair, 1); buyPositionInfo.ClosePrice = buyPositionInfo.CloseStopPrice = buyPositionInfo.OpenStopPrice; buyPositionInfo.StopLossPrice = buyPositionInfo.OpenPrice - currencyPair.TickSize * 2000; newPositionInfo = buyPositionInfo; break; default: newPositionInfo = new WaitPositionInfo(); break; } return(newPositionInfo); }
public OpenPositionAnalysisService(CandleLoadingService candleLoadingService, OrderBookLoadingService orderBookLoadingService, IIndicatorComputingService indicatorComputingService, ConfigurationService configurationService) { _candleLoadingService = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService)); _orderBookLoadingService = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService)); _indicatorComputingService = indicatorComputingService ?? throw new ArgumentNullException(nameof(indicatorComputingService)); _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); }
public TripleFrameRSIStrategyAnalysisService(CandleLoadingService candleLoadingService, OrderBookLoadingService orderBookLoadingService, IIndicatorComputingService indicatorComputingService, ConfigurationService configurationService) { CandleLoadingService = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService)); OrderBookLoadingService = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService)); IndicatorComputingService = indicatorComputingService ?? throw new ArgumentNullException(nameof(indicatorComputingService)); ConfigurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); }
public OrdersService(OrderBookLoadingService orderBookLoadingService, IStockRestConnector stockRestConnector, IStockSocketConnector stockSocketConnector, ConfigurationService configurationService) { _orderBookLoadingService = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService)); _stockRestConnector = stockRestConnector ?? throw new ArgumentNullException(nameof(stockRestConnector)); _stockSocketConnector = stockSocketConnector ?? throw new ArgumentNullException(nameof(stockSocketConnector)); _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); }
public static decimal GetTopBidPrice(this OrderBookLoadingService orderBookLoadingService, CurrencyPair currencyPair, int skip = 0) { var orderBookBidItems = orderBookLoadingService.GetOrderBook(currencyPair.Id, OrderBookItemType.Bid, 5).ToList(); if (!orderBookBidItems.Any()) { throw new NoNullAllowedException("Couldn't load order book"); } return(orderBookBidItems .OrderByDescending(item => item.Price) .Skip(skip) .Select(item => item.Price) .First()); }
public TradingPositionWorker(CandleLoadingService candleLoadingService, OrderBookLoadingService orderBookLoadingService, TradingReportsService tradingReportsService, IMarketPendingPositionAnalysisService marketPendingPositionAnalysisService, IMarketOpenPositionAnalysisService marketOpenPositionAnalysisService, ITradingPositionService tradingPositionService, ConfigurationService configurationService) { _candleLoadingService = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService)); _orderBookLoadingService = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService)); _tradingReportsService = tradingReportsService ?? throw new ArgumentNullException(nameof(tradingReportsService)); _marketPendingPositionAnalysisService = marketPendingPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketPendingPositionAnalysisService)); _marketOpenPositionAnalysisService = marketOpenPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketOpenPositionAnalysisService)); _tradingPositionService = tradingPositionService ?? throw new ArgumentNullException(nameof(tradingPositionService)); _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); }
public static decimal GetBottomAskPrice(this OrderBookLoadingService orderBookLoadingService, CurrencyPair currencyPair, int skip = 0) { var orderBookAskItems = orderBookLoadingService.GetOrderBook(currencyPair.Id, OrderBookItemType.Ask, 5).ToList(); if (!orderBookAskItems.Any()) { return(0); } var bottomMeaningfulAskPrice = orderBookAskItems .OrderBy(item => item.Price) .Skip(skip) .Select(item => item.Price) .First(); return(bottomMeaningfulAskPrice); }
public static decimal GetBottomMeaningfulAskPrice(this OrderBookLoadingService orderBookLoadingService, CurrencyPair currencyPair) { var orderBookAskItems = orderBookLoadingService.GetOrderBook(currencyPair.Id, OrderBookItemType.Ask, 5).ToList(); if (!orderBookAskItems.Any()) { throw new NoNullAllowedException("Couldn't load order book"); } var maxAskSize = orderBookAskItems .Max(item => item.Size); var bottomMeaningfulAskPrice = orderBookAskItems .Where(item => item.Size == maxAskSize) .OrderBy(item => item.Price) .Select(item => item.Price) .First(); return(bottomMeaningfulAskPrice); }
public static decimal GetTopMeaningfulBidPrice(this OrderBookLoadingService orderBookLoadingService, CurrencyPair currencyPair) { var orderBookBidItems = orderBookLoadingService.GetOrderBook(currencyPair.Id, OrderBookItemType.Bid, 5).ToList(); if (!orderBookBidItems.Any()) { return(0); } var maxBidSize = orderBookBidItems .Max(item => item.Size); var topMeaningfulBidPrice = orderBookBidItems .Where(item => item.Size == maxBidSize) .OrderByDescending(item => item.Price) .Select(item => item.Price) .First(); return(topMeaningfulBidPrice); }
public static decimal GetNearestAskSupportPrice(this OrderBookLoadingService orderBookLoadingService, CurrencyPair currencyPair) { var orderBookAskItems = orderBookLoadingService.GetOrderBook(currencyPair.Id, OrderBookItemType.Ask, 20).ToList(); if (!orderBookAskItems.Any()) { throw new NoNullAllowedException("Couldn't load order book"); } var avgAskSize = orderBookAskItems .Average(item => item.Size); var bottomAskPrice = orderBookAskItems .OrderBy(item => item.Price) .Select(item => item.Price) .First(); return(orderBookAskItems .Where(item => item.Size > avgAskSize && item.Price >= bottomAskPrice) .OrderBy(item => item.Price) .Select(item => item.Price) .First()); }