forked from tavurth/OandaWrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOandaWrapReference.html
366 lines (360 loc) · 19.3 KB
/
OandaWrapReference.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<html><head><title>OandaWrap REST API</title></head><body><pre>
<h1>OANDAWRAP</h1>
Copyright 2014 William Whitty
Tavurth@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</pre><br><pre>
<b>OANDAWRAP API WRAPPER FOR OANDAS 'REST'</b>
Written by William Whitty July 2014
Questions, comments or bug reports?
Tavurth@gmail.com
I am in no way responsible for any of your losses incurred
while trading forex.
I take my trades off the table if they become losers.
Best,
Will
</pre><pre><b>Function Index:</b>
<br><br>
<a href="#valid"><b><i>valid</i></b></a>
<a href="#setup"><b><i>setup</i></b></a>
<a href="#stream"><b><i>stream</i></b></a>
<a href="#account"><b><i>account</i></b></a>
<a href="#accounts"><b><i>accounts</i></b></a>
<a href="#account_id"><b><i>account_id</i></b></a>
<a href="#account_named"><b><i>account_named</i></b></a>
<a href="#instruments"><b><i>instruments</i></b></a>
<a href="#instrument"><b><i>instrument</i></b></a>
<a href="#instrument_pairs"><b><i>instrument_pairs</i></b></a>
<a href="#instrument_name"><b><i>instrument_name</i></b></a>
<a href="#instrument_split"><b><i>instrument_split</i></b></a>
<a href="#instrument_pip"><b><i>instrument_pip</i></b></a>
<a href="#convert"><b><i>convert</i></b></a>
<a href="#convert_pair"><b><i>convert_pair</i></b></a>
<a href="#calc_pips"><b><i>calc_pips</i></b></a>
<a href="#calc_pip_price"><b><i>calc_pip_price</i></b></a>
<a href="#nav_account_set"><b><i>nav_account_set</i></b></a>
<a href="#nav_account"><b><i>nav_account</i></b></a>
<a href="#nav_instrument_name"><b><i>nav_instrument_name</i></b></a>
<a href="#nav_size_percent"><b><i>nav_size_percent</i></b></a>
<a href="#nav_size_percent_per_pip"><b><i>nav_size_percent_per_pip</i></b></a>
<a href="#nav_pnl"><b><i>nav_pnl</i></b></a>
<a href="#transaction"><b><i>transaction</i></b></a>
<a href="#transactions"><b><i>transactions</i></b></a>
<a href="#transactions_types"><b><i>transactions_types</i></b></a>
<a href="#transactions_type"><b><i>transactions_type</i></b></a>
<a href="#time_seconds"><b><i>time_seconds</i></b></a>
<a href="#gran_seconds"><b><i>gran_seconds</i></b></a>
<a href="#expiry"><b><i>expiry</i></b></a>
<a href="#expiry_min"><b><i>expiry_min</i></b></a>
<a href="#expiry_hour"><b><i>expiry_hour</i></b></a>
<a href="#expiry_day"><b><i>expiry_day</i></b></a>
<a href="#set_stop"><b><i>set_stop</i></b></a>
<a href="#set_tp"><b><i>set_tp</i></b></a>
<a href="#set_trailing_stop"><b><i>set_trailing_stop</i></b></a>
<a href="#order"><b><i>order</i></b></a>
<a href="#order_pair"><b><i>order_pair</i></b></a>
<a href="#order_open"><b><i>order_open</i></b></a>
<a href="#order_close"><b><i>order_close</i></b></a>
<a href="#order_close_all"><b><i>order_close_all</i></b></a>
<a href="#order_set"><b><i>order_set</i></b></a>
<a href="#order_set_stop"><b><i>order_set_stop</i></b></a>
<a href="#order_set_tp"><b><i>order_set_tp</i></b></a>
<a href="#order_set_trailing_stop"><b><i>order_set_trailing_stop</i></b></a>
<a href="#order_set_expiry"><b><i>order_set_expiry</i></b></a>
<a href="#order_set_units"><b><i>order_set_units</i></b></a>
<a href="#order_set_all"><b><i>order_set_all</i></b></a>
<a href="#trade"><b><i>trade</i></b></a>
<a href="#trade_pair"><b><i>trade_pair</i></b></a>
<a href="#trade_close"><b><i>trade_close</i></b></a>
<a href="#trade_close_all"><b><i>trade_close_all</i></b></a>
<a href="#trade_set"><b><i>trade_set</i></b></a>
<a href="#trade_set_stop"><b><i>trade_set_stop</i></b></a>
<a href="#trade_set_tp"><b><i>trade_set_tp</i></b></a>
<a href="#trade_set_trailing_stop"><b><i>trade_set_trailing_stop</i></b></a>
<a href="#trade_set_all"><b><i>trade_set_all</i></b></a>
<a href="#position"><b><i>position</i></b></a>
<a href="#position_pnl_pips"><b><i>position_pnl_pips</i></b></a>
<a href="#positions"><b><i>positions</i></b></a>
<a href="#position_close"><b><i>position_close</i></b></a>
<a href="#market"><b><i>market</i></b></a>
<a href="#limit"><b><i>limit</i></b></a>
<a href="#stop"><b><i>stop</i></b></a>
<a href="#mit"><b><i>mit</i></b></a>
<a href="#buy_market"><b><i>buy_market</i></b></a>
<a href="#buy_limit"><b><i>buy_limit</i></b></a>
<a href="#buy_stop"><b><i>buy_stop</i></b></a>
<a href="#buy_mit"><b><i>buy_mit</i></b></a>
<a href="#buy_bullish"><b><i>buy_bullish</i></b></a>
<a href="#sell_market"><b><i>sell_market</i></b></a>
<a href="#sell_limit"><b><i>sell_limit</i></b></a>
<a href="#sell_stop"><b><i>sell_stop</i></b></a>
<a href="#sell_mit"><b><i>sell_mit</i></b></a>
<a href="#sell_bearish"><b><i>sell_bearish</i></b></a>
<a href="#price"><b><i>price</i></b></a>
<a href="#prices"><b><i>prices</i></b></a>
<a href="#price_time"><b><i>price_time</i></b></a>
<a href="#candles"><b><i>candles</i></b></a>
<a href="#candles_time"><b><i>candles_time</i></b></a>
<a href="#candles_count"><b><i>candles_count</i></b></a>
<div id="valid">
<hr><pre><b>Function:<i>valid</i></b>(jsonObject, verbose=Optional, message=Optional)
<b>Usage:</b>
Return boolean false if object has been corrupted or has error messages/codes included</pre></div><div id="setup">
<hr><pre><b>Function:<i>setup</i></b>(server=Optional, apiKey=Optional, accountId=Optional, checkSSL = 2)
<b>Usage:</b>
Setup our enviornment variables</pre></div><div id="stream">
<hr><pre><b>Function:<i>stream</i></b>(callback, quotes = Optional, accounts = Optional)
<b>Usage:</b>
Open a stream to Oanda
$callback = function ($jsonObject) { /* { YOUR CODE } */; }
Quotes Example:
OandaWrap::stream(function ($event) { var_dump($event); }, array('EUR_USD'), FALSE);
Events Example:
OandaWrap::stream(function ($event) { var_dump($event); }, FALSE, array('12345'));
Events Example:
OandaWrap::stream(function ($event) { var_dump($event); }, array('EUR_USD'), array('12345'));
Notes:
Returning any value from the callback function (true or false) will exit the stream</pre></div><div id="account">
<hr><pre><b>Function:<i>account</i></b>(accountId)
<b>Usage:</b>
Return the information for $accountId</pre></div><div id="accounts">
<hr><pre><b>Function:<i>accounts</i></b>()
<b>Usage:</b>
Return a jsonObject of the accounts for $username </pre></div><div id="account_id">
<hr><pre><b>Function:<i>account_id</i></b>(accountName, uName)
<b>Usage:</b>
Return the accountId for $accountName</pre></div><div id="account_named">
<hr><pre><b>Function:<i>account_named</i></b>(accountName, uName)
<b>Usage:</b>
Return the information for $accountName</pre></div><div id="instruments">
<hr><pre><b>Function:<i>instruments</i></b>()
<b>Usage:</b>
Return a list of tradeable instruments for $accountId</pre></div><div id="instrument">
<hr><pre><b>Function:<i>instrument</i></b>(pair)
<b>Usage:</b>
Return instrument for named $pair</pre></div><div id="instrument_pairs">
<hr><pre><b>Function:<i>instrument_pairs</i></b>(currency)
<b>Usage:</b>
Return instruments for that correspond to $currency</pre></div><div id="instrument_name">
<hr><pre><b>Function:<i>instrument_name</i></b>(home, away)
<b>Usage:</b>
Return a proper instrument name for two currencies</pre></div><div id="instrument_split">
<hr><pre><b>Function:<i>instrument_split</i></b>(pair)
<b>Usage:</b>
Split an instrument into two currencies and return an array of them both</pre></div><div id="instrument_pip">
<hr><pre><b>Function:<i>instrument_pip</i></b>(pair)
<b>Usage:</b>
Return a floating point number declaring the pip size of $pair</pre></div><div id="convert">
<hr><pre><b>Function:<i>convert</i></b>(pairHome, pairAway, amount)
<b>Usage:</b>
Convert $amount of $pairHome to $pairAway</pre></div><div id="convert_pair">
<hr><pre><b>Function:<i>convert_pair</i></b>(pair, amount, home)
<b>Usage:</b>
Convert $amount of $pair from $home
i.e. OandaWrap::convert_pair('EUR_USD', 500, 'EUR'); Converts 500 EUR to USD
i.e. OandaWrap::convert_pair('EUR_USD', 500, 'USD'); Converts 500 USD to EUR</pre></div><div id="calc_pips">
<hr><pre><b>Function:<i>calc_pips</i></b>(pair, open, close)
<b>Usage:</b>
Return the pip difference between prices $open and $close for $pair</pre></div><div id="calc_pip_price">
<hr><pre><b>Function:<i>calc_pip_price</i></b>(pair, size, side=1)
<b>Usage:</b>
Return the cost of a single pip of $pair when $size is used</pre></div><div id="nav_account_set">
<hr><pre><b>Function:<i>nav_account_set</i></b>(accountId)
<b>Usage:</b>
Set our environment variable $account</pre></div><div id="nav_account">
<hr><pre><b>Function:<i>nav_account</i></b>(verbose=Optional)
<b>Usage:</b>
Return our environment variable account</pre></div><div id="nav_instrument_name">
<hr><pre><b>Function:<i>nav_instrument_name</i></b>(pair, index=0)
<b>Usage:</b>
Return the instrument name used to convert currency for the NAV</pre></div><div id="nav_size_percent">
<hr><pre><b>Function:<i>nav_size_percent</i></b>(pair, percent, leverage = 50)
<b>Usage:</b>
Return the value of a percentage of the NAV (Net account value)</pre></div><div id="nav_size_percent_per_pip">
<hr><pre><b>Function:<i>nav_size_percent_per_pip</i></b>(pair, riskPerPip, leverage = 50)
<b>Usage:</b>
Return the size for $pair that risks $riskPerPip every pip</pre></div><div id="nav_pnl">
<hr><pre><b>Function:<i>nav_pnl</i></b>(dollarValue=Optional)
<b>Usage:</b>
Return the pnl for account, if $dollarValue is set TRUE, return in base currency, else as %.</pre></div><div id="transaction">
<hr><pre><b>Function:<i>transaction</i></b>(transactionId)
<b>Usage:</b>
Get information on a single transaction</pre></div><div id="transactions">
<hr><pre><b>Function:<i>transactions</i></b>(number=50, pair='all')
<b>Usage:</b>
Return an object with all transactions (max 50)</pre></div><div id="transactions_types">
<hr><pre><b>Function:<i>transactions_types</i></b>(types, number=50, pair='all')
<b>Usage:</b>
Return a jsonObject with all transactions conforming to one of $types which is an array of strings</pre></div><div id="transactions_type">
<hr><pre><b>Function:<i>transactions_type</i></b>(type, number=50, pair='all')
<b>Usage:</b>
Return up to 50 transactions of $type</pre></div><div id="time_seconds">
<hr><pre><b>Function:<i>time_seconds</i></b>(time)
<b>Usage:</b>
Convert oanda time from microseconds to seconds</pre></div><div id="gran_seconds">
<hr><pre><b>Function:<i>gran_seconds</i></b>(gran)
<b>Usage:</b>
Return a the number of seconds per Oandas 'granularity'</pre></div><div id="expiry">
<hr><pre><b>Function:<i>expiry</i></b>(seconds=5)
<b>Usage:</b>
Return the Oanda compatible timestamp of time() + $seconds</pre></div><div id="expiry_min">
<hr><pre><b>Function:<i>expiry_min</i></b>(minutes=5)
<b>Usage:</b>
Return the Oanda compatible timestamo of time() + $minutes</pre></div><div id="expiry_hour">
<hr><pre><b>Function:<i>expiry_hour</i></b>(hours=1)
<b>Usage:</b>
Return the Oanda compatible timestamp of time() + $hours</pre></div><div id="expiry_day">
<hr><pre><b>Function:<i>expiry_day</i></b>(days=1)
<b>Usage:</b>
Return the Oanda compatible timestamp of time() + $days</pre></div><div id="set_stop">
<hr><pre><b>Function:<i>set_stop</i></b>(type, id, price)
<b>Usage:</b>
Set the stopLoss of an order or trade</pre></div><div id="set_tp">
<hr><pre><b>Function:<i>set_tp</i></b>(type, id, price)
<b>Usage:</b>
Set the takeProfit of an order or trade</pre></div><div id="set_trailing_stop">
<hr><pre><b>Function:<i>set_trailing_stop</i></b>(type, id, distance)
<b>Usage:</b>
Set the trailingStop of an order or trade</pre></div><div id="order">
<hr><pre><b>Function:<i>order</i></b>(orderId)
<b>Usage:</b>
Return an object with the information about $orderId</pre></div><div id="order_pair">
<hr><pre><b>Function:<i>order_pair</i></b>(pair, number=50)
<b>Usage:</b>
Get an object with all the orders for $pair</pre></div><div id="order_open">
<hr><pre><b>Function:<i>order_open</i></b>(side, units, pair, type, price=Optional, expiry=Optional, rest = Optional)
<b>Usage:</b>
Open a new order</pre></div><div id="order_close">
<hr><pre><b>Function:<i>order_close</i></b>(orderId)
<b>Usage:</b>
Close an order by Id</pre></div><div id="order_close_all">
<hr><pre><b>Function:<i>order_close_all</i></b>(pair)
<b>Usage:</b>
Close all orders in $pair</pre></div><div id="order_set">
<hr><pre><b>Function:<i>order_set</i></b>(orderId, options)
<b>Usage:</b>
Modify the parameters of an order</pre></div><div id="order_set_stop">
<hr><pre><b>Function:<i>order_set_stop</i></b>(id, price)
<b>Usage:</b>
Set the stopLoss of an order</pre></div><div id="order_set_tp">
<hr><pre><b>Function:<i>order_set_tp</i></b>(id, price)
<b>Usage:</b>
Set the takeProfit of an order</pre></div><div id="order_set_trailing_stop">
<hr><pre><b>Function:<i>order_set_trailing_stop</i></b>(id, distance)
<b>Usage:</b>
Set the trailingStop of an order</pre></div><div id="order_set_expiry">
<hr><pre><b>Function:<i>order_set_expiry</i></b>(id, time)
<b>Usage:</b>
Set the expiry of an order</pre></div><div id="order_set_units">
<hr><pre><b>Function:<i>order_set_units</i></b>(id, units)
<b>Usage:</b>
Set the units of an order</pre></div><div id="order_set_all">
<hr><pre><b>Function:<i>order_set_all</i></b>(pair, options)
<b>Usage:</b>
Modify all orders on $pair</pre></div><div id="trade">
<hr><pre><b>Function:<i>trade</i></b>(tradeId)
<b>Usage:</b>
Return an object containing information on a single pair</pre></div><div id="trade_pair">
<hr><pre><b>Function:<i>trade_pair</i></b>(pair, number=50)
<b>Usage:</b>
Return an object with all the trades on $pair</pre></div><div id="trade_close">
<hr><pre><b>Function:<i>trade_close</i></b>(tradeId)
<b>Usage:</b>
Close trade referenced by $tradeId</pre></div><div id="trade_close_all">
<hr><pre><b>Function:<i>trade_close_all</i></b>(pair)
<b>Usage:</b>
Close all trades on $pair</pre></div><div id="trade_set">
<hr><pre><b>Function:<i>trade_set</i></b>(tradeId, options)
<b>Usage:</b>
Modify attributes of a trade referenced by $tradeId</pre></div><div id="trade_set_stop">
<hr><pre><b>Function:<i>trade_set_stop</i></b>(id, price)
<b>Usage:</b>
Set the stopLoss of a trade</pre></div><div id="trade_set_tp">
<hr><pre><b>Function:<i>trade_set_tp</i></b>(id, price)
<b>Usage:</b>
Set the takeProfit of a trade</pre></div><div id="trade_set_trailing_stop">
<hr><pre><b>Function:<i>trade_set_trailing_stop</i></b>(id, distance)
<b>Usage:</b>
Set the trailingStop of a trade</pre></div><div id="trade_set_all">
<hr><pre><b>Function:<i>trade_set_all</i></b>(pair, options)
<b>Usage:</b>
Modify all trades on $pair</pre></div><div id="position">
<hr><pre><b>Function:<i>position</i></b>(pair)
<b>Usage:</b>
Return an object with the information for a single $pairs position</pre></div><div id="position_pnl_pips">
<hr><pre><b>Function:<i>position_pnl_pips</i></b>(pair)
<b>Usage:</b>
Return an int() of the calculated profit or loss for $pair in pips</pre></div><div id="positions">
<hr><pre><b>Function:<i>positions</i></b>()
<b>Usage:</b>
Return an object with all the positions for the account</pre></div><div id="position_close">
<hr><pre><b>Function:<i>position_close</i></b>(pair)
<b>Usage:</b>
Close the position for $pair</pre></div><div id="market">
<hr><pre><b>Function:<i>market</i></b>(side, units, pair, rest = Optional)
<b>Usage:</b>
Open a new @ market order</pre></div><div id="limit">
<hr><pre><b>Function:<i>limit</i></b>(side, units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Open a new limit order</pre></div><div id="stop">
<hr><pre><b>Function:<i>stop</i></b>(side, units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Open a new stop order</pre></div><div id="mit">
<hr><pre><b>Function:<i>mit</i></b>(side, units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Open a new marketIfTouched order</pre></div><div id="buy_market">
<hr><pre><b>Function:<i>buy_market</i></b>(units, pair, rest = Optional)
<b>Usage:</b>
Buy @ market</pre></div><div id="buy_limit">
<hr><pre><b>Function:<i>buy_limit</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Buy limit with expiry</pre></div><div id="buy_stop">
<hr><pre><b>Function:<i>buy_stop</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Buy stop with expiry</pre></div><div id="buy_mit">
<hr><pre><b>Function:<i>buy_mit</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Buy marketIfTouched with expiry</pre></div><div id="buy_bullish">
<hr><pre><b>Function:<i>buy_bullish</i></b>(pair, risk, stop, leverage=50)
<b>Usage:</b>
Macro: Buy $pair and limit size to equal %NAV loss over $stop pips. Then set stopLoss</pre></div><div id="sell_market">
<hr><pre><b>Function:<i>sell_market</i></b>(units, pair, rest = Optional)
<b>Usage:</b>
Sell @ market</pre></div><div id="sell_limit">
<hr><pre><b>Function:<i>sell_limit</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Sell limit with expiry</pre></div><div id="sell_stop">
<hr><pre><b>Function:<i>sell_stop</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Sell stop with expiry</pre></div><div id="sell_mit">
<hr><pre><b>Function:<i>sell_mit</i></b>(units, pair, price, expiry, rest = Optional)
<b>Usage:</b>
Sell marketIfTouched with expiry</pre></div><div id="sell_bearish">
<hr><pre><b>Function:<i>sell_bearish</i></b>(pair, risk, stop, leverage=50)
<b>Usage:</b>
Macro: Sell $pair and limit size to equal %NAV loss over $stop pips. Then set stopLoss</pre></div><div id="price">
<hr><pre><b>Function:<i>price</i></b>(pair)
<b>Usage:</b>
Wrapper, return the current price of '$pair'</pre></div><div id="prices">
<hr><pre><b>Function:<i>prices</i></b>(pairs)
<b>Usage:</b>
Return a jsonObject {prices} for {$pairs}</pre></div><div id="price_time">
<hr><pre><b>Function:<i>price_time</i></b>(pair, date)
<b>Usage:</b>
Wrapper, return the price of '$pair' at $date which is a string such as "20:15 5th november 2012"</pre></div><div id="candles">
<hr><pre><b>Function:<i>candles</i></b>(pair, gran, rest = null)
<b>Usage:</b>
Return a number of candles for '$pair'</pre></div><div id="candles_time">
<hr><pre><b>Function:<i>candles_time</i></b>(pair, gran, start, end)
<b>Usage:</b>
Return candles for '$pair' between $start and $end</pre></div><div id="candles_count">
<hr><pre><b>Function:<i>candles_count</i></b>(pair, gran, count)
<b>Usage:</b>
Return $count of the previous candles for '$pair'</pre></div></body></html>