示例#1
0
        public async Task <WatchListResult <IMarginTradingWatchList> > AddAsync(string id, string clientId, string name, List <string> assetIds)
        {
            var result     = new WatchListResult <IMarginTradingWatchList>();
            var isNew      = string.IsNullOrEmpty(id);
            var watchLists = (await GetWatchLists(clientId)).ToList();
            var allAssets  = await GetAvailableAssetIds(clientId);

            foreach (var assetId in assetIds)
            {
                if (!allAssets.Contains(assetId))
                {
                    result.Status  = WatchListStatus.AssetNotFound;
                    result.Message = assetId;
                    return(result);
                }
            }

            var existing = watchLists.FirstOrDefault(item => item.Id == id);

            if (existing != null && existing.ReadOnly)
            {
                result.Status  = WatchListStatus.ReadOnly;
                result.Message = "This watch list is readonly";
                return(result);
            }

            var watchList = new MarginTradingWatchList
            {
                Id       = isNew ? Guid.NewGuid().ToString("N") : id,
                ClientId = clientId,
                Name     = name,
                AssetIds = assetIds
            };

            if (isNew)
            {
                watchList.Order = watchLists.Count;
            }

            if (existing != null)
            {
                watchList.Order = existing.Order;
            }

            result.Result = await _watchListRepository.AddAsync(watchList);

            return(result);
        }
示例#2
0
        public async Task <WatchListResult <bool> > DeleteAsync(string clientId, string id)
        {
            var result = new WatchListResult <bool>();

            var watchList = await GetAsync(clientId, id);

            if (watchList == null)
            {
                result.Status = WatchListStatus.NotFound;
                return(result);
            }

            if (watchList.ReadOnly)
            {
                result.Status = WatchListStatus.ReadOnly;
                return(result);
            }

            await _watchListRepository.DeleteAsync(clientId, id);

            result.Result = true;
            return(result);
        }