protected void OnData(ITransactionMessage <IPointModel> message) { var point = message.Next; var account = point.Account; var instrument = point.Account.Instruments[_asset]; var points = instrument.PointGroups; var volumes = _imbalanceIndicator.Calculate(points).Values; var performanceIndicator = _performanceIndicator.Calculate(points, Gateways.Select(o => o.Account)); if (points.Count > 1 && IsNextPoint(point)) { var currentPoint = points.ElementAt(points.Count - 1); var previousPoint = points.ElementAt(points.Count - 2); var currentVolume = volumes.ElementAt(volumes.Count - 1).Last; var previousVolume = volumes.ElementAt(volumes.Count - 2).Last; var isLong = currentVolume > 0 && previousVolume > 0 && previousPoint.Bar.Close > previousPoint.Bar.Open; var isShort = currentVolume < 0 && previousVolume < 0 && previousPoint.Bar.Close < previousPoint.Bar.Open; //CreateOrder(point, OrderSideEnum.Buy, 1); if (account.ActiveOrders.Count == 0 && account.ActivePositions.Count == 0) { if (isLong) { CreateOrder(point, OrderSideEnum.Buy, 1); } if (isShort) { CreateOrder(point, OrderSideEnum.Sell, 1); } } if (account.ActivePositions.Count > 0) { var activePosition = account.ActivePositions.Last(); switch (activePosition.Side) { case OrderSideEnum.Buy: if (isShort) { CreateOrder(point, OrderSideEnum.Sell, activePosition.Size.Value + 1); } break; case OrderSideEnum.Sell: if (isLong) { CreateOrder(point, OrderSideEnum.Buy, activePosition.Size.Value + 1); } break; } } } }
private byte[] Sign(ITransactionMessage msg) { SignData signData = new SignData(); signData.ChainId = Wallet.ChainId; signData.AccountNumber = Wallet.AccountNumber.ToString(); signData.Sequence = Wallet.Sequence.ToString(); signData.Msgs = new ITransactionMessage[] { msg }; signData.Memo = TranscationOption.Memo; signData.Source = TranscationOption.Source.ToString(); signData.Data = TranscationOption.Data; return(Signature.Sign(signData, Wallet.EcKey)); }
protected void OnData(ITransactionMessage <IPointModel> message) { var point = message.Next; var account = point.Account; var gateway = account.Gateway; var instrument = point.Account.Instruments[_asset]; var series = instrument.PointGroups; var bidIndicator = _bidIndicator.Calculate(series); var askIndicator = _askIndicator.Calculate(series); var rsiIndicator = _rsiIndicator.Calculate(series); var atrIndicator = _atrIndicator.Calculate(series); var performanceIndicator = _performanceIndicator.Calculate(series, Gateways.Select(o => o.Account)); if (series.Any()) { var rsiValues = rsiIndicator.Values; var noOrders = account.ActiveOrders.Any() == false; var noPositions = account.ActivePositions.Any() == false; if (noOrders && noPositions && rsiValues.Count > 1) { var rsiCurrent = rsiValues.ElementAt(rsiValues.Count - 1).Bar.Close; var rsiPrevious = rsiValues.ElementAt(rsiValues.Count - 2).Bar.Close; if (rsiPrevious < 30 && rsiCurrent > 30) { CreateOrder(point, OrderSideEnum.Buy, 100); } if (rsiPrevious > 70 && rsiCurrent < 70) { CreateOrder(point, OrderSideEnum.Sell, 100); } } if (noPositions == false) { var activePosition = account.ActivePositions.Last(); var rsiCurrent = rsiValues.ElementAt(rsiValues.Count - 1).Bar.Close; var rsiPrevious = rsiValues.ElementAt(rsiValues.Count - 2).Bar.Close; if (Equals(activePosition.Type, OrderSideEnum.Buy) && rsiPrevious > 70 && rsiCurrent < 70) { CreateOrder(point, OrderSideEnum.Sell, 200); } if (Equals(activePosition.Type, OrderSideEnum.Sell) && rsiPrevious < 30 && rsiCurrent > 30) { CreateOrder(point, OrderSideEnum.Buy, 200); } } } }
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) { } } }