Beispiel #1
0
        public async Task CreateNewPosition(NewOrderPositionInfo positionInfo)
        {
            Position = await _tradingPositionService.OpenPosition(positionInfo);

            Position = await _tradingPositionService.UpdatePosition(null, Position, true, OnPositionChanged);
            await SubscribeOnTradingEvents();
        }
        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 static TradingPosition CreatePosition(NewOrderPositionInfo positionInfo, CurrencyPair currencyPair, TradingSettings tradingSettings)
        {
            var now            = DateTime.UtcNow;
            var parentClientId = Guid.NewGuid();

            var position = new TradingPosition
            {
                OpenPositionOrder = new Order
                {
                    ClientId       = parentClientId,
                    CurrencyPair   = currencyPair,
                    Role           = OrderRoleType.OpenPosition,
                    OrderSide      = tradingSettings.BaseOrderSide,
                    OrderType      = OrderType.StopLimit,
                    OrderStateType = OrderStateType.Suspended,
                    TimeInForce    = OrderTimeInForceType.GoodTillCancelled,
                    Price          = positionInfo.OpenPrice,
                    StopPrice      = positionInfo.OpenStopPrice,
                    Created        = now,
                    Updated        = now
                },

                ClosePositionOrder = new Order
                {
                    ClientId       = Guid.NewGuid(),
                    ParentClientId = parentClientId,
                    CurrencyPair   = currencyPair,
                    Role           = OrderRoleType.ClosePosition,
                    OrderSide      = tradingSettings.OppositeOrderSide,
                    OrderType      = OrderType.StopLimit,
                    OrderStateType = OrderStateType.Pending,
                    TimeInForce    = OrderTimeInForceType.GoodTillCancelled,
                    Price          = positionInfo.ClosePrice,
                    StopPrice      = positionInfo.CloseStopPrice,
                    Created        = now,
                    Updated        = now
                },

                StopLossOrder = new Order
                {
                    ClientId       = Guid.NewGuid(),
                    ParentClientId = parentClientId,
                    CurrencyPair   = currencyPair,
                    Role           = OrderRoleType.StopLoss,
                    OrderSide      = tradingSettings.OppositeOrderSide,
                    OrderType      = OrderType.StopMarket,
                    OrderStateType = OrderStateType.Pending,
                    TimeInForce    = OrderTimeInForceType.GoodTillCancelled,
                    Price          = 0,
                    StopPrice      = positionInfo.StopLossPrice,
                    Created        = now,
                    Updated        = now
                }
            };

            return(position);
        }
Beispiel #4
0
        public async Task <TradingPosition> OpenPosition(NewOrderPositionInfo positionInfo)
        {
            var tradingSettings = _configurationService.GetTradingSettings();
            var currencyPair    = await _stockRestConnector.GetCurrencyPair(positionInfo.CurrencyPairId);

            var position = TradingPositionHelper.CreatePosition(positionInfo, currencyPair, tradingSettings);

            return(position);
        }