forked from DannyBen/php-quandl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.php
92 lines (78 loc) · 2.3 KB
/
examples.php
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
89
90
91
92
<?php
//--------------------------------------------------------------
// Examples: Quandl API
//--------------------------------------------------------------
require "./vendor/autoload.php";
if (file_exists(__DIR__.'/.env')) {
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
}
Kint::enabled(true);
$api_key = getenv('QUANDL_API_KEY');
$symbol = "GOOG/NASDAQ_AAPL";
// Modify this call to check different samples
$data = example1($api_key, $symbol);
d($data);
// Example 1: Hello Quandl
function example1($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl();
return $quandl->getSymbol($symbol);
}
// Example 2: API Key + JSON
function example2($api_key, $symbol) {
$quandl = new Royopa\Quandl\Quandl($api_key);
$quandl->format = "json";
return $quandl->getSymbol($symbol);
}
// Example 3: Date Range + Last URL
function example3($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key);
print $quandl->last_url;
return $quandl->getSymbol($symbol, [
"trim_start" => "today-30 days",
"trim_end" => "today",
]);
}
// Example 4: CSV + More parameters
function example4($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key, "csv");
return $quandl->getSymbol($symbol, [
"sort_order" => "desc", // asc|desc
"exclude_headers" => true,
"rows" => 10,
"column" => 4, // 4 = close price
]);
}
// Example 5: XML + Frequency
function example5($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key, "xml");
return $quandl->getSymbol($symbol, [
"collapse" => "weekly" // none|daily|weekly|monthly|quarterly|annual
]);
}
// Example 6: Search
function example6($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key);
return $quandl->getSearch("crude oil");
}
// Example 7: Symbol Lists
function example7($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key, "csv");
return $quandl->getList("WIKI", 1, 10);
}
// Example 8: Error Handling
function example8($api_key, $symbol)
{
$quandl = new Royopa\Quandl\Quandl($api_key, "csv");
$result = $quandl->getSymbol("DEBUG/INVALID");
if ($quandl->error and !$result) {
return $quandl->error . " - " . $quandl->last_url;
}
return $result;
}