public async Task <ActionResult> ViewPositions() { try { var authResult = await _unifiedAuth.AuthenticateUser(Request.HttpContext); var tokenStatus = authResult.Item3; switch (tokenStatus) { case TokenHelper.TokenStatus.Valid: { var account = authResult.Item2; var positions = await _context.Positions.Where(x => x.AccountId == account.Id).ToListAsync(); return(Ok(positions)); } case TokenHelper.TokenStatus.Expired: { StatusOutput status = new StatusOutput() { message = StatusMessages.ExpiredTokenMessage }; return(Ok(status)); } default: { StatusOutput status = new StatusOutput() { message = StatusMessages.InvalidTokenMessage }; return(Ok(status)); } } } catch (Exception e) { Log.Fatal(e, $"{nameof(ViewPositions)}"); return(StatusCode(500)); } }
public async Task <ActionResult> ExecuteTrade([FromBody] TradeExecInput input) { var authResult = await _unifiedAuth.AuthenticateUser(Request.HttpContext); var tokenStatus = authResult.TokenStatus; switch (tokenStatus) { case TokenHelper.TokenStatus.Valid: { TradeExecOutput response = default; // Use the Consolidated Trading Platform Service (Real-time and/or RDS) if (_consolidatedTradingPlatformEnabled) { if (authResult.Account != null) { var consolidatedTradeRequest = new ConsolidatedTradeRequest() { AccountId = authResult.Account.Id, OrderAction = input.Type, OrderOrigin = ConsolidatedTradeEnums.ConsolidatedOrderOrigin.PseudoMarkets, OrderTiming = ConsolidatedTradeEnums.ConsolidatedOrderTiming.DayOnly, OrderType = ConsolidatedTradeEnums.ConsolidatedOrderType.Market, Quantity = input.Quantity, Symbol = input.Symbol, EnforceMarketOpenCheck = true }; _tradingPlatformClient.SendTradeRequest(consolidatedTradeRequest); var ctpResponse = _tradingPlatformClient.GetTradeResponse(); if (ctpResponse != null) { response = new TradeExecOutput() { Order = ctpResponse?.Order, StatusCode = GetTradeStatusCodeUsing(ctpResponse.StatusCode), StatusMessage = ctpResponse?.StatusMessage }; } } } else { // Fallback to legacy trading code using Relational Data Store (RDS) response = await RdsFallback.ProcessTradingRequestUsingRdsFallback(authResult.User, authResult.Account, input, _context, _marketDataService, _dateTimeHelper); } return(Ok(response)); } case TokenHelper.TokenStatus.Expired: { TradeExecOutput status = new TradeExecOutput { Order = null, StatusCode = TradeStatusCodes.ExecutionError, StatusMessage = StatusMessages.ExpiredTokenMessage }; return(Ok(status)); } default: { TradeExecOutput status = new TradeExecOutput { Order = null, StatusCode = TradeStatusCodes.ExecutionError, StatusMessage = StatusMessages.InvalidTokenMessage }; return(Ok(status)); } } }