public void ApplyTrade(InternalTrade internalTrade)
        {
            if (internalTrade.Type == TradeType.Sell)
            {
                BaseAssetVolume -= internalTrade.Volume;
                QuoteAssetVolume += internalTrade.OppositeSideVolume;
                
                TotalSellBaseAssetVolume += internalTrade.Volume;
                
                TotalBuyQuoteAssetVolume += internalTrade.OppositeSideVolume;

                SellTradesCount++;
            }
            else
            {
                BaseAssetVolume += internalTrade.Volume;
                QuoteAssetVolume -= internalTrade.OppositeSideVolume;
                
                TotalBuyBaseAssetVolume += internalTrade.Volume;
                
                TotalSellQuoteAssetVolume += internalTrade.OppositeSideVolume;

                BuyTradesCount++;
            }
        }
Beispiel #2
0
        public async Task <InternalTradeModel> GetInternalTradeByIdAsync(string tradeId)
        {
            InternalTrade internalTrade = await _internalTradeService.GetByIdAsync(tradeId);

            if (internalTrade == null)
            {
                throw new ValidationApiException(HttpStatusCode.NotFound, "Internal trade does not exist.");
            }

            return(Mapper.Map <InternalTradeModel>(internalTrade));
        }
        public async Task InsertAsync(InternalTrade internalTrade)
        {
            using (DataContext context = _connectionFactory.CreateDataContext())
            {
                InternalTradeEntity entity = Mapper.Map <InternalTradeEntity>(internalTrade);

                context.Add(entity);

                await context.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task InsertAsync(InternalTrade internalTrade)
        {
            var entity = new InternalTradeEntity(GetPartitionKey(internalTrade.Time), GetRowKey(internalTrade.Id));

            Mapper.Map(internalTrade, entity);

            await _storage.InsertOrReplaceAsync(entity);

            AzureIndex index = new AzureIndex(GetIndexPartitionKey(internalTrade.Id), GetRowKey(internalTrade.Id),
                                              entity);

            await _indicesStorage.InsertOrReplaceAsync(index);
        }
Beispiel #5
0
        public async Task UpdateVolumeAsync(string assetId, InternalTrade internalTrade)
        {
            await _semaphore.WaitAsync();

            try
            {
                Token previousToken = await GetAsync(assetId);

                Token currentToken = previousToken.Copy();

                if (internalTrade.Type == TradeType.Sell)
                {
                    currentToken.IncreaseVolume(internalTrade.Volume, internalTrade.OppositeVolume);
                }
                else
                {
                    currentToken.DecreaseVolume(internalTrade.Volume, internalTrade.OppositeVolume);
                }

                await _tokenRepository.SaveAsync(currentToken);

                _cache.Set(currentToken);

                _log.InfoWithDetails("Token open amount updated", new
                {
                    PreviuosToken = previousToken,
                    CurrentToken  = currentToken,
                    InternalTrade = internalTrade
                });
            }
            catch (Exception exception)
            {
                _log.WarningWithDetails("An error occurred while updating open tokens", exception, new
                {
                    AssetId       = assetId,
                    InternalTrade = internalTrade
                });

                throw;
            }
            finally
            {
                _semaphore.Release();
            }
        }
Beispiel #6
0
 public Task RegisterAsync(InternalTrade internalTrade)
 {
     return(_internalTradeRepository.InsertAsync(internalTrade));
 }
Beispiel #7
0
        public void UpdateBillInternalState(IBill bill, InternalTrade trade, string remarks, DateTime? date = null)
        {
            ExceptionHelper.ThrowIfNull(bill, "bill");
            using (var scope = new System.Transactions.TransactionScope())
            {
                var oldState = bill.State;

                bill.UpdateInternalState(_User, trade);
                _BillRepository.SaveChanges();

                if (BillStates.清关完毕国内派送中 != oldState)
                    InsertBillStateHistory(bill, BillStates.清关完毕国内派送中, remarks, date);

                scope.Complete();
            }
        }
Beispiel #8
0
        public async Task <bool> ExistAsync(string internalTradeId)
        {
            InternalTrade internalTrade = await _lykkeTradeRepository.GetByIdAsync(internalTradeId);

            return(internalTrade != null);
        }