Пример #1
0
        private void OrderCacheOnDetectOrder(object sender, OrderEventBacktest order)
        {
            if (order.EventType == OrderEventType.Buy)
            {
                Log.Information($"Buy order: {order}");

                _mtBus.GetBus().Publish <BuyCurrency>(new
                {
                    Id      = Guid.NewGuid(),
                    Created = DateTime.Now,
                    Amount  = 0,
                    Bid     = order.Price
                });
            }
            else if (order.EventType == OrderEventType.Sell)
            {
                Log.Information($"Sell order: {order}");

                _mtBus.GetBus().Publish <SellCurrency>(new
                {
                    Id      = Guid.NewGuid(),
                    Created = DateTime.Now,
                    Amount  = 0,
                    Ask     = order.Price
                });
            }
            else if (order.EventType == OrderEventType.Unknown)
            {
                Log.Information($"Unknown order: {order}");
            }
        }
Пример #2
0
        private List <BacktestOrderPair> ExtractOrders()
        {
            var htmlSource = Browser.GetSourceAsync().GetAwaiter().GetResult();
            var cq         = CQ.Create(htmlSource);

            var items      = cq.Find(".backtesting-content-wrapper").Find("tbody").ToList();
            var orderPairs = new List <BacktestOrderPair>();

            foreach (var tbody in items)
            {
                var orderPair = new BacktestOrderPair();

                var trs      = tbody.Cq().Find("tr").ToList();
                var firstTr  = trs.FirstOrDefault()?.ChildElements.Skip(2).ToList();
                var secondTr = trs.LastOrDefault()?.ChildElements.Skip(1).ToList();

                var ftype     = firstTr[0].TextContent;
                var fdateTime = firstTr[1].TextContent;
                var fprice    = firstTr[2].TextContent;

                orderPair.Left = OrderEventBacktest.Parse(ftype, fdateTime, fprice);

                if (!string.IsNullOrWhiteSpace(secondTr[1].TextContent))
                {
                    var stype     = secondTr[0].TextContent;
                    var sdateTime = secondTr[1].TextContent;
                    var sprice    = secondTr[2].TextContent;

                    orderPair.Right = OrderEventBacktest.Parse(stype, sdateTime, sprice);
                }
                else
                {
                    orderPair.Right = null;
                }

                orderPairs.Add(orderPair);
            }

            orderPairs.RemoveAt(orderPairs.Count - 1);

            return(orderPairs);
        }