コード例 #1
0
        public async Task HandleTrade(string orderId, decimal tradeSize)
        {
            await _semaphoreSlim.WaitAsync();

            try
            {
                var level = GetLevelbyOrder(orderId);

                if (level == null)
                {
                    Console.WriteLine($"ERROR: Cannot found level by orderId: {orderId}");
                    return;
                }

                //level.CompensateSize += tradeSize;

                var isOrderOpen = await _trader.CheckOrderIsOpenedAsync(orderId, _symbol);

                if (isOrderOpen)
                {
                    return;
                }

                Console.WriteLine($"execute level. Price: {level.PriceBuy}, Side: {level.Side}, Id: {level.CurrentOrderId}");

                _levelsByOrder.Remove(orderId);

                level.Revert();
            }
            finally
            {
                _semaphoreSlim.Release();
            }
        }
コード例 #2
0
        public async Task HandleTrade(string orderId)
        {
            var isOrderOpen = await _trader.CheckOrderIsOpenedAsync(orderId, _symbol);

            if (isOrderOpen)
            {
                return;
            }

            if (!_levelsByOrder.TryGetValue(orderId, out var level))
            {
                Console.WriteLine($"ERROR: Cannot found level by orderId: {orderId}");
                return;
            }

            Console.WriteLine($"execute level. Side: {level.Side}, Type: {level.Type}, Id: {level.CurrentOrderId}");

            _levelsByOrder.Remove(orderId);

            level.CurrentOrderId = string.Empty;
            level.Status         = MarketLevelStatus.Empty;
            level.Type           = level.Type == MarketLevelType.Direct ? MarketLevelType.Compensate : MarketLevelType.Direct;
        }