Пример #1
0
        protected void OnData(ITransactionMessage <IPointModel> message)
        {
            var point       = message.Next;
            var account     = point.Account;
            var gateway     = Gateways.First();
            var instrumentX = point.Account.Instruments[_assetX];
            var instrumentY = point.Account.Instruments[_assetY];
            var seriesX     = instrumentX.PointGroups;
            var seriesY     = instrumentY.PointGroups;
            var indicatorX  = _scaleIndicatorX.Calculate(seriesX).Bar.Close;
            var indicatorY  = _scaleIndicatorY.Calculate(seriesY).Bar.Close;

            //var balanceIndicator = _balanceIndicator.Calculate(Gateways.Select(o => o.Account), point).Close;

            if (seriesX.Any() && seriesY.Any())
            {
                if (account.ActiveOrders.Any() == false &&
                    account.ActivePositions.Any() == false &&
                    Math.Abs(indicatorX.Value - indicatorY.Value) >= 0.5)
                {
                    if (indicatorX > indicatorY)
                    {
                        gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
                        {
                            Action = ActionEnum.Create,
                            Next   = new TransactionOrderModel
                            {
                                Size       = 1,
                                Side       = OrderSideEnum.Sell,
                                Type       = OrderTypeEnum.Market,
                                Instrument = instrumentX
                            }
                        });

                        gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
                        {
                            Action = ActionEnum.Create,
                            Next   = new TransactionOrderModel
                            {
                                Size       = 1,
                                Side       = OrderSideEnum.Buy,
                                Type       = OrderTypeEnum.Market,
                                Instrument = instrumentX
                            }
                        });
                    }

                    if (indicatorX < indicatorY)
                    {
                        gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
                        {
                            Action = ActionEnum.Create,
                            Next   = new TransactionOrderModel
                            {
                                Size       = 1,
                                Side       = OrderSideEnum.Buy,
                                Type       = OrderTypeEnum.Market,
                                Instrument = instrumentX
                            }
                        });

                        gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
                        {
                            Action = ActionEnum.Create,
                            Next   = new TransactionOrderModel
                            {
                                Size       = 1,
                                Side       = OrderSideEnum.Sell,
                                Type       = OrderTypeEnum.Market,
                                Instrument = instrumentY
                            }
                        });
                    }
                }

                if (account.ActivePositions.Any() && Math.Abs(indicatorX.Value - indicatorY.Value) < 0.05)
                {
                }
            }
        }