Example #1
0
        private IEnumerable <AssetOwner> CalculateOwnership(int height)
        {
            var owners = new Dictionary <string, long> {
                { _asset.AccountRs, _asset.QuantityQnt }
            };
            var index = 0;

            while (index < _asset.NumberOfTrades)
            {
                var getTradesResult = _assetService.GetTrades(AssetIdOrAccountId.ByAssetId(_asset.AssetId), index, index + 99, includeAssetInfo: false).Result;
                foreach (var trade in getTradesResult.Trades.Where(t => t.Height <= height))
                {
                    UpdateOwnership(owners, trade.BuyerRs, trade.SellerRs, trade.QuantityQnt);
                }
                index += 100;
            }
            index = 0;
            while (index < _asset.NumberOfTransfers)
            {
                var getTransfersResult = _assetService.GetAssetTransfers(AssetIdOrAccountId.ByAssetId(_asset.AssetId), index, index + 99, includeAssetInfo: false).Result;
                foreach (var transfer in getTransfersResult.Transfers.Where(t => t.Height <= height))
                {
                    UpdateOwnership(owners, transfer.RecipientRs, transfer.SenderRs, transfer.QuantityQnt);
                }
                index += 100;
            }
            return(owners.Where(o => o.Value != 0).Select(o => new AssetOwner(o.Key, o.Value)));
        }
Example #2
0
        private IList <Asset> GetAssetList(ProgramOptions options)
        {
            var assetList = new List <Asset>();

            if (options.Mode == Mode.All)
            {
                assetList = _assetService.GetAllAssets().Result.AssetList;
            }
            else if (options.Mode == Mode.Account)
            {
                _transfers = _assetService.GetAssetTransfers(AssetIdOrAccountId.ByAccountId(options.Id.ToString()), includeAssetInfo: false).Result.Transfers;
                _trades    = _assetService.GetTrades(AssetIdOrAccountId.ByAccountId(options.Id.ToString()), includeAssetInfo: false).Result.Trades;

                var assetIds = _transfers.Select(transfer => transfer.AssetId).Union(_trades.Select(trade => trade.AssetId)).Distinct();

                assetList = _assetService.GetAssets(assetIds).Result.AssetList;
            }
            else if (options.Mode == Mode.Asset)
            {
                assetList = new List <Asset> {
                    _assetService.GetAsset(options.Id).Result
                };
            }
            return(assetList);
        }
Example #3
0
        private static void GetAllTrades()
        {
            foreach (var asset in Assets)
            {
                var trades = new List <AssetTrade>();
                AssetTrades.Add(asset.AssetId, trades);

                var       index = 0;
                int       replyCount;
                const int increase = 100;
                do
                {
                    var tradesReply = AssetExchangeService.GetTrades(AssetIdOrAccountId.ByAssetId(asset.AssetId), index,
                                                                     index + increase - 1, includeAssetInfo: false).Result;
                    trades.AddRange(tradesReply.Trades);

                    foreach (var assetTrade in tradesReply.Trades)
                    {
                        AssetTradeCount[assetTrade.Buyer]  = GetValueOrDefault(AssetTradeCount, assetTrade.Buyer) + 1;
                        AssetTradeCount[assetTrade.Seller] = GetValueOrDefault(AssetTradeCount, assetTrade.Seller) + 1;
                    }
                    replyCount = tradesReply.Trades.Count;
                    index     += increase;
                } while (replyCount == increase);
            }
        }