コード例 #1
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var result  = false;
            var message = string.Empty;

            if (solbot.Communication.Buy.IsReady)
            {
                var funds = solbot.Communication.Buy.AvailableFund;

                var buyOrderResult = _kucoinClient.PlaceOrder(
                    solbot.Strategy.AvailableStrategy.Symbol,
                    Kucoin.Net.Objects.KucoinOrderSide.Buy,
                    Kucoin.Net.Objects.KucoinNewOrderType.Market,
                    funds: funds);

                if (!(buyOrderResult is null))
                {
                    result = buyOrderResult.Success;

                    if (buyOrderResult.Success)
                    {
                        var order = _kucoinClient.GetOrder(buyOrderResult.Data.OrderId);

                        if (!(order is null))
                        {
                            if (order.Success)
                            {
                                Logger.Info(LogGenerator.TradeResultStart(order.Data.ClientOrderId));

                                if (order.Data.DealQuantity != 0)
                                {
                                    var price = (order.Data.Funds / order.Data.DealQuantity).ToKucoinRound();
                                    Logger.Info(LogGenerator.TradeResultKucoin(MarketOrder, order.Data, price));

                                    solbot.Actions.BoughtPrice = price;
                                }

                                Logger.Info(LogGenerator.TradeResultEndKucoin(order.Data.ClientOrderId));
                            }
                            else
                            {
                                Logger.Warn(order.Error.Message);
                            }
                        }

                        _pushOverNotificationService.Send(
                            LogGenerator.NotificationTitle(EnvironmentType.PRODUCTION, MarketOrder, solbot.Strategy.AvailableStrategy.Symbol),
                            LogGenerator.NotificationMessage(
                                solbot.Communication.Average.Current,
                                solbot.Communication.Price.Current,
                                solbot.Communication.Buy.Change));
                    }
                    else
                    {
                        Logger.Warn(buyOrderResult.Error.Message);
                    }
                }
                else
                {
                    Logger.Warn(buyOrderResult.Error.Message);
                }
            }
コード例 #2
0
        public IRuleResult RuleExecuted(Solbot solbot)
        {
            var result  = false;
            var message = string.Empty;

            if (solbot.Communication.Sell.IsReady)
            {
                var quantity = BinanceHelpers.ClampQuantity(solbot.Communication.Symbol.MinQuantity, solbot.Communication.Symbol.MaxQuantity, solbot.Communication.Symbol.BasePrecision, solbot.Communication.AvailableAsset.Base);

                var sellOrderResult = _kucoinClient.PlaceOrder(
                    solbot.Strategy.AvailableStrategy.Symbol,
                    Kucoin.Net.Objects.KucoinOrderSide.Sell,
                    Kucoin.Net.Objects.KucoinNewOrderType.Market,
                    quantity: quantity);

                if (!(sellOrderResult is null))
                {
                    result = sellOrderResult.Success;

                    if (sellOrderResult.Success)
                    {
                        Logger.Info(LogGenerator.TradeResultStart(sellOrderResult.Data.OrderId));

                        var order = _kucoinClient.GetOrder(sellOrderResult.Data.OrderId);

                        if (!(order is null))
                        {
                            if (order.Success)
                            {
                                Logger.Info(LogGenerator.TradeResultStart(order.Data.ClientOrderId));

                                if (order.Data.DealQuantity != 0)
                                {
                                    var price = (order.Data.Funds / order.Data.DealQuantity).ToKucoinRound();
                                    Logger.Info(LogGenerator.TradeResultKucoin(MarketOrder, order.Data, price));

                                    solbot.Actions.BoughtPrice = price;
                                }

                                Logger.Info(LogGenerator.TradeResultEndKucoin(order.Data.ClientOrderId));
                            }
                            else
                            {
                                Logger.Warn(order.Error.Message);
                            }
                        }

                        solbot.Actions.BoughtPrice = 0;

                        Logger.Info(LogGenerator.TradeResultEndKucoin(sellOrderResult.Data.OrderId));

                        _pushOverNotificationService.Send(
                            LogGenerator.NotificationTitle(EnvironmentType.PRODUCTION, MarketOrder, solbot.Strategy.AvailableStrategy.Symbol),
                            LogGenerator.NotificationMessage(
                                solbot.Communication.Average.Current,
                                solbot.Communication.Price.Current,
                                solbot.Communication.Sell.Change));
                    }
                    else
                    {
                        Logger.Warn(sellOrderResult.Error.Message);
                    }
                }
                else
                {
                    Logger.Warn(sellOrderResult.Error.Message);
                }
            }