示例#1
0
        public async Task <Unit> UpdateOrder(CryptoOrder cryptoOrder)
        {
            try
            {
                Console.WriteLine($"Closed order {cryptoOrder.Uuid} as {cryptoOrder.OrderType} at {cryptoOrder.Limit}");
                switch (cryptoOrder.OrderType)
                {
                case CryptoOrderType.LimitSell:
                    Budget.Available += cryptoOrder.Price;
                    var tradeForSellOrder = Trades.FirstOrDefault(t => t.SellOrder.Uuid == cryptoOrder.Uuid);
                    if (tradeForSellOrder != null)
                    {
                        if (cryptoOrder.Canceled)
                        {
                            tradeForSellOrder.Status             = TradeStatus.Bought;
                            tradeForSellOrder.SellOrder.IsOpened = false;
                            return(await Task.FromResult(Unit.Default));
                        }
                        var tradeProfit = tradeForSellOrder.BuyOrder.Price.GetReadablePercentageChange(tradeForSellOrder.SellOrder.Price);
                        Budget.Profit += tradeProfit;
                        Budget.Earned += tradeForSellOrder.SellOrder.Price - tradeForSellOrder.BuyOrder.Price;
                        Console.WriteLine($"{cryptoOrder.Uuid}: SELL - {tradeProfit}");
                        await _pushManager.TriggerPush(PushMessage.FromMessage($"Sold {Market} for profit {tradeProfit}%"));

                        tradeForSellOrder.Profit    = tradeProfit;
                        tradeForSellOrder.Status    = TradeStatus.Completed;
                        tradeForSellOrder.SellOrder = cryptoOrder;
                    }
                    break;

                case CryptoOrderType.LimitBuy:
                    var tradeForBuyOrder = Trades.FirstOrDefault(t => t.BuyOrder.Uuid == cryptoOrder.Uuid);
                    if (tradeForBuyOrder != null)
                    {
                        await _pushManager.TriggerPush(PushMessage.FromMessage($"Bought {Market} at {cryptoOrder.Limit} BTC"));

                        if (cryptoOrder.Canceled)
                        {
                            tradeForBuyOrder.Status   = TradeStatus.Empty;
                            tradeForBuyOrder.BuyOrder = new CryptoOrder();
                            return(await Task.FromResult(Unit.Default));
                        }
                        tradeForBuyOrder.Status   = TradeStatus.Bought;
                        tradeForBuyOrder.BuyOrder = cryptoOrder;
                    }
                    break;
                }
            }
            finally
            {
                if (!IsInTestMode)
                {
                    var traderData = await _traderGrain.GetTraderData();

                    traderData.CurrentTicker = Ticker;
                    await _hubNotifier.UpdateTrader(traderData);
                }
            }
            return(await Task.FromResult(Unit.Default));
        }
示例#2
0
        public async Task <Unit> UpdateOrder(CryptoOrder cryptoOrder)
        {
            if (!IsInTestMode)
            {
                var traderData = await _traderGrain.GetTraderData();

                traderData.CurrentTicker = Ticker;
                await _hubNotifier.UpdateTrader(traderData);
            }
            return(await Task.FromResult(Unit.Default));
        }
示例#3
0
        public async Task StartAsync()
        {
            Console.WriteLine($"Starting {Market}");
            Strategy     = new HoldUntilPriceDropsStrategy();
            _traderGrain = _orleansClient.GetGrain <ITraderGrain>(Market);
            await _traderGrain.SetMarketAsync(Market);

            TraderState = await _traderGrain.GetTraderData();

            TraderState.Trades = TraderState.Trades ?? new List <Trade>();

            Strategy.Settings     = TraderSettings.Default;
            _lastCandleUpdateTime = DateTime.UtcNow;
            var candlesResponse = await _cryptoApi.GetCandlesAsync(Market, TickInterval.OneHour);

            _coinTrader.Candles = candlesResponse.Content;
            Console.WriteLine($"Downloaded {candlesResponse.Content.Count} candles for {Market}");
            if (TraderState.Trades.Count == 0)
            {
                TraderState.Trades.Add(new Trade {
                    Status = TradeStatus.Empty
                });
            }

            _coinTrader.IsInTestMode = IsInTestMode;
            _coinTrader.Initialize(TraderState);
            CanUpdate = true;
            if (!IsInTestMode)
            {
                await UpdateOrders();
            }
        }
示例#4
0
        public async Task StartAsync()
        {
            _traderGrain = _orleansClient.GetGrain <ITraderGrain>(Market);
            await _traderGrain.UpdateTrades(new List <Trade>());

            await _traderGrain.SetMarketAsync(Market);

            var traderState = await _traderGrain.GetTraderData();

            Trades = traderState.Trades ?? new List <Trade>();

            Strategy.Settings = TraderSettings.Default;
            if (Trades.Count == 0)
            {
                Trades.Add(new Trade {
                    Status = TradeStatus.Empty
                });
            }
        }
示例#5
0
        public async Task StartAsync()
        {
            Strategy     = new HoldUntilPriceDropsStrategy();
            _traderGrain = _orleansClient.GetGrain <ITraderGrain>(Market);
            await _traderGrain.UpdateTrades(new List <Trade>());

            await _traderGrain.SetMarketAsync(Market);

            TraderState = await _traderGrain.GetTraderData();

            TraderState.Trades = TraderState.Trades ?? new List <Trade>();

            Strategy.Settings = TraderSettings.Default;
            if (TraderState.Trades.Count == 0)
            {
                TraderState.Trades.Add(new Trade {
                    Status = TradeStatus.Empty
                });
            }
            _cryptoBroker.Initialize(TraderState);
        }