Ejemplo n.º 1
0
        public static HistoricalPrice GetLastPrice(string ticker, Exchange?exchange, AssetClass?assetType)
        {
            string uri = $"api/DataSources/getlastprice?ticker={ticker}";

            if (exchange.HasValue)
            {
                uri += $"&market={exchange.ToString()}";
            }
            if (assetType.HasValue)
            {
                uri += $"&assetType={assetType.ToString()}";
            }
            else
            {
                uri += $"&assetType={AssetClass.Unknown.ToString()}";
            }

            HttpStatusCode statusCode = HttpClientWebAPI.Get(uri, out string jsonResponse);
            var            response   = JsonConvert.DeserializeObject <APIResponse <HistoricalPrice> >(jsonResponse);

            if (response.Ok)
            {
                return(response.Content);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <Portfolio> GetPortfoliosByUser(string username)
        {
            string         uri        = $"api/Portfolios/getportfoliosbyuser?username={username}";
            HttpStatusCode statusCode = HttpClientWebAPI.Get(uri, out string jsonResponse);
            APIResponse <IEnumerable <Portfolio> > response = JsonConvert.DeserializeObject <APIResponse <IEnumerable <Portfolio> > >(jsonResponse, jsonSerializerSettings);

            return(response.Content);
        }
Ejemplo n.º 3
0
        public static APIResponse <Portfolio> CreateNewPortfolioFromTransacions(string username, string portfolioName, Stream file)
        {
            string uri = $"api/Portfolios/createportfolio";
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("username", username);
            parameters.Add("portfolioname", portfolioName);
            string                  name       = "transactions";
            string                  filename   = name + ".csv";
            HttpStatusCode          statusCode = HttpClientWebAPI.Post(uri, parameters, file, name, filename, out string jsonResponse);
            APIResponse <Portfolio> response   = JsonConvert.DeserializeObject <APIResponse <Portfolio> >(jsonResponse, jsonSerializerSettings);

            return(response);
        }
Ejemplo n.º 4
0
        public static bool UpdateAssetAllocation(AssetAllocation assetAllocation, out APIResponse <AssetAllocation> response, out string message)
        {
            string         uri            = $"api/Portfolios/updateassetallocation";
            HttpStatusCode httpStatusCode = HttpClientWebAPI.Post <int>(uri, assetAllocation.Id, out string jsonResponse, out string reasonPhrase);

            if (httpStatusCode == HttpStatusCode.OK)
            {
                response = JsonConvert.DeserializeObject <APIResponse <AssetAllocation> >(jsonResponse, jsonSerializerSettings);
                message  = response.ErrorMessage;
                return(response.Ok);
            }
            else
            {
                response = null;
                message  = reasonPhrase;
                return(false);
            }
        }
Ejemplo n.º 5
0
        public static bool Save(int id, decimal marketValue, out APIResponse <bool> response, out string message)
        {
            string uri = $"api/Portfolios/updateportfolio";
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("id", id.ToString());
            parameters.Add("marketValue", marketValue.ToString());

            HttpStatusCode httpStatusCode = HttpClientWebAPI.Post(uri, parameters, out string jsonResponse, out string reasonPhrase);;

            response = JsonConvert.DeserializeObject <APIResponse <bool> >(jsonResponse);
            if (httpStatusCode == HttpStatusCode.OK)
            {
                message = response.ErrorMessage;
                return(response.Ok);
            }
            else
            {
                message = $"{reasonPhrase} - {response.ErrorMessage}";
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static APIResponse <Stock> GetCompleteStockData(string ticker, Exchange?market, AssetClass?assetType, bool includeOptionChain, bool includeFinancialData)
        {
            string uri = $"api/DataSources/getcompletestockdata?ticker={ticker}";

            if (market.HasValue)
            {
                uri += $"&market={market.ToString()}";
            }
            if (assetType.HasValue)
            {
                uri += $"&assetType={assetType.ToString()}";
            }
            else
            {
                uri += $"&assetType={AssetClass.Unknown.ToString()}";
            }
            uri += $"&includeOptionChain={includeOptionChain}";
            uri += $"&includeFinancialData={includeFinancialData}";
            HttpStatusCode statusCode = HttpClientWebAPI.Get(uri, out string jsonResponse);

            return(JsonConvert.DeserializeObject <APIResponse <Stock> >(jsonResponse));
        }
Ejemplo n.º 7
0
        public static APIResponse <PriceList> GetPrices(string ticker, Exchange?exchange, DateTime?from, DateTime?to, PriceInterval interval)
        {
            string uri = $"api/DataSources/getprices?ticker={ticker}";

            if (exchange.HasValue)
            {
                uri += $"&market={exchange.ToString()}";
            }

            if (from.HasValue)
            {
                uri += $"&from={from.Value.ToString("")}";
            }

            if (to.HasValue)
            {
                uri += $"&to={to.Value.ToString("")}";
            }

            uri += $"&interval={interval.ToString("")}";
            HttpStatusCode statusCode = HttpClientWebAPI.Get(uri, out string jsonResponse);

            return(JsonConvert.DeserializeObject <APIResponse <PriceList> >(jsonResponse));
        }