コード例 #1
0
        public async Task <(string, string)> GetAssetIdsAsync(string assetPair)
        {
            if (_pairsDict.ContainsKey(assetPair))
            {
                return(_pairsDict[assetPair].BaseAssetId, _pairsDict[assetPair].QuotingAssetId);
            }

            var pair = await _assetsService.AssetPairGetAsync(assetPair);

            if (pair == null)
            {
                throw new UnknownPairException($"Unknown assetPair {assetPair}!");
            }

            _pairsDict.TryAdd(pair.Id, pair);

            return(pair.BaseAssetId, pair.QuotingAssetId);
        }
コード例 #2
0
        private async Task ProcessTrade(TradeQueueItem message)
        {
            if (!message.Order.Status.Equals("matched", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var pair = await _assetsService.AssetPairGetAsync(message.Order.AssetPairId);

            if (pair == null)
            {
                throw new ArgumentNullException(nameof(pair));
            }

            bool isLimitAssetBase = message.Trades.First().LimitAsset == pair.BaseAssetId;

            var limitAsset = await _assetsService.AssetGetAsync(message.Trades.First().LimitAsset);

            if (limitAsset == null)
            {
                throw new ArgumentNullException(nameof(limitAsset));
            }

            var marketAsset = await _assetsService.AssetGetAsync(message.Trades.First().MarketAsset);

            if (marketAsset == null)
            {
                throw new ArgumentNullException(nameof(marketAsset));
            }

            foreach (var trade in message.Trades)
            {
                await _tradesCommonRepository.InsertCommonTrade(new TradeCommon
                {
                    Amount        = isLimitAssetBase ? trade.LimitVolume : trade.MarketVolume,
                    AssetPair     = message.Order.AssetPairId,
                    BaseAsset     = isLimitAssetBase ? limitAsset.DisplayId : marketAsset.DisplayId,
                    BaseAssetId   = isLimitAssetBase ? trade.LimitAsset : trade.MarketAsset,
                    QuotAssetId   = isLimitAssetBase ? trade.MarketAsset : trade.LimitAsset,
                    Dt            = trade.Timestamp,
                    Id            = Guid.NewGuid().ToString(),
                    LimitOrderId  = trade.LimitOrderId,
                    MarketOrderId = message.Order.Id,
                    Price         = trade.Price.GetValueOrDefault(),
                    QuotAsset     = isLimitAssetBase ? marketAsset.DisplayId : limitAsset.DisplayId,
                });
            }
        }