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,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/instruments?fields=pip,precision&instruments=EUR_USD,EUR_CAD&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
+ - '196'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"3a3c61c7d6d86ef8c92f59e4020f39d07e2e5b2f"'
33
+ Expires:
34
+ - Wed, 21 January 2015 17:22:31 GMT
35
+ body:
36
+ encoding: UTF-8
37
+ string: "{\n\t\"instruments\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"pip\"
38
+ : \"0.0001\",\n\t\t\t\"precision\" : \"0.00001\"\n\t\t},\n\t\t{\n\t\t\t\"instrument\"
39
+ : \"EUR_CAD\",\n\t\t\t\"pip\" : \"0.0001\",\n\t\t\t\"precision\" : \"0.00001\"\n\t\t}\n\t]\n}"
40
+ http_version:
41
+ recorded_at: Tue, 20 Jan 2015 17:22:33 GMT
42
+ - request:
43
+ method: get
44
+ uri: http://api-sandbox.oanda.com/v1/instruments?fields=pip,precision&instruments=EUR_USD,EUR_CAD&username
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ''
48
+ headers:
49
+ X-Accept-Datetime-Format:
50
+ - RFC3339
51
+ Connection:
52
+ - keep-alive
53
+ Keep-Alive:
54
+ - 30
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Server:
61
+ - openresty/1.7.0.1
62
+ Date:
63
+ - Fri, 23 Jan 2015 17:37:54 GMT
64
+ Content-Type:
65
+ - application/json
66
+ Content-Length:
67
+ - '196'
68
+ Connection:
69
+ - keep-alive
70
+ Etag:
71
+ - '"3a3c61c7d6d86ef8c92f59e4020f39d07e2e5b2f"'
72
+ Expires:
73
+ - Sat, 24 January 2015 17:37:54 GMT
74
+ body:
75
+ encoding: UTF-8
76
+ string: "{\n\t\"instruments\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"pip\"
77
+ : \"0.0001\",\n\t\t\t\"precision\" : \"0.00001\"\n\t\t},\n\t\t{\n\t\t\t\"instrument\"
78
+ : \"EUR_CAD\",\n\t\t\t\"pip\" : \"0.0001\",\n\t\t\t\"precision\" : \"0.00001\"\n\t\t}\n\t]\n}"
79
+ http_version:
80
+ recorded_at: Fri, 23 Jan 2015 17:37:54 GMT
81
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,81 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD,EUR_CAD&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
+ - '258'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"bb3bee85840ca7561196c2e00d0341e667a40188"'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
36
+ : \"2015-01-20T17:21:05.832175Z\",\n\t\t\t\"bid\" : 1.24089,\n\t\t\t\"ask\"
37
+ : 1.24101\n\t\t},\n\t\t{\n\t\t\t\"instrument\" : \"EUR_CAD\",\n\t\t\t\"time\"
38
+ : \"2015-01-20T17:20:59.875130Z\",\n\t\t\t\"bid\" : 1.4188,\n\t\t\t\"ask\"
39
+ : 1.41906\n\t\t}\n\t]\n}"
40
+ http_version:
41
+ recorded_at: Tue, 20 Jan 2015 17:22:34 GMT
42
+ - request:
43
+ method: get
44
+ uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD,EUR_CAD&username
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ''
48
+ headers:
49
+ X-Accept-Datetime-Format:
50
+ - RFC3339
51
+ Connection:
52
+ - keep-alive
53
+ Keep-Alive:
54
+ - 30
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Server:
61
+ - openresty/1.7.0.1
62
+ Date:
63
+ - Fri, 23 Jan 2015 17:37:54 GMT
64
+ Content-Type:
65
+ - application/json
66
+ Content-Length:
67
+ - '258'
68
+ Connection:
69
+ - keep-alive
70
+ Etag:
71
+ - '"61b0cfa4b3f60f7fcf1bce3089bbf5a7b706d340"'
72
+ body:
73
+ encoding: UTF-8
74
+ string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
75
+ : \"2015-01-23T17:37:49.093636Z\",\n\t\t\t\"bid\" : 1.2403,\n\t\t\t\"ask\"
76
+ : 1.24048\n\t\t},\n\t\t{\n\t\t\t\"instrument\" : \"EUR_CAD\",\n\t\t\t\"time\"
77
+ : \"2015-01-23T17:37:48.869787Z\",\n\t\t\t\"bid\" : 1.41832,\n\t\t\t\"ask\"
78
+ : 1.41855\n\t\t}\n\t]\n}"
79
+ http_version:
80
+ recorded_at: Fri, 23 Jan 2015 17:37:54 GMT
81
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,116 @@
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=_
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:25 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '79'
29
+ Connection:
30
+ - keep-alive
31
+ Location:
32
+ - http://api-sandbox.oanda.com/v1/accounts/5342358
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"username\" : \"dwaymotim\",\n\t\"password\" : \"hoHahaHu\",\n\t\"accountId\"
36
+ : 5342358\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/v1account
42
+ body:
43
+ encoding: UTF-8
44
+ string: username=_
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: 404
55
+ message: Not Found
56
+ headers:
57
+ Server:
58
+ - openresty/1.7.0.1
59
+ Date:
60
+ - Tue, 20 Jan 2015 21:20:26 GMT
61
+ Content-Type:
62
+ - application/json
63
+ Content-Length:
64
+ - '170'
65
+ Connection:
66
+ - keep-alive
67
+ Etag:
68
+ - '"53f4b7f5-aa"'
69
+ body:
70
+ encoding: UTF-8
71
+ string: |+
72
+ {
73
+ "code" : 38,
74
+ "message" : "No matching handler for the request is found",
75
+ "moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/troubleshooting\/#errors"
76
+ }
77
+
78
+ http_version:
79
+ recorded_at: Tue, 20 Jan 2015 21:20:26 GMT
80
+ - request:
81
+ method: post
82
+ uri: http://api-sandbox.oanda.com/v1/accounts/
83
+ body:
84
+ encoding: UTF-8
85
+ string: username=_
86
+ headers:
87
+ X-Accept-Datetime-Format:
88
+ - RFC3339
89
+ Connection:
90
+ - keep-alive
91
+ Keep-Alive:
92
+ - 30
93
+ response:
94
+ status:
95
+ code: 201
96
+ message: CREATED
97
+ headers:
98
+ Server:
99
+ - openresty/1.7.0.1
100
+ Date:
101
+ - Tue, 20 Jan 2015 23:27:03 GMT
102
+ Content-Type:
103
+ - application/json
104
+ Content-Length:
105
+ - '82'
106
+ Connection:
107
+ - keep-alive
108
+ Location:
109
+ - http://api-sandbox.oanda.com/v1/accounts/1724176
110
+ body:
111
+ encoding: UTF-8
112
+ string: "{\n\t\"username\" : \"paudougles\",\n\t\"password\" : \"AtIrgElCyp\",\n\t\"accountId\"
113
+ : 1724176\n}"
114
+ http_version:
115
+ recorded_at: Tue, 20 Jan 2015 23:27:02 GMT
116
+ 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:05 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:05 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:53 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:53 GMT
111
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,77 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api-sandbox.oanda.com/v1/prices?instruments=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:27 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '139'
29
+ Connection:
30
+ - keep-alive
31
+ Etag:
32
+ - '"4c7f5d9d4c94c9bf6cdadb72776e76f6427cf98e"'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
36
+ : \"2015-01-20T17:21:05.832175Z\",\n\t\t\t\"bid\" : 1.24089,\n\t\t\t\"ask\"
37
+ : 1.24101\n\t\t}\n\t]\n}"
38
+ http_version:
39
+ recorded_at: Tue, 20 Jan 2015 17:22:30 GMT
40
+ - request:
41
+ method: get
42
+ uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username
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
+ - Fri, 23 Jan 2015 17:37:53 GMT
62
+ Content-Type:
63
+ - application/json
64
+ Content-Length:
65
+ - '138'
66
+ Connection:
67
+ - keep-alive
68
+ Etag:
69
+ - '"16d16d0147a57d698b64bb4f5c784e4cc0256695"'
70
+ body:
71
+ encoding: UTF-8
72
+ string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
73
+ : \"2015-01-23T17:37:49.093636Z\",\n\t\t\t\"bid\" : 1.2403,\n\t\t\t\"ask\"
74
+ : 1.24048\n\t\t}\n\t]\n}"
75
+ http_version:
76
+ recorded_at: Fri, 23 Jan 2015 17:37:53 GMT
77
+ recorded_with: VCR 2.9.3