public async Task InitializeAsync() { _logger.LogInformation("Initializing internal trades..."); var tradesRequest = new TradesRequest(); _logger.LogInformation("Receiving all internal quotes..."); //tradesRequest.From //var pricesResponse = await _client.PrivateApi.Get(priceRequest); //ValidateResponse(pricesResponse.Error); //_logger.LogInformation($"Received {pricesResponse.Payload.Count} internal quotes."); //foreach (var priceUpdate in pricesResponse.Payload) //{ // var quote = Map(priceUpdate); // foreach (var quoteHandler in _handlers) // { // await quoteHandler.HandleAsync(quote); // } //} //_logger.LogInformation("Handled all internal quotes."); }
public Task <CurrencyPairDictionary <Trade[]> > GetTradesAsync(CurrencyPairCollection pairs, CancellationToken cancellationToken = default) { var request = new TradesRequest { Pairs = pairs }; return(_client.PostAsync <CurrencyPairDictionary <Trade[]> >("trades", request, cancellationToken)); }
public void UnsubscribeTrades() { TradesRequest tr = new TradesRequest { Channel = ChannelType.Trades, Action = ActionType.Unsubscribe }; AddMessageToQueue(tr); }
public void SubscribeTrades(string symbol) { TradesRequest tr = new TradesRequest { Channel = ChannelType.Trades, Action = ActionType.Subscribe, Symbol = symbol }; AddMessageToQueue(tr); }
public async Task TradesRequest_Test() { const string symbol = "tBTCUSD"; TradesRequest tradesRequest = new TradesRequest(symbol) { Limit = 120, Sort = -1 }; var result = await tradesRequest.ExecuteAsync(); }
public override async Task <TradesResponse> GetTrades(TradesRequest request, ServerCallContext context) { var result = await _validationService.ValidateTradesRequestAsync(request.AssetPairId, request.Offset, request.Take); if (result != null) { return(new TradesResponse { Error = new Error { Code = _mapper.Map <ErrorCode>(result.Code), Message = result.Message } }); } DateTime?from = null; DateTime?to = null; if (request.OptionalFromCase != TradesRequest.OptionalFromOneofCase.None) { from = request.From.ToDateTime(); } if (request.OptionalToCase != TradesRequest.OptionalToOneofCase.None) { to = request.To.ToDateTime(); } var orderAction = request.OptionalSideCase == TradesRequest.OptionalSideOneofCase.None ? (OrderAction?)null : _mapper.Map <OrderAction>(request.Side); if (request.Take == 0) { request.Take = Constants.MaxPageSize; } var trades = await _historyClient.GetTradersAsync(context.GetHttpContext().User.GetWalletId(), request.AssetPairId, request.Offset, request.Take, orderAction, from, to); var res = new TradesResponse(); var data = _mapper.Map <List <Trade> >(trades); res.Payload.AddRange(data); return(res); }
public void Trades() { var request = new TradesRequest() { Bin = "700000001", Subcode = "0517614", TradePaymentSummary = true, TradePaymentTotals = true, TradePaymentExperiences = true, TradePaymentTrends = true, }; var response = this.Fixture.ServiceClient.PostTradesAsync(Client.Environ.Sandbox, this.Fixture.ObtainAuthToken(), request); Assert.NotNull(response.Result); }
public override async Task <TradesResponse> GetTrades(TradesRequest request, ServerCallContext context) { var session = SessionFromContext(context); var assetPairId = request.OptionalAssetPairIdCase == TradesRequest.OptionalAssetPairIdOneofCase.AssetPairId ? request.AssetPairId : string.Empty; DateTime?fromTime = request.OptionalFromDateCase == TradesRequest.OptionalFromDateOneofCase.From ? request.From.ToDateTime() : (DateTime?)null; DateTime?toTime = request.OptionalToDateCase == TradesRequest.OptionalToDateOneofCase.To ? request.To.ToDateTime() : (DateTime?)null; var side = request.OptionalTradeTypeCase == TradesRequest.OptionalTradeTypeOneofCase.TradeType ? request.TradeType : string.Empty; var trades = await _clientWalletService.GetClientTradesAsync(session.TenantId, session.ClientId, assetPairId, fromTime, toTime, side, request.Skip, request.Take); var resp = new TradesResponse(); foreach (var trade in trades) { resp.Trades.Add(new TradesResponse.Types.TradeModel() { Id = trade.TradeId, AssetPairId = trade.BaseAssetId + trade.QuotingAssetId, //todo: take Id from AssetPair list Timestamp = Timestamp.FromDateTime(DateTime.SpecifyKind(trade.Timestamp, DateTimeKind.Utc)), Price = trade.Price, BaseVolume = trade.BaseVolume.Replace("-", ""), BaseAssetName = trade.BaseAssetId, QuoteVolume = trade.QuotingVolume, QuoteAssetName = trade.QuotingAssetId, Direction = trade.BaseVolume.StartsWith("-") ? "Sell" : "Buy", OrderId = trade.ExternalOrderId }); } return(resp); }
public override async Task <TradesResponse> GetTrades(TradesRequest request, ServerCallContext context) { var result = await _validationService.ValidateTradesRequestAsync(request.AssetPairId, request.Offset, request.Take); if (result != null) { return(new TradesResponse { Error = new Error { Code = (int)result.Code, Message = result.Message } }); } DateTime?from = null; DateTime?to = null; if (DateTime.TryParse(request.From, out var fromDate)) { from = fromDate; } if (DateTime.TryParse(request.To, out var toDate)) { to = toDate; } var orderAction = request.OptionalSideCase == TradesRequest.OptionalSideOneofCase.None ? (OrderAction?)null : request.Side == Side.Buy ? OrderAction.Buy : OrderAction.Sell; var trades = await _historyClient.GetTradersAsync(context.GetHttpContext().User.GetWalletId(), request.AssetPairId, request.Offset, request.Take, orderAction, from, to); var res = new TradesResponse(); var data = _mapper.Map <List <Trade> >(trades); res.Payload.AddRange(data); return(res); }
public override async Task <TradesResponse> GetTrades(TradesRequest request, ServerCallContext context) { var result = new TradesResponse(); var token = context.GetBearerToken(); var wallets = await _clientAccountClient.Wallets.GetClientWalletsFilteredAsync(context.GetClientId(), WalletType.Trading); var walletId = wallets.FirstOrDefault()?.Id; var response = await _walletApiV2Client.GetTradesByWalletIdAsync( walletId, request.AssetPairId, request.Take, request.Skip, request.OptionalFromDateCase == TradesRequest.OptionalFromDateOneofCase.None?(DateTimeOffset?)null : request.From.ToDateTimeOffset(), request.OptionalToDateCase == TradesRequest.OptionalToDateOneofCase.None?(DateTimeOffset?)null : request.To.ToDateTimeOffset(), request.OptionalTradeTypeCase == TradesRequest.OptionalTradeTypeOneofCase.None?null : (TradeType?)Enum.Parse(typeof(TradeType?), request.TradeType), token); if (response != null) { result.Body = new TradesResponse.Types.Body(); result.Body.Trades.AddRange(_mapper.Map <List <TradesResponse.Types.TradeModel> >(response)); } return(result); }
public TradePage GetTrades(TradesRequest request) => GetTradesAsync(request).GetAwaiter().GetResult();
public async Task <TradePage> GetTradesAsync(TradesRequest request) { return(await this.httpClient.GetAsync <TradePage>($"{baseUrl}/api/v1/trades{Query(request)}")); }
public override TradesModel RequestTrades(PairBase pair) { var request = new TradesRequest(pair); return(request.Request <TradesResponse>().Transform()); }