forked from ISM6225/Assignment_5_ActiveCloudSite_Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIEXHandlerUpdate
More file actions
90 lines (76 loc) · 3.39 KB
/
IEXHandlerUpdate
File metadata and controls
90 lines (76 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using IEXTrading.Models;
using Newtonsoft.Json;
namespace IEXTrading.Infrastructure.IEXTradingHandler
{
public class IEXHandler
{
static string BASE_URL = "https://api.iextrading.com/1.0/"; //This is the base URL, method specific URL is appended to this.
HttpClient httpClient;
public IEXHandler()
{
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
}
/****
* Calls the IEX reference API to get the list of symbols.
****/
public List<Company> GetSymbols()
{
string IEXTrading_API_PATH = BASE_URL + "ref-data/symbols";
string companyList = "";
List<Company> companies = null;
httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();
if (response.IsSuccessStatusCode)
{
companyList = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
if (!companyList.Equals(""))
{
companies = JsonConvert.DeserializeObject<List<Company>>(companyList);
companies = companies.GetRange(0, 9);
}
return companies;
}
/****
* Calls the IEX stock API to get 1 year's chart for the supplied symbol.
****/
public List<Equity> GetChart(string symbol)
{
//Using the format method.
//string IEXTrading_API_PATH = BASE_URL + "stock/{0}/batch?types=chart&range=1y";
//IEXTrading_API_PATH = string.Format(IEXTrading_API_PATH, symbol);
string IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/batch?types=quote,chart&range=1y";
string charts = "";
List<Equity> Equities = new List<Equity>();
httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();
if (response.IsSuccessStatusCode)
{
charts = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
if (!charts.Equals(""))
{
ChartRoot root = JsonConvert.DeserializeObject<ChartRoot>(charts, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
Equities = root.chart.ToList();
}
//make sure to add the symbol the chart
foreach (Equity Equity in Equities)
{
Equity.symbol = symbol;
}
return Equities;
}
}
}
/****************************************************************************
I reverted this to the original functions. The major change was adding the quote path to the api handler
string IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/batch?types=quote,chart&range=1y";
This adds the variables the recommender needs, but keeps separate form Company Model
******************************************************************************/