public IHttpActionResult GetBalances()
 {
     try
     {
         // Get api key from header
         var    headers = Request.Headers;
         string apikey  = "";
         IEnumerable <string> headerParams;
         if (headers.TryGetValues("Auth", out headerParams))
         {
             string[] auth = headerParams.ToList()[0].Split(',');
             apikey = auth[0];
         }
         if (log.IsDebugEnabled)
         {
             log.Debug(string.Format("Get Balances Call: ApiKey = {0}", apikey));
         }
         int accountId = _apiKeyInfoAccess.GetUserIdFromApiKey(apikey);
         return(Ok(_balanceQueryService.GetBalances(new AccountId(accountId))));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(string.Format("Get Balances Call Error: {0}", exception));
         }
         return(InternalServerError());
     }
 }
Пример #2
0
        public void GetUserIDFromApiKey_IfKeyPairExists_UserIdWillBeReturned()
        {
            SecurityKeysPair digitalSignatureInfo = new SecurityKeysPair("1", "123456", "secretkey", 1, DateTime.Today.AddDays(1), DateTime.Today.AddDays(-20), DateTime.Today, DateTime.Now, true, null);

            _persistenceRepository.SaveUpdate(digitalSignatureInfo);
            Assert.AreEqual(_apiKeyInfoAccess.GetUserIdFromApiKey("123456"), 1);
        }
 public IHttpActionResult GetRecentDeposits([FromBody] GetRecentDepositParams getRecentDepositParams)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug(string.Format("Get Recent Deposits call: Currency = {0}",
                                 getRecentDepositParams.Currency));
     }
     try
     {
         // Get api key from header
         var    headers = Request.Headers;
         string apikey  = "";
         IEnumerable <string> headerParams;
         if (headers.TryGetValues("Auth", out headerParams))
         {
             string[] auth = headerParams.ToList()[0].Split(',');
             apikey = auth[0];
         }
         if (log.IsDebugEnabled)
         {
             log.Debug(string.Format("Get Recent Deposits Call: ApiKey = {0}", apikey));
         }
         if (getRecentDepositParams != null && !string.IsNullOrEmpty(getRecentDepositParams.Currency))
         {
             int accountId = _apiKeyInfoAccess.GetUserIdFromApiKey(apikey);
             return(Ok(_depositApplicationService.GetRecentDeposits(getRecentDepositParams.Currency, accountId)));
         }
         return(BadRequest("Currency is not provided."));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(string.Format("Get Recent Deposits Call Error: {0}", exception));
         }
         return(InternalServerError());
     }
 }
        public IHttpActionResult GetTradeHistory([FromBody] TradeHistoryParams tradeHistoryParams)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Trade History Call Recevied:" + tradeHistoryParams);
            }
            try
            {
                //get api key from header
                var    headers = Request.Headers;
                string apikey  = "";
                IEnumerable <string> headerParams;
                if (headers.TryGetValues("Auth", out headerParams))
                {
                    string[] auth = headerParams.ToList()[0].Split(',');
                    apikey = auth[0];
                }
                log.Debug("Api Key:" + apikey);
                TraderId traderId     = new TraderId(_apiKeyInfoAccess.GetUserIdFromApiKey(apikey).ToString());
                var      closedOrders = _tradeApplicationService.GetTradesHistory(traderId, tradeHistoryParams.Start, tradeHistoryParams.End);

                if (closedOrders != null)
                {
                    return(Ok(closedOrders));
                }
                return(BadRequest());
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Trade History Call Error", exception);
                }
                return(InternalServerError());
            }
        }
 public IHttpActionResult CancelOrder([FromBody] string orderId)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug("Cancel Order Call: OrderId=" + orderId);
     }
     try
     {
         //get api key from header
         var    headers = Request.Headers;
         string apikey  = "";
         IEnumerable <string> headerParams;
         if (headers.TryGetValues("Auth", out headerParams))
         {
             string[] auth = headerParams.ToList()[0].Split(',');
             apikey = auth[0];
         }
         if (log.IsDebugEnabled)
         {
             log.Debug("Cancel Order Call: apikey=" + apikey);
         }
         if (orderId != string.Empty)
         {
             TraderId traderId = new TraderId(_apiKeyInfoAccess.GetUserIdFromApiKey(apikey).ToString());
             return(Ok(_orderApplicationService.CancelOrder(
                           new CancelOrderCommand(new OrderId(orderId), traderId))));
         }
         return(BadRequest("OrderId is not provided."));
     }
     catch (InvalidOperationException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Cancel Order Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (NullReferenceException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Cancel Order Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (InstanceNotFoundException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Cancel Order Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Cancel Order Call Error", exception);
         }
         return(InternalServerError());
     }
 }