-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathData_Stooq_EOD.c
29 lines (27 loc) · 901 Bytes
/
Data_Stooq_EOD.c
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
// Download EOD data from any online source to a .t6 history file /////////////////
// the symbol that you want to download
string Ticker = "AAPL.US";
// the API url of the online source ("%s" is replaced with the symbol name)
string URL = "https://stooq.pl/q/d/l/?s=%s&i=d";
// the CSV format string (for details see manual about "dataParse")
string Format = "+%Y-%m-%d,f3,f1,f2,f4,f6";
void main()
{
string Api = strf(URL,Ticker);
string Content = http_transfer(Api,0);
if(!Content) {
printf("Can't access %s",Api);
return;
}
string TempFile = "History\\history.csv";
file_write(TempFile,Content,0);
// convert the CSV to .t8
int N = dataParse(1,Format,TempFile);
if(!N) {
printf("%s invalid content",TempFile);
return;
}
// replace '.','/' in ticker name with '-'
dataSave(1,strf("History\\%s.t6",strxc(strxc(Ticker,'.','-'),'/','-')));
printf("%i %s records read",N,Ticker);
}