oanda_api 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/.gitignore +38 -0
  2. data/.rspec_non_jruby +2 -0
  3. data/.yardopts +6 -0
  4. data/Gemfile +13 -0
  5. data/Guardfile +7 -0
  6. data/LICENSE +22 -0
  7. data/README.md +218 -0
  8. data/Rakefile +23 -0
  9. data/lib/oanda_api.rb +25 -0
  10. data/lib/oanda_api/client/client.rb +175 -0
  11. data/lib/oanda_api/client/namespace_proxy.rb +112 -0
  12. data/lib/oanda_api/client/resource_descriptor.rb +52 -0
  13. data/lib/oanda_api/client/token_client.rb +69 -0
  14. data/lib/oanda_api/client/username_client.rb +53 -0
  15. data/lib/oanda_api/configuration.rb +167 -0
  16. data/lib/oanda_api/errors.rb +4 -0
  17. data/lib/oanda_api/resource/account.rb +37 -0
  18. data/lib/oanda_api/resource/candle.rb +29 -0
  19. data/lib/oanda_api/resource/instrument.rb +21 -0
  20. data/lib/oanda_api/resource/order.rb +74 -0
  21. data/lib/oanda_api/resource/position.rb +18 -0
  22. data/lib/oanda_api/resource/price.rb +16 -0
  23. data/lib/oanda_api/resource/trade.rb +23 -0
  24. data/lib/oanda_api/resource/transaction.rb +67 -0
  25. data/lib/oanda_api/resource_base.rb +35 -0
  26. data/lib/oanda_api/resource_collection.rb +77 -0
  27. data/lib/oanda_api/utils/utils.rb +101 -0
  28. data/lib/oanda_api/version.rb +3 -0
  29. data/oanda_api.gemspec +32 -0
  30. data/spec/fixtures/vcr_cassettes/account_id_order_id_close.yml +264 -0
  31. data/spec/fixtures/vcr_cassettes/account_id_order_id_get.yml +114 -0
  32. data/spec/fixtures/vcr_cassettes/account_id_order_options_create.yml +74 -0
  33. data/spec/fixtures/vcr_cassettes/account_id_order_options_update.yml +112 -0
  34. data/spec/fixtures/vcr_cassettes/account_id_orders_get.yml +118 -0
  35. data/spec/fixtures/vcr_cassettes/account_id_orders_options_get.yml +123 -0
  36. data/spec/fixtures/vcr_cassettes/account_id_positions_get.yml +112 -0
  37. data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_close.yml +214 -0
  38. data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_get.yml +110 -0
  39. data/spec/fixtures/vcr_cassettes/account_id_trade_id_close.yml +252 -0
  40. data/spec/fixtures/vcr_cassettes/account_id_trade_id_get.yml +112 -0
  41. data/spec/fixtures/vcr_cassettes/account_id_trade_options_modify.yml +110 -0
  42. data/spec/fixtures/vcr_cassettes/account_id_trades_filter_get.yml +118 -0
  43. data/spec/fixtures/vcr_cassettes/account_id_trades_get.yml +118 -0
  44. data/spec/fixtures/vcr_cassettes/account_id_transaction_id_get.yml +283 -0
  45. data/spec/fixtures/vcr_cassettes/account_id_transactions_options_get.yml +205 -0
  46. data/spec/fixtures/vcr_cassettes/accounts_create.yml +75 -0
  47. data/spec/fixtures/vcr_cassettes/accounts_get.yml +111 -0
  48. data/spec/fixtures/vcr_cassettes/accounts_id_get.yml +187 -0
  49. data/spec/fixtures/vcr_cassettes/candles_options_get.yml +79 -0
  50. data/spec/fixtures/vcr_cassettes/instruments_get.yml +501 -0
  51. data/spec/fixtures/vcr_cassettes/instruments_options_get.yml +81 -0
  52. data/spec/fixtures/vcr_cassettes/prices_options_get.yml +81 -0
  53. data/spec/fixtures/vcr_cassettes/sandbox_client.yml +116 -0
  54. data/spec/fixtures/vcr_cassettes/sandbox_client_account.yml +111 -0
  55. data/spec/fixtures/vcr_cassettes/sandbox_instrument_EUR_USD.yml +77 -0
  56. data/spec/oanda_api/client/client_spec.rb +107 -0
  57. data/spec/oanda_api/client/namespace_proxy_spec.rb +16 -0
  58. data/spec/oanda_api/client/resource_descriptor_spec.rb +39 -0
  59. data/spec/oanda_api/client/token_client_spec.rb +60 -0
  60. data/spec/oanda_api/client/username_client_spec.rb +31 -0
  61. data/spec/oanda_api/configuration_spec.rb +138 -0
  62. data/spec/oanda_api/examples/accounts_spec.rb +28 -0
  63. data/spec/oanda_api/examples/orders_spec.rb +68 -0
  64. data/spec/oanda_api/examples/positions_spec.rb +38 -0
  65. data/spec/oanda_api/examples/rates_spec.rb +46 -0
  66. data/spec/oanda_api/examples/trades_spec.rb +58 -0
  67. data/spec/oanda_api/examples/transactions_spec.rb +24 -0
  68. data/spec/oanda_api/resource_collection_spec.rb +109 -0
  69. data/spec/oanda_api/utils/utils_spec.rb +109 -0
  70. data/spec/spec_helper.rb +10 -0
  71. data/spec/support/client_helper.rb +60 -0
  72. data/spec/support/vcr.rb +7 -0
  73. metadata +124 -9
@@ -0,0 +1,75 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api-sandbox.oanda.com/v1/accounts
6
+ body:
7
+ encoding: UTF-8
8
+ string: username=dwaymotim
9
+ headers:
10
+ X-Accept-Datetime-Format:
11
+ - RFC3339
12
+ Connection:
13
+ - keep-alive
14
+ Keep-Alive:
15
+ - 30
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: CREATED
20
+ headers:
21
+ Server:
22
+ - openresty/1.7.0.1
23
+ Date:
24
+ - Tue, 20 Jan 2015 17:22:26 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '77'
29
+ Connection:
30
+ - keep-alive
31
+ Location:
32
+ - http://api-sandbox.oanda.com/v1/accounts/7079317
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"username\" : \"shenry\",\n\t\"password\" : \"heewgUjEd\",\n\t\"accountId\"
36
+ : 7079317\n}"
37
+ http_version:
38
+ recorded_at: Tue, 20 Jan 2015 17:22:28 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://api-sandbox.oanda.com/v1/accounts/
42
+ body:
43
+ encoding: UTF-8
44
+ string: username=paudougles
45
+ headers:
46
+ X-Accept-Datetime-Format:
47
+ - RFC3339
48
+ Connection:
49
+ - keep-alive
50
+ Keep-Alive:
51
+ - 30
52
+ response:
53
+ status:
54
+ code: 201
55
+ message: CREATED
56
+ headers:
57
+ Server:
58
+ - openresty/1.7.0.1
59
+ Date:
60
+ - Tue, 20 Jan 2015 23:27:03 GMT
61
+ Content-Type:
62
+ - application/json
63
+ Content-Length:
64
+ - '79'
65
+ Connection:
66
+ - keep-alive
67
+ Location:
68
+ - http://api-sandbox.oanda.com/v1/accounts/2107190
69
+ body:
70
+ encoding: UTF-8
71
+ string: "{\n\t\"username\" : \"flouglee\",\n\t\"password\" : \"1Swasyof9\",\n\t\"accountId\"
72
+ : 2107190\n}"
73
+ http_version:
74
+ recorded_at: Tue, 20 Jan 2015 23:27:03 GMT
75
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,111 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/accounts?username=dwaymotim
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Accept-Datetime-Format:
11
+ - RFC3339
12
+ Connection:
13
+ - keep-alive
14
+ Keep-Alive:
15
+ - 30
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - openresty/1.7.0.1
23
+ Date:
24
+ - Tue, 20 Jan 2015 17:22:27 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '139'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"2c8bda3c0aced2c86025961c4e2da0452332ea36"'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"accounts\" : [\n\t\t{\n\t\t\t\"accountId\" : 5342358,\n\t\t\t\"accountName\"
36
+ : \"Primary\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\"
37
+ : 0.05\n\t\t}\n\t]\n}"
38
+ http_version:
39
+ recorded_at: Tue, 20 Jan 2015 17:22:29 GMT
40
+ - request:
41
+ method: get
42
+ uri: http://api-sandbox.oanda.com/v1/accounts/?username=paudougles
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ''
46
+ headers:
47
+ X-Accept-Datetime-Format:
48
+ - RFC3339
49
+ Connection:
50
+ - keep-alive
51
+ Keep-Alive:
52
+ - 30
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Server:
59
+ - openresty/1.7.0.1
60
+ Date:
61
+ - Tue, 20 Jan 2015 23:27:03 GMT
62
+ Content-Type:
63
+ - application/json
64
+ Content-Length:
65
+ - '139'
66
+ Connection:
67
+ - keep-alive
68
+ Etag:
69
+ - '"61cce213956060b4ccb6fd9f47235b4c03e74095"'
70
+ body:
71
+ encoding: UTF-8
72
+ string: "{\n\t\"accounts\" : [\n\t\t{\n\t\t\t\"accountId\" : 1724176,\n\t\t\t\"accountName\"
73
+ : \"Primary\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\"
74
+ : 0.05\n\t\t}\n\t]\n}"
75
+ http_version:
76
+ recorded_at: Tue, 20 Jan 2015 23:27:03 GMT
77
+ - request:
78
+ method: get
79
+ uri: http://api-sandbox.oanda.com/v1/accounts?username
80
+ body:
81
+ encoding: US-ASCII
82
+ string: ''
83
+ headers:
84
+ X-Accept-Datetime-Format:
85
+ - RFC3339
86
+ Connection:
87
+ - keep-alive
88
+ Keep-Alive:
89
+ - 30
90
+ response:
91
+ status:
92
+ code: 404
93
+ message: NOT_FOUND
94
+ headers:
95
+ Server:
96
+ - openresty/1.7.0.1
97
+ Date:
98
+ - Fri, 23 Jan 2015 17:37:52 GMT
99
+ Content-Type:
100
+ - application/json
101
+ Content-Length:
102
+ - '144'
103
+ Connection:
104
+ - keep-alive
105
+ body:
106
+ encoding: UTF-8
107
+ string: "{\n\t\"code\" : 55,\n\t\"message\" : \"Username specified is invalid\",\n\t\"moreInfo\"
108
+ : \"http:\\/\\/developer.oanda.com\\/docs\\/v1\\/troubleshooting\\/#errors\"\n}"
109
+ http_version:
110
+ recorded_at: Fri, 23 Jan 2015 17:37:52 GMT
111
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,187 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/accounts?username=dwaymotim
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Accept-Datetime-Format:
11
+ - RFC3339
12
+ Connection:
13
+ - keep-alive
14
+ Keep-Alive:
15
+ - 30
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - openresty/1.7.0.1
23
+ Date:
24
+ - Tue, 20 Jan 2015 17:22:27 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '139'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"2c8bda3c0aced2c86025961c4e2da0452332ea36"'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"accounts\" : [\n\t\t{\n\t\t\t\"accountId\" : 5342358,\n\t\t\t\"accountName\"
36
+ : \"Primary\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\"
37
+ : 0.05\n\t\t}\n\t]\n}"
38
+ http_version:
39
+ recorded_at: Tue, 20 Jan 2015 17:22:29 GMT
40
+ - request:
41
+ method: get
42
+ uri: http://api-sandbox.oanda.com/v1/accounts/5342358?username=dwaymotim
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ''
46
+ headers:
47
+ X-Accept-Datetime-Format:
48
+ - RFC3339
49
+ Connection:
50
+ - keep-alive
51
+ Keep-Alive:
52
+ - 30
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Server:
59
+ - openresty/1.7.0.1
60
+ Date:
61
+ - Tue, 20 Jan 2015 17:22:27 GMT
62
+ Content-Type:
63
+ - application/json
64
+ Content-Length:
65
+ - '247'
66
+ Connection:
67
+ - keep-alive
68
+ Etag:
69
+ - '"52b4908f3477c81c8c80224512bc0715f21deaf4"'
70
+ body:
71
+ encoding: UTF-8
72
+ string: "{\n\t\"accountId\" : 5342358,\n\t\"accountName\" : \"Primary\",\n\t\"balance\"
73
+ : 100000,\n\t\"unrealizedPl\" : 0,\n\t\"realizedPl\" : 0,\n\t\"marginUsed\"
74
+ : 0,\n\t\"marginAvail\" : 100000,\n\t\"openTrades\" : 0,\n\t\"openOrders\"
75
+ : 0,\n\t\"marginRate\" : 0.05,\n\t\"accountCurrency\" : \"USD\"\n}"
76
+ http_version:
77
+ recorded_at: Tue, 20 Jan 2015 17:22:29 GMT
78
+ - request:
79
+ method: get
80
+ uri: http://api-sandbox.oanda.com/v1/accounts/?username=paudougles
81
+ body:
82
+ encoding: US-ASCII
83
+ string: ''
84
+ headers:
85
+ X-Accept-Datetime-Format:
86
+ - RFC3339
87
+ Connection:
88
+ - keep-alive
89
+ Keep-Alive:
90
+ - 30
91
+ response:
92
+ status:
93
+ code: 200
94
+ message: OK
95
+ headers:
96
+ Server:
97
+ - openresty/1.7.0.1
98
+ Date:
99
+ - Tue, 20 Jan 2015 23:27:04 GMT
100
+ Content-Type:
101
+ - application/json
102
+ Content-Length:
103
+ - '139'
104
+ Connection:
105
+ - keep-alive
106
+ Etag:
107
+ - '"61cce213956060b4ccb6fd9f47235b4c03e74095"'
108
+ body:
109
+ encoding: UTF-8
110
+ string: "{\n\t\"accounts\" : [\n\t\t{\n\t\t\t\"accountId\" : 1724176,\n\t\t\t\"accountName\"
111
+ : \"Primary\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\"
112
+ : 0.05\n\t\t}\n\t]\n}"
113
+ http_version:
114
+ recorded_at: Tue, 20 Jan 2015 23:27:03 GMT
115
+ - request:
116
+ method: get
117
+ uri: http://api-sandbox.oanda.com/v1/accounts/1724176?username=paudougles
118
+ body:
119
+ encoding: US-ASCII
120
+ string: ''
121
+ headers:
122
+ X-Accept-Datetime-Format:
123
+ - RFC3339
124
+ Connection:
125
+ - keep-alive
126
+ Keep-Alive:
127
+ - 30
128
+ response:
129
+ status:
130
+ code: 200
131
+ message: OK
132
+ headers:
133
+ Server:
134
+ - openresty/1.7.0.1
135
+ Date:
136
+ - Tue, 20 Jan 2015 23:27:04 GMT
137
+ Content-Type:
138
+ - application/json
139
+ Content-Length:
140
+ - '247'
141
+ Connection:
142
+ - keep-alive
143
+ Etag:
144
+ - '"83c3b001199921bd888ca07ddf04539617fe4a63"'
145
+ body:
146
+ encoding: UTF-8
147
+ string: "{\n\t\"accountId\" : 1724176,\n\t\"accountName\" : \"Primary\",\n\t\"balance\"
148
+ : 100000,\n\t\"unrealizedPl\" : 0,\n\t\"realizedPl\" : 0,\n\t\"marginUsed\"
149
+ : 0,\n\t\"marginAvail\" : 100000,\n\t\"openTrades\" : 0,\n\t\"openOrders\"
150
+ : 0,\n\t\"marginRate\" : 0.05,\n\t\"accountCurrency\" : \"USD\"\n}"
151
+ http_version:
152
+ recorded_at: Tue, 20 Jan 2015 23:27:04 GMT
153
+ - request:
154
+ method: get
155
+ uri: http://api-sandbox.oanda.com/v1/accounts?username
156
+ body:
157
+ encoding: US-ASCII
158
+ string: ''
159
+ headers:
160
+ X-Accept-Datetime-Format:
161
+ - RFC3339
162
+ Connection:
163
+ - keep-alive
164
+ Keep-Alive:
165
+ - 30
166
+ response:
167
+ status:
168
+ code: 404
169
+ message: NOT_FOUND
170
+ headers:
171
+ Server:
172
+ - openresty/1.7.0.1
173
+ Date:
174
+ - Fri, 23 Jan 2015 17:37:52 GMT
175
+ Content-Type:
176
+ - application/json
177
+ Content-Length:
178
+ - '144'
179
+ Connection:
180
+ - keep-alive
181
+ body:
182
+ encoding: UTF-8
183
+ string: "{\n\t\"code\" : 55,\n\t\"message\" : \"Username specified is invalid\",\n\t\"moreInfo\"
184
+ : \"http:\\/\\/developer.oanda.com\\/docs\\/v1\\/troubleshooting\\/#errors\"\n}"
185
+ http_version:
186
+ recorded_at: Fri, 23 Jan 2015 17:37:53 GMT
187
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,79 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/candles?candleFormat=midpoint&count=1&granularity=M1&instrument=EUR_USD&username=dwaymotim
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Accept-Datetime-Format:
11
+ - RFC3339
12
+ Connection:
13
+ - keep-alive
14
+ Keep-Alive:
15
+ - 30
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - openresty/1.7.0.1
23
+ Date:
24
+ - Tue, 20 Jan 2015 17:22:31 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '257'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"91138a61742f1acf37e141ebabd730c909d2bd6f"'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"instrument\" : \"EUR_USD\",\n\t\"granularity\" : \"M1\",\n\t\"candles\"
36
+ : [\n\t\t{\n\t\t\t\"time\" : \"2015-01-20T17:21:00.000000Z\",\n\t\t\t\"openMid\"
37
+ : 1.24095,\n\t\t\t\"highMid\" : 1.24095,\n\t\t\t\"lowMid\" : 1.24095,\n\t\t\t\"closeMid\"
38
+ : 1.24095,\n\t\t\t\"volume\" : 1,\n\t\t\t\"complete\" : false\n\t\t}\n\t]\n}"
39
+ http_version:
40
+ recorded_at: Tue, 20 Jan 2015 17:22:34 GMT
41
+ - request:
42
+ method: get
43
+ uri: http://api-sandbox.oanda.com/v1/candles?candleFormat=midpoint&count=1&granularity=M1&instrument=EUR_USD&username
44
+ body:
45
+ encoding: US-ASCII
46
+ string: ''
47
+ headers:
48
+ X-Accept-Datetime-Format:
49
+ - RFC3339
50
+ Connection:
51
+ - keep-alive
52
+ Keep-Alive:
53
+ - 30
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Server:
60
+ - openresty/1.7.0.1
61
+ Date:
62
+ - Fri, 23 Jan 2015 17:37:54 GMT
63
+ Content-Type:
64
+ - application/json
65
+ Content-Length:
66
+ - '259'
67
+ Connection:
68
+ - keep-alive
69
+ Etag:
70
+ - '"ddcad30954a705da9c3a47886df47ab4e20bed99"'
71
+ body:
72
+ encoding: UTF-8
73
+ string: "{\n\t\"instrument\" : \"EUR_USD\",\n\t\"granularity\" : \"M1\",\n\t\"candles\"
74
+ : [\n\t\t{\n\t\t\t\"time\" : \"2015-01-23T17:37:00.000000Z\",\n\t\t\t\"openMid\"
75
+ : 1.240555,\n\t\t\t\"highMid\" : 1.24057,\n\t\t\t\"lowMid\" : 1.24039,\n\t\t\t\"closeMid\"
76
+ : 1.24039,\n\t\t\t\"volume\" : 29,\n\t\t\t\"complete\" : false\n\t\t}\n\t]\n}"
77
+ http_version:
78
+ recorded_at: Fri, 23 Jan 2015 17:37:54 GMT
79
+ recorded_with: VCR 2.9.3