Ejemplo n.º 1
0
        public async Task CloseOrder(bool closeAnyFpl)
        {
            var subscription = _realmProxy.Services.GetSubject <NotifyResponse>($"user.updates.{_notificationId}")
                               .Subscribe(info =>
            {
                if (info.Order != null)
                {
                    Console.WriteLine($"Order pnl: {info.Order.Fpl}");
                }
            });

            while (true)
            {
                var orders = await _service.GetOpenPositions(_token);

                if (orders.Demo.Any(item => item.Fpl > 0) || closeAnyFpl)
                {
                    var order = orders.Demo.First();

                    var request = new CloseOrderRpcClientRequest
                    {
                        OrderId   = order.Id,
                        AccountId = order.AccountId,
                        Token     = _token
                    };

                    var result = await _service.CloseOrder(request.ToJson());

                    break;
                }

                Thread.Sleep(200);
            }

            Console.WriteLine("Press enter");
            Console.ReadLine();
            subscription.Dispose();
        }
Ejemplo n.º 2
0
        public async Task <OperationResult> GetOpenPositionsFromDemo()
        {
            var res = new OperationResult
            {
                Operation = "GetOpenPositions",
                StartDate = DateTime.UtcNow
            };

            var result = await _service.GetOpenPositions(_token);

            res.EndDate = DateTime.UtcNow;
            res.Result  = result.Demo;
            LogInfo($";{res.Duration};GetOpenPositionsFromDemo: Items={result.Demo.Length}");
            return(res);
        }