oanda_api_v20 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +270 -0
- data/lib/oanda_api_v20/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b5d5cf2702df29602ad452b2e5ae37d15564c2f
|
4
|
+
data.tar.gz: 179e4fe0af79d0575dec2aa556ef7007e27f62cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e4b3d036323f149a1e8a9ca3f6b9f5b84ed40cde33fc266f71e5a7a50d6e6d085a19aebf2651c9495ece6aeac3fff3b67c9100c0f876b2073d8fc2dc107147
|
7
|
+
data.tar.gz: 1d1b8a51a510f72d2219641d3f167635438352216f6261cdaedab1c4438a2b4155841d3ce5a401c95bf1ce2870a72bc16f463732ac516f1522a8b855b7ca2c3c
|
data/README.md
CHANGED
@@ -1 +1,271 @@
|
|
1
1
|
# OandaApiV20
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/oanda_api_v20.svg)](https://rubygems.org/gems/oanda_api_v20)
|
4
|
+
|
5
|
+
Ruby client that supports the Oanda REST API V20 methods.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'oanda_api_v20'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install oanda_api_v20
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add the following to your ruby program:
|
24
|
+
|
25
|
+
require 'oanda_api_v20'
|
26
|
+
|
27
|
+
Initialise a client:
|
28
|
+
|
29
|
+
client = OandaApiV20.new(access_token: 'my_access_token')
|
30
|
+
|
31
|
+
If you would like to trade with your test account:
|
32
|
+
|
33
|
+
client = OandaApiV20.new(access_token: 'my_access_token', practice: true)
|
34
|
+
|
35
|
+
## Examples
|
36
|
+
|
37
|
+
### Accounts
|
38
|
+
|
39
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/account-ep/) for all available options on accounts.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
client.accounts.show
|
43
|
+
```
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client.account('account_id').show
|
47
|
+
```
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
client.account('account_id').summary.show
|
51
|
+
```
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client.account('account_id').instruments.show
|
55
|
+
```
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
client.account('account_id').changes.show
|
59
|
+
```
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
options = { alias: 'My New Account #2' }
|
63
|
+
|
64
|
+
client.account('account_id').configuration(options).update
|
65
|
+
```
|
66
|
+
|
67
|
+
### Orders
|
68
|
+
|
69
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/orders-ep/) for all available options on orders.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
client.account('account_id').orders.show
|
73
|
+
```
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
id = client.account('account_id').orders.show['orders'][0]['id']
|
77
|
+
|
78
|
+
client.account('account_id').order(id).show
|
79
|
+
```
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
options = {
|
83
|
+
'order' => {
|
84
|
+
'units' => '100',
|
85
|
+
'instrument' => 'EUR_CAD',
|
86
|
+
'timeInForce' => 'FOK',
|
87
|
+
'type' => 'MARKET',
|
88
|
+
'positionFill' => 'DEFAULT'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
client.account('account_id').order(options).create
|
93
|
+
```
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
id = client.account('account_id').orders.show['orders'][0]['id']
|
97
|
+
|
98
|
+
options = {
|
99
|
+
'order' => {
|
100
|
+
'timeInForce' => 'GTC',
|
101
|
+
'price' => '1.7000',
|
102
|
+
'type' => 'TAKE_PROFIT',
|
103
|
+
'tradeID' => '1'
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
client.account('account_id').order(id, options).update
|
108
|
+
```
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
id = client.account('account_id').orders.show['orders'][0]['id']
|
112
|
+
|
113
|
+
client.account('account_id').order(id).cancel
|
114
|
+
```
|
115
|
+
|
116
|
+
### Trades
|
117
|
+
|
118
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/trades-ep/) for all available options on trades.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
options = { 'instrument' => 'USD_CAD' }
|
122
|
+
|
123
|
+
client.account('account_id').trades(options).show
|
124
|
+
```
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
client.account('account_id').open_trades.show
|
128
|
+
```
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
132
|
+
|
133
|
+
client.account('account_id').trade(id).show
|
134
|
+
```
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
138
|
+
|
139
|
+
options = {
|
140
|
+
'clientExtensions' => {
|
141
|
+
'comment' => 'This is a USD/CAD trade',
|
142
|
+
'tag' => 'trade tag',
|
143
|
+
'id' => 'my_usd_cad_trade'
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
client.account('account_id').trade(id, options).update
|
148
|
+
```
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
152
|
+
|
153
|
+
options = {
|
154
|
+
'takeProfit' => {
|
155
|
+
'timeInForce' => 'GTC',
|
156
|
+
'price' => '0.5'
|
157
|
+
},
|
158
|
+
'stopLoss': {
|
159
|
+
'timeInForce' => 'GTC',
|
160
|
+
'price' => '2.5'
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
client.account('account_id').trade(id, options).update
|
165
|
+
```
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
169
|
+
|
170
|
+
options = { 'units' => '10' }
|
171
|
+
|
172
|
+
client.account('account_id').trade(id, options).close
|
173
|
+
```
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
177
|
+
|
178
|
+
client.account('account_id').trade(id).close
|
179
|
+
```
|
180
|
+
|
181
|
+
### Positions
|
182
|
+
|
183
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/positions-ep/) for all available options on positions.
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
client.account('account_id').positions.show
|
187
|
+
```
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
client.account('account_id').open_positions.show
|
191
|
+
```
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
client.account('account_id').position('EUR_USD').show
|
195
|
+
```
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
options = { 'longUnits' => 'ALL' }
|
199
|
+
|
200
|
+
client.account('account_id').position('EUR_CAD', options).close
|
201
|
+
```
|
202
|
+
|
203
|
+
### Transactions
|
204
|
+
|
205
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/transactions-ep/) for all available options on transactions.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
client.account('account_id').transactions.show
|
209
|
+
```
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
options = {
|
213
|
+
'from' => '2016-08-01T02:00:00Z',
|
214
|
+
'to' => '2016-08-15T02:00:00Z'
|
215
|
+
}
|
216
|
+
|
217
|
+
client.account('account_id').transactions(options).show
|
218
|
+
```
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
id = 6410
|
222
|
+
|
223
|
+
client.account('account_id').transaction(id).show
|
224
|
+
```
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
options = {
|
228
|
+
'from' => '6409',
|
229
|
+
'to' => '6412'
|
230
|
+
}
|
231
|
+
|
232
|
+
client.account('account_id').transactions_id_range(options).show
|
233
|
+
```
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
options = {
|
237
|
+
'id' => '6411'
|
238
|
+
}
|
239
|
+
|
240
|
+
client.account('account_id').transactions_since_id(options).show
|
241
|
+
```
|
242
|
+
|
243
|
+
### Pricing
|
244
|
+
|
245
|
+
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/pricing-ep/) for all available options on pricing.
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
options = {
|
249
|
+
'instruments' => 'EUR_USD,USD_CAD'
|
250
|
+
}
|
251
|
+
|
252
|
+
client.account('account_id').pricing(options).show
|
253
|
+
```
|
254
|
+
|
255
|
+
## Contributing
|
256
|
+
|
257
|
+
1. Fork it
|
258
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
259
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
260
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
261
|
+
5. Create new Pull Request
|
262
|
+
|
263
|
+
## TODO
|
264
|
+
|
265
|
+
There are still a lot to be added to this gem:
|
266
|
+
|
267
|
+
- Unit tests using RSpec.
|
268
|
+
- Persistent connections using persistent_httparty.
|
269
|
+
- No more than 2 connections per second.
|
270
|
+
- Limit to 30 requests per second.
|
271
|
+
- ...
|