-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_readme.php
162 lines (124 loc) · 5.78 KB
/
generate_readme.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php include(__DIR__ . '/testsautoload.php'); ?>
<!-- DO NOT EDIT README.MD DIRECTLY, YOUR CHANGES WILL BE WIPED OUT. PLEASE EDIT generate_readme.php INSTEAD! -->
# QuoteMedia API PHP Library
This library is intended to make QuoteMedia API calls easier to manage.
## Getting Started
Download/clone this repo from Github.
To start using this library, you must first include the autoload.php in the root directory.
## Stocks
This library includes code for using QuoteMedia's stock APIs.
### QuoteMediaStocks Class
If you want quick requests for basic information about stocks, you can use the QuoteMediaStocks class. Note that you should use this class when you want information on less than 50 tickers at once, since that's the API call limit. To go beyond this limit, skip to the next section.
Here's a basic runthrough.
<pre>
$webmaster_id = XXXXX; // REPLACE this with your webmaster ID
$tickers = array('GOOG');//any size array up to maximum per API call
$api = new QuoteMediaStocks($webmaster_id);
$result = $api->getQuotes($tickers);
var_dump($result->getResult());
</pre>
The var dump will show something like this
<pre>
<?php
$api = new QuoteMediaStocks(TEST_WEBMASTER_ID);
$tickers = array('GOOG');
$res = $api->getQuotes($tickers);
var_dump($res->getResult());
?>
</pre>
Other calls are
<pre>
$profiles = $api->getProfiles($tickers);
$fundamentals = $api->getFundamentals($tickers);
$keyratios = $api->getKeyRatios($tickers);
</pre>
If you want it to return a associative map (SYMBOL => RESULT ARRAY) just add second parameter true, ie
<pre>
$quotes = $api->getQuotes($ticker,true);
</pre>
#### Function Reference
<?php
$info = array(
array('getQuotes', QuoteMediaConst::GET_QUOTES, QuoteMediaConst::GET_QUOTES_MAX_SYMBOLS),
array('getProfiles', QuoteMediaConst::GET_PROFILES, QuoteMediaConst::GET_PROFILES_MAX_SYMBOLS),
array('getFundamentals', QuoteMediaConst::GET_FUNDAMENTALS, QuoteMediaConst::GET_FUNDAMENTALS_MAX_SYMBOLS),
array('getKeyRatios', QuoteMediaConst::GET_KEY_RATIOS, QuoteMediaConst::GET_KEY_RATIOS_MAX_SYMBOLS),
);
foreach ($info as $v) {
echo '+ ' . $v[0] . ' (array, bool) - function id (' . $v[1] . ') : calls QuoteMedia\'s ' . $v[0] . '. Can accept up to ' . $v[2] . ' symbols at a time.' . "\n";
}
?>
#### Result Object
You may have realized that to get the actual data, you call $result->getResult().
This is because the returned value from a get* function call is actually a QuoteMediaStockResult object. Here is a quick reference of the functions you can call on this object:
+ hasMissing() - boolean of whether or not there are missing symbols not returned from API
+ getMissing() - get array of missing symbols
+ hasMalformed() - boolean of whether or not there are malformed symbols in the input array
+ getMalformed() - get array of malformed symbols
+ hasError() - boolean of whether or not an error occurred
+ getError() - return string that describes the last error encountered
+ getErrorID() - return ID of the last error encountered
+ getErrorIDHistory() - if multiple errors occurred, this will be an array of errors
+ getResult() - return the result obtained from API
#### QuoteMediaBatcher Class
Note that in the previous section you can only retrieve each section separately and you are limited to 50 tickers at a time in getProfiles. This is due to limitations on the API itself. To bypass these limitations you can use the QuoteMediaBatcher class that is conveniently embedded in the QuoteMediaStocks class.
<pre>
$webmaster_id = 000000;//user inputs webmaster id
$input = array( 'GOOG');
$api = new QuoteMediaStocks($webmaster_id);
$batcher = $api->getBatcher();
$result = $batcher->getAll($input);
var_dump($result->getResult());
</pre>
The var dump would look something like this
<pre>
<?php
$webmaster_id = TEST_WEBMASTER_ID;//user inputs webmaster id
$input = array( 'GOOG');
$api = new QuoteMediaStocks($webmaster_id);
$batcher = $api->getBatcher();
$result = $batcher->getAll($input);
var_dump($result->getResult());
?>
</pre>
If you want to grab only a few sections instead of all, you can use the get() function, like so
<pre>
$webmaster_id = 000000;//user inputs webmaster id
$input = array( 'GOOG');
$api = new QuoteMediaStocks($webmaster_id);
$batcher = $api->getBatcher();
$result = $batcher->get($input,array(QuoteMediaConst::GET_KEY_RATIOS,QuoteMediaConst::GET_QUOTES));
var_dump($result->getResult());
</pre>
The var dump would look something like
<pre>
<?php
$webmaster_id = TEST_WEBMASTER_ID;//user inputs webmaster id
$input = array( 'GOOG');
$api = new QuoteMediaStocks($webmaster_id);
$batcher = $api->getBatcher();
$result = $batcher->get($input,array(QuoteMediaConst::GET_KEY_RATIOS,QuoteMediaConst::GET_QUOTES));
var_dump($result->getResult());
?>
</pre>
Again, you can choose to return an associative map instead of an array using an optional parameter, ie
<pre>
$api->getAll($input,true);
</pre>
## Articles
N/A TBA
## Error Codes
<?php
$oClass = new ReflectionClass('QuoteMediaError');
$array = $oClass->getConstants();
foreach ($array as $a) {
echo '+ ' . $a . ' : ' . QuoteMediaError::IDtoError($a) . "\n";
}
?>
Remember you can always use the result object's getError() function to retrieve the error string instead of doing the conversion yourself.
# Contributing
Contributions can be submitted right here on Github through a pull request.
All functions should be documented in doxygen/javadoc style. The current code the code is in doxygen/javadoc style so you can generate it yourself for reference.
Before any pull request can be submitted, be sure to add to the unit tests to test your new code. Be sure to run the entire suit of unit tests.
You can use the run_tests.sh script if you don't know phpunit.
Don't forget to add your webmaster ID to testsautoload.php before running the test or it will give you a syntax error.