public async Task <IActionResult> GetTickers([FromQuery] string[] assetPairIds) { var entities = _tickersReader.Get(TickerEntity.GetPk()); List <TickerModel> result; if (entities.Any()) { result = _mapper.Map <List <TickerModel> >(entities); } else { var marketData = await _marketDataClient.GetMarketDataAsync(new Empty()); result = _mapper.Map <List <TickerModel> >(marketData.Items.ToList()); } if (assetPairIds.Any()) { result = result.Where(x => assetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } return(Ok(ResponseModel <IReadOnlyCollection <TickerModel> > .Ok(result))); }
public async Task <ResponseModel <string> > Handle(CreateOrderCommand createOrderCommand, CancellationToken cancellationToken) { string sql = @"INSERT INTO Orders (BrandId, Price, StoreName, CustomerName, CreatedOn, Status) Values (@BrandId, @Price, @StoreName, @CustomerName, @CreatedOn, @Status)"; using var connection = _dbConnectionFactory.CreateConnection(); var insertCount = 0; foreach (var item in createOrderCommand.OrderModel.Orders.Where(x => x.BrandId > 0)) { insertCount += await connection.ExecuteAsync(sql, new { item.BrandId, item.Price, item.StoreName, item.CustomerName, item.CreatedOn, item.Status, }, commandType : CommandType.Text); } var invalidBrandIdCount = createOrderCommand.OrderModel.Orders.Where(x => x.BrandId <= 0).Count(); if (invalidBrandIdCount > 0) { _logger.LogWarning($"BrandId less than 1 item count: {invalidBrandIdCount}"); } return(ResponseModel.Ok($"Total insert count: {insertCount}")); }
public async Task <IActionResult> GetBalances() { var walletId = User.GetWalletId(); var balances = await _balanceService.GetBalancesAsync(walletId); return(Ok(ResponseModel <IReadOnlyCollection <Balance> > .Ok(balances))); }
public async Task <IActionResult> PlaceBulkOrder([FromBody] PlaceBulkLimitOrderRequest request) { var walletId = User.GetWalletId(); var items = request.Orders?.ToArray() ?? Array.Empty <BulkOrderItemModel>(); var orders = new List <MultiOrderItemModel>(); foreach (var item in items) { var order = new MultiOrderItemModel { Id = Guid.NewGuid().ToString(), Price = (double)item.Price, Volume = (double)item.Volume, OrderAction = item.OrderAction, OldId = item.OldId }; orders.Add(order); } var multiOrder = new MultiLimitOrderModel { Id = Guid.NewGuid().ToString(), ClientId = walletId, AssetPairId = request.AssetPairId, CancelPreviousOrders = request.CancelPreviousOrders, Orders = orders.ToArray() }; if (request.CancelMode.HasValue) { multiOrder.CancelMode = request.CancelMode.Value; } MultiLimitOrderResponse response = await _matchingEngineClient.PlaceMultiLimitOrderAsync(multiOrder); if (response == null) { throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available"); } var bulkResponse = new BulkLimitOrderResponse { AssetPairId = request.AssetPairId, Error = response.Status.ToHftApiError().code, Statuses = response.Statuses?.Select(x => new BulkOrderItemStatusModel { Id = x.Id, Price = (decimal)x.Price, Volume = (decimal)x.Volume, Error = x.Status.ToHftApiError().code }).ToArray() }; return(Ok(ResponseModel <BulkLimitOrderResponse> .Ok(bulkResponse))); }
/// <summary> /// Успешный ответ с данными /// </summary> /// <param name="obj">данные</param> protected HttpResponseMessage Success <T>(T obj) { var result = ResponseModel <T> .Ok(obj); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json"); return(response); }
public async Task <IActionResult> GetPublicTrades(string assetPairId, [FromQuery] int?offset = 0, [FromQuery] int?take = 100 ) { var data = await _tradesAdapterClient.GetTradesByAssetPairIdAsync(assetPairId, offset ?? 0, take ?? 100); return(Ok(ResponseModel <IReadOnlyCollection <PublicTradeModel> > .Ok(_mapper.Map <IReadOnlyCollection <PublicTradeModel> >(data.Records)))); }
public async Task <IActionResult> GetOperationsHistoryAsync([FromQuery] int offset = 0, [FromQuery] int take = 100) { var history = await _historyWrapperClient.GetOperationsHistoryAsync( User.GetWalletId(), offset, take); return(Ok(ResponseModel <List <Models.Operations.OperationModel> > .Ok( _mapper.Map <List <Models.Operations.OperationModel> >(history.ToList())))); }
public async Task <IActionResult> UpdateAsync([FromBody] TradingFeeLevelEditModel model) { var brokerId = User.GetTenantId(); var domain = _mapper.Map <TradingFeeLevel>(model); var newDmain = await _tradingFeeLevelService.UpdateAsync(domain, brokerId); var newModel = _mapper.Map <TradingFeeLevelModel>(newDmain); return(Ok(ResponseModel <TradingFeeLevelModel> .Ok(newModel))); }
public async Task <IActionResult> GetOrder(string orderId) { var order = await _historyClient.GetOrderAsync(orderId); if (order == null) { throw HftApiException.Create(HftApiErrorCode.ItemNotFound, HftApiErrorMessages.OrderNotFound).AddField(orderId); } var orderModel = _mapper.Map <OrderModel>(order); return(Ok(ResponseModel <OrderModel> .Ok(orderModel))); }
public async Task <IActionResult> GetOrderbooks(string assetPairId = null, int?depth = null) { var result = await _validationService.ValidateAssetPairAsync(assetPairId); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var orderbooks = await _orderbooksService.GetAsync(assetPairId, depth); return(Ok(ResponseModel <IReadOnlyCollection <OrderbookModel> > .Ok(_mapper.Map <IReadOnlyCollection <OrderbookModel> >(orderbooks)))); }
public async Task <IActionResult> GetAssetPairAsync(string assetPairId) { var result = await _validationService.ValidateAssetPairAsync(assetPairId); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var assetPair = await _assetsService.GetAssetPairByIdAsync(assetPairId); return(Ok(ResponseModel <AssetPair> .Ok(assetPair))); }
public ResponseModel <bool> SetOffline(IWorkerContext context, string userId) { var key = Pref("SetOffline_" + userId); var exist = _redis.GetDatabase().KeyExists(key); if (exist) { return(ResponseModel <bool> .Ok(true)); } _redis.GetDatabase().StringSet(key, "True", TimeSpan.FromMinutes(_setOfflineExpiryInMin), When.Always, CommandFlags.FireAndForget); return(_backend.SetOffline(context, userId)); }
public async Task <IActionResult> AddAsync([FromBody] TradingFeeAddModel model) { var brokerId = User.GetTenantId(); var domain = _mapper.Map <TradingFee>(model); domain.BrokerId = brokerId; var newDomain = await _tradingFeeService.AddAsync(domain); var newModel = _mapper.Map <TradingFeeModel>(newDomain); return(Ok(ResponseModel <TradingFeeModel> .Ok(newModel))); }
public async Task <IActionResult> CancelAllOrders([FromQuery] string assetPairId = null, [FromQuery] OrderAction?side = null) { var assetPairResult = await _validationService.ValidateAssetPairAsync(assetPairId); if (assetPairResult != null) { throw HftApiException.Create(assetPairResult.Code, assetPairResult.Message).AddField(assetPairResult.FieldName); } bool?isBuy; switch (side) { case OrderAction.Buy: isBuy = true; break; case OrderAction.Sell: isBuy = false; break; default: isBuy = null; break; } var model = new LimitOrderMassCancelModel { Id = Guid.NewGuid().ToString(), AssetPairId = assetPairId, ClientId = User.GetWalletId(), IsBuy = isBuy }; MeResponseModel response = await _matchingEngineClient.MassCancelLimitOrdersAsync(model); if (response == null) { throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available"); } (HftApiErrorCode code, string message) = response.Status.ToHftApiError(); if (code == HftApiErrorCode.Success) { return(Ok(ResponseModel <string> .Ok(null))); } throw HftApiException.Create(code, message); }
public async Task <IActionResult> GetAsync(long id) { var brokerId = User.GetTenantId(); var asset = await _cashOperationsFeeService.GetAsync(id, brokerId); if (asset == null) { return(NotFound()); } var model = _mapper.Map <CashOperationsFeeModel>(asset); return(Ok(ResponseModel <CashOperationsFeeModel> .Ok(model))); }
public async Task <IActionResult> GetLevelsAsync(long tradingFeeId) { var brokerId = User.GetTenantId(); var domain = await _tradingFeeLevelService.GetAllAsync(tradingFeeId, brokerId); if (domain == null) { return(NotFound()); } var model = _mapper.Map <TradingFeeLevelModel[]>(domain); return(Ok(ResponseModel <TradingFeeLevelModel[]> .Ok(model))); }
public async Task <IActionResult> GetAsync() { var brokerId = User.GetTenantId(); var domain = await _settingsService.GetAsync(brokerId); if (domain == null) { return(NotFound()); } var model = _mapper.Map <SettingsModel>(domain); return(Ok(ResponseModel <SettingsModel> .Ok(model))); }
public async Task <IActionResult> UpdateAsync([FromBody] CashOperationsFeeEditModel model) { var brokerId = User.GetTenantId(); var userId = User.GetUserId(); var domain = _mapper.Map <CashOperationsFee>(model); domain.BrokerId = brokerId; var newDmain = await _cashOperationsFeeService.UpdateAsync(userId, domain); var newModel = _mapper.Map <CashOperationsFeeModel>(newDmain); return(Ok(ResponseModel <CashOperationsFeeModel> .Ok(newModel))); }
public async Task <IActionResult> GetManyAsync([FromQuery] CashOperationsFeeRequestManyModel request) { var sortOrder = request.Order == PaginationOrder.Asc ? ListSortDirection.Ascending : ListSortDirection.Descending; var brokerId = User.GetTenantId(); var cashOperationsFees = await _cashOperationsFeeService.GetAllAsync(brokerId, request.Asset, sortOrder, request.Cursor, request.Limit); var result = _mapper.Map <CashOperationsFeeModel[]>(cashOperationsFees); var payload = result.Paginate(request, Url, x => x.Id); return(Ok(ResponseModel <Paginated <CashOperationsFeeModel, long> > .Ok(payload))); }
public async Task <IActionResult> CancelOrder(string orderId) { MeResponseModel response = await _matchingEngineClient.CancelLimitOrderAsync(orderId); if (response == null) { throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available"); } (HftApiErrorCode code, string message) = response.Status.ToHftApiError(); if (code == HftApiErrorCode.Success) { return(Ok(ResponseModel <string> .Ok(null))); } throw HftApiException.Create(code, message); }
public async Task <IActionResult> GetCloasedOrders( [FromQuery] string assetPairId = null, [FromQuery] int?offset = 0, [FromQuery] int?take = 100 ) { var result = await _validationService.ValidateOrdersRequestAsync(assetPairId, offset, take); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var orders = await _historyClient.GetOrdersByWalletAsync(User.GetWalletId(), assetPairId, new [] { OrderStatus.Matched, OrderStatus.Cancelled, OrderStatus.Replaced }, null, false, offset, take); var ordersModel = _mapper.Map <IReadOnlyCollection <OrderModel> >(orders); return(Ok(ResponseModel <IReadOnlyCollection <OrderModel> > .Ok(_mapper.Map <IReadOnlyCollection <OrderModel> >(ordersModel)))); }
public ResponseModel <User> ValidateToken(IWorkerContext context, TokenModel model) { var key = Pref("ValidateToken_" + model.Token); var userId = _redis.GetDatabase().StringGet(key); if (userId.HasValue) { return(ResponseModel <User> .Ok(new User { UserId = userId })); } var response = _backend.ValidateToken(context, model); if (response.Success) { _redis.GetDatabase() .StringSet(key, response.Body.UserId, TimeSpan.FromMinutes(_validateTokenExpiryInMin)); } return(response); }
public async Task <IActionResult> GetTrades( [FromQuery] string assetPairId = null, [FromQuery] OrderAction?side = null, [FromQuery] int?offset = 0, [FromQuery] int?take = 100, [FromQuery] DateTime?from = null, [FromQuery] DateTime?to = null ) { var result = await _validationService.ValidateOrdersRequestAsync(assetPairId, offset, take); if (result != null) { throw HftApiException.Create(result.Code, result.Message) .AddField(result.FieldName); } var trades = await _historyClient.GetTradersAsync(User.GetWalletId(), assetPairId, offset, take, side, from, to); return(Ok(ResponseModel <IReadOnlyCollection <TradeModel> > .Ok(_mapper.Map <IReadOnlyCollection <TradeModel> >(trades)))); }
public async Task <ResponseModel <IEnumerable <object> > > Handle(GetOrdersQuery getOrdersQuery, CancellationToken cancellationToken) { var builder = new SqlBuilder(); var sql = builder.AddTemplate(@"select * from Orders /**where**/ /**orderby**/ LIMIT @Next OFFSET @Offset", new { Offset = getOrdersQuery.OrderFilterModel.PageNumber - 1, Next = getOrdersQuery.OrderFilterModel.PageSize }); if (!string.IsNullOrEmpty(getOrdersQuery.OrderFilterModel.SearchText)) { builder.Where("StoreName || CustomerName like @SearchText", new { SearchText = "%" + getOrdersQuery.OrderFilterModel.SearchText + "%" }); } if (getOrdersQuery.OrderFilterModel.StartDate.HasValue && getOrdersQuery.OrderFilterModel.EndDate.HasValue) { builder.Where("CreatedOn >= @StartDate AND CreatedOn <= @EndDate", new { StartDate = getOrdersQuery.OrderFilterModel.StartDate.Value, EndDate = getOrdersQuery.OrderFilterModel.EndDate.Value }); } if (getOrdersQuery.OrderFilterModel.Statuses.ContainItem()) { builder.Where("Status in (@Statuses)", new { getOrdersQuery.OrderFilterModel.Statuses }); } if (!string.IsNullOrEmpty(getOrdersQuery.OrderFilterModel.SortBy)) { var sortColumns = OrderInfoModel.GetMatchOrderByFields(getOrdersQuery.OrderFilterModel.SortBy); if (sortColumns.ContainItem()) { builder.OrderBy($"{string.Join(",", sortColumns)}"); } } using var connection = _dbConnectionFactory.CreateConnection(); var result = await connection.QueryAsync <object>(sql.RawSql, sql.Parameters); return(ResponseModel.Ok(result)); }
public async Task <IActionResult> PlaceLimitOrder(PlaceLimitOrderRequest request) { var walletId = User.GetWalletId(); var result = await _validationService.ValidateLimitOrderAsync(walletId, request.AssetPairId, request.Side, request.Price, request.Volume); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var order = new LimitOrderModel { Id = Guid.NewGuid().ToString(), AssetPairId = request.AssetPairId, ClientId = walletId, Price = (double)request.Price, CancelPreviousOrders = false, Volume = (double)Math.Abs(request.Volume), OrderAction = request.Side }; MeResponseModel response = await _matchingEngineClient.PlaceLimitOrderAsync(order); if (response == null) { throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available"); } (HftApiErrorCode code, string message) = response.Status.ToHftApiError(); if (code == HftApiErrorCode.Success) { return(Ok(ResponseModel <LimitOrderResponse> .Ok(new LimitOrderResponse { OrderId = response.TransactionId }))); } throw HftApiException.Create(code, message); }
public async Task <IActionResult> PlaceMarketOrder(PlaceMarketOrderRequest request) { var result = await _validationService.ValidateMarketOrderAsync(request.AssetPairId, request.Volume); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var walletId = User.GetWalletId(); var order = new MarketOrderModel { Id = Guid.NewGuid().ToString(), AssetPairId = request.AssetPairId, ClientId = walletId, Volume = (double)request.Volume, OrderAction = request.Side, Straight = true }; var response = await _matchingEngineClient.HandleMarketOrderAsync(order); if (response == null) { throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available"); } (HftApiErrorCode code, string message) = response.Status.ToHftApiError(); if (code == HftApiErrorCode.Success) { return(Ok(ResponseModel <MarketOrderResponse> .Ok(new MarketOrderResponse { OrderId = order.Id, Price = (decimal)response.Price }))); } throw HftApiException.Create(code, message); }
public async Task <IActionResult> GetActiveOrders( [FromQuery] string assetPairId = null, [FromQuery] int?offset = 0, [FromQuery] int?take = 100 ) { var result = await _validationService.ValidateOrdersRequestAsync(assetPairId, offset, take); if (result != null) { throw HftApiException.Create(result.Code, result.Message).AddField(result.FieldName); } var statuses = new List <string> { OrderStatus.Placed.ToString(), OrderStatus.PartiallyMatched.ToString() }; var orders = _ordersReader.Get(User.GetWalletId(), offset ?? 0, take ?? 100, x => (string.IsNullOrEmpty(assetPairId) || x.AssetPairId == assetPairId) && statuses.Contains(x.Status)); var ordersModel = _mapper.Map <IReadOnlyCollection <OrderModel> >(orders); return(Ok(ResponseModel <IReadOnlyCollection <OrderModel> > .Ok(ordersModel))); }
protected ActionResult Success <T>(T data, string strMessage = "") { return(Return(ResponseModel <T> .Ok(data, strMessage))); }
public async Task <IActionResult> GetAllAssetPairs() { var assetPairs = await _assetsService.GetAllAssetPairsAsync(); return(Ok(ResponseModel <IReadOnlyList <AssetPair> > .Ok(assetPairs))); }
protected ActionResult Success() { return(Return(ResponseModel <string> .Ok(""))); }