oanda_api 0.9.4 → 0.9.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +67 -6
- data/README.md +31 -3
- data/lib/oanda_api.rb +3 -1
- data/lib/oanda_api/client/client.rb +17 -12
- data/lib/oanda_api/client/namespace_proxy.rb +2 -2
- data/lib/oanda_api/client/resource_descriptor.rb +25 -9
- data/lib/oanda_api/client/username_client.rb +7 -0
- data/lib/oanda_api/configuration.rb +14 -0
- data/lib/oanda_api/resource/account.rb +22 -3
- data/lib/oanda_api/resource/candle.rb +1 -1
- data/lib/oanda_api/resource/labs/calendar_event.rb +25 -0
- data/lib/oanda_api/resource/labs/spread_history.rb +61 -0
- data/lib/oanda_api/resource/order.rb +4 -4
- data/lib/oanda_api/resource/transaction_history.rb +0 -1
- data/lib/oanda_api/resource_base.rb +64 -2
- data/lib/oanda_api/resource_collection.rb +6 -0
- data/lib/oanda_api/streaming/client.rb +1 -0
- data/lib/oanda_api/version.rb +1 -1
- data/oanda_api.gemspec +2 -2
- data/spec/fixtures/vcr_cassettes/accounts_get.yml +13 -79
- data/spec/fixtures/vcr_cassettes/accounts_id_get.yml +23 -125
- data/spec/fixtures/vcr_cassettes/calendar_events_period_get.yml +54 -0
- data/spec/fixtures/vcr_cassettes/calendar_instrument_and_period_get.yml +61 -0
- data/spec/fixtures/vcr_cassettes/calendar_period_get.yml +54 -0
- data/spec/fixtures/vcr_cassettes/candles_options_get.yml +9 -45
- data/spec/fixtures/vcr_cassettes/client_helper_account.yml +45 -0
- data/spec/fixtures/vcr_cassettes/client_helper_accounts.yml +45 -0
- data/spec/fixtures/vcr_cassettes/instrument_EUR_USD.yml +42 -0
- data/spec/fixtures/vcr_cassettes/instrument_USD_JPY.yml +42 -0
- data/spec/fixtures/vcr_cassettes/instruments_get.yml +37 -303
- data/spec/fixtures/vcr_cassettes/instruments_options_get.yml +6 -43
- data/spec/fixtures/vcr_cassettes/order_id_close.yml +448 -0
- data/spec/fixtures/vcr_cassettes/order_id_get.yml +84 -0
- data/spec/fixtures/vcr_cassettes/order_options_create.yml +42 -0
- data/spec/fixtures/vcr_cassettes/order_options_update.yml +82 -0
- data/spec/fixtures/vcr_cassettes/orders_get.yml +205 -0
- data/spec/fixtures/vcr_cassettes/orders_options_get.yml +120 -0
- data/spec/fixtures/vcr_cassettes/positions_get.yml +82 -0
- data/spec/fixtures/vcr_cassettes/positions_instrument_close.yml +154 -0
- data/spec/fixtures/vcr_cassettes/{account_id_order_options_create.yml → positions_instrument_get.yml} +24 -18
- data/spec/fixtures/vcr_cassettes/prices_options_get.yml +11 -48
- data/spec/fixtures/vcr_cassettes/spread_history_get.yml +53 -0
- data/spec/fixtures/vcr_cassettes/spreads_get.yml +53 -0
- data/spec/fixtures/vcr_cassettes/trade_id_close.yml +277 -0
- data/spec/fixtures/vcr_cassettes/trade_id_get.yml +82 -0
- data/spec/fixtures/vcr_cassettes/trade_options_modify.yml +80 -0
- data/spec/fixtures/vcr_cassettes/trades_filter_get.yml +90 -0
- data/spec/fixtures/vcr_cassettes/trades_get.yml +171 -0
- data/spec/fixtures/vcr_cassettes/transaction_id_get.yml +248 -0
- data/spec/fixtures/vcr_cassettes/transactions_options_get.yml +202 -0
- data/spec/fixtures/vcr_cassettes/with_throttling_and_max_requests_per_second.yml +25 -19
- data/spec/fixtures/vcr_cassettes/with_throttling_with_multiple_threads.yml +51 -39
- data/spec/fixtures/vcr_cassettes/without_throttling.yml +81 -61
- data/spec/oanda_api/client/client_spec.rb +23 -10
- data/spec/oanda_api/client/namespace_proxy_spec.rb +1 -1
- data/spec/oanda_api/client/resource_descriptor_spec.rb +45 -14
- data/spec/oanda_api/configuration_spec.rb +13 -0
- data/spec/oanda_api/examples/accounts_spec.rb +0 -7
- data/spec/oanda_api/examples/calendar_spec.rb +27 -0
- data/spec/oanda_api/examples/orders_spec.rb +12 -12
- data/spec/oanda_api/examples/positions_spec.rb +3 -3
- data/spec/oanda_api/examples/rates_spec.rb +4 -2
- data/spec/oanda_api/examples/spread_history_spec.rb +32 -0
- data/spec/oanda_api/examples/trades_spec.rb +5 -5
- data/spec/oanda_api/examples/transactions_spec.rb +2 -2
- data/spec/oanda_api/resource_base_spec.rb +48 -8
- data/spec/oanda_api/streaming/client_spec.rb +30 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/client_helper.rb +45 -11
- data/spec/support/vcr.rb +1 -0
- metadata +63 -49
- data/spec/fixtures/vcr_cassettes/account_id_order_id_close.yml +0 -264
- data/spec/fixtures/vcr_cassettes/account_id_order_id_get.yml +0 -114
- data/spec/fixtures/vcr_cassettes/account_id_order_options_update.yml +0 -112
- data/spec/fixtures/vcr_cassettes/account_id_orders_get.yml +0 -118
- data/spec/fixtures/vcr_cassettes/account_id_orders_options_get.yml +0 -123
- data/spec/fixtures/vcr_cassettes/account_id_positions_get.yml +0 -112
- data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_close.yml +0 -214
- data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_get.yml +0 -110
- data/spec/fixtures/vcr_cassettes/account_id_trade_id_close.yml +0 -252
- data/spec/fixtures/vcr_cassettes/account_id_trade_id_get.yml +0 -112
- data/spec/fixtures/vcr_cassettes/account_id_trade_options_modify.yml +0 -110
- data/spec/fixtures/vcr_cassettes/account_id_trades_filter_get.yml +0 -118
- data/spec/fixtures/vcr_cassettes/account_id_trades_get.yml +0 -118
- data/spec/fixtures/vcr_cassettes/account_id_transaction_id_get.yml +0 -283
- data/spec/fixtures/vcr_cassettes/account_id_transactions_options_get.yml +0 -205
- data/spec/fixtures/vcr_cassettes/accounts_create.yml +0 -75
- data/spec/fixtures/vcr_cassettes/sandbox_client.yml +0 -116
- data/spec/fixtures/vcr_cassettes/sandbox_client_account.yml +0 -111
- data/spec/fixtures/vcr_cassettes/sandbox_instrument_EUR_USD.yml +0 -77
- data/spec/oanda_api/client/username_client_spec.rb +0 -31
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "OandaAPI::Client::NamespaceProxy" do
|
|
4
|
-
let(:client) { OandaAPI::Client
|
|
4
|
+
let(:client) { (Class.new { include OandaAPI::Client }).new }
|
|
5
5
|
let(:namespace_proxy) { OandaAPI::Client::NamespaceProxy.new client, "account" }
|
|
6
6
|
|
|
7
7
|
describe "#initialize" do
|
|
@@ -3,33 +3,52 @@ require 'spec_helper'
|
|
|
3
3
|
describe "OandaAPI::Client::ResourceDescriptor" do
|
|
4
4
|
describe "#initialize" do
|
|
5
5
|
let(:resource_descriptor) { OandaAPI::Client::ResourceDescriptor.new "/accounts", :get }
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
it "sets the path " do
|
|
7
8
|
expect(resource_descriptor.path).to eq("/accounts")
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
context
|
|
11
|
-
|
|
11
|
+
context "non-standard (special case) resources" do
|
|
12
|
+
describe "special case: '/alltransactions'" do
|
|
13
|
+
let(:resource_descriptor) { OandaAPI::Client::ResourceDescriptor.new "/account/123/alltransactions", :get }
|
|
14
|
+
|
|
15
|
+
it "sets TransactionHistory as its resource_klass" do
|
|
16
|
+
expect(resource_descriptor.resource_klass).to eq(OandaAPI::Resource::TransactionHistory)
|
|
17
|
+
end
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
it "sets @is_collection to false" do
|
|
20
|
+
expect(resource_descriptor.is_collection?).to be false
|
|
21
|
+
end
|
|
15
22
|
end
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
describe "special case: '/calendar'" do
|
|
25
|
+
let(:resource_descriptor) { OandaAPI::Client::ResourceDescriptor.new "/calendar", :get }
|
|
26
|
+
|
|
27
|
+
it "sets CalendarEvents as its resource_klass" do
|
|
28
|
+
expect(resource_descriptor.resource_klass).to eq(OandaAPI::Resource::Labs::CalendarEvent)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "sets @is_collection to true, despite its path name being singular" do
|
|
32
|
+
expect(resource_descriptor.is_collection?).to be true
|
|
33
|
+
end
|
|
19
34
|
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
describe "special case: '/calendar_events'" do
|
|
37
|
+
let(:resource_descriptor) { OandaAPI::Client::ResourceDescriptor.new "/calendar_events", :get }
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
it "uses /calendar as the true API resource name" do
|
|
40
|
+
expect(resource_descriptor.path).to eq "/calendar"
|
|
41
|
+
end
|
|
29
42
|
end
|
|
30
43
|
end
|
|
31
44
|
end
|
|
32
45
|
|
|
46
|
+
context "when the path ends with an unknown resource" do
|
|
47
|
+
it "doesn't allow invalid resources" do
|
|
48
|
+
expect { OandaAPI::Client::ResourceDescriptor.new "/invalid_resource" }.to raise_error(ArgumentError)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
33
52
|
describe "#is_collection?" do
|
|
34
53
|
it "is true for GET requests without a resource id" do
|
|
35
54
|
resource_descriptor = OandaAPI::Client::ResourceDescriptor.new "/account/123/orders", :get
|
|
@@ -48,4 +67,16 @@ describe "OandaAPI::Client::ResourceDescriptor" do
|
|
|
48
67
|
end
|
|
49
68
|
end
|
|
50
69
|
end
|
|
70
|
+
|
|
71
|
+
describe "#labs?" do
|
|
72
|
+
it "is true for 'Labs' resources" do
|
|
73
|
+
resource_descriptor = OandaAPI::Client::ResourceDescriptor.new "/calendar", :get
|
|
74
|
+
expect(resource_descriptor.labs?).to be true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "is false for non 'Labs' resources" do
|
|
78
|
+
resource_descriptor = OandaAPI::Client::ResourceDescriptor.new "/account", :get
|
|
79
|
+
expect(resource_descriptor.labs?).to be false
|
|
80
|
+
end
|
|
81
|
+
end
|
|
51
82
|
end
|
|
@@ -59,6 +59,19 @@ describe "OandaAPI::Configuration" do
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
describe "#labs_api_version" do
|
|
63
|
+
it "returns the default Labs api version" do
|
|
64
|
+
expect(config.labs_api_version).to eq OandaAPI::Configuration::LABS_API_VERSION
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "#labs_api_version=" do
|
|
69
|
+
it "overrides the default Labs api version" do
|
|
70
|
+
config.labs_api_version = "X"
|
|
71
|
+
expect(config.labs_api_version).to eq "X"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
62
75
|
describe "#max_requests_per_second" do
|
|
63
76
|
it "returns the default max requests per second" do
|
|
64
77
|
expect(config.max_requests_per_second).to eq OandaAPI::Configuration::MAX_REQUESTS_PER_SECOND
|
|
@@ -4,13 +4,6 @@ require 'support/client_helper'
|
|
|
4
4
|
describe "OandaAPI::Resource::Account" do
|
|
5
5
|
let(:client) { ClientHelper.client }
|
|
6
6
|
|
|
7
|
-
it "creates a new account" do
|
|
8
|
-
VCR.use_cassette("accounts.create") do
|
|
9
|
-
account = client.accounts.create
|
|
10
|
-
expect(account).to be_an OandaAPI::Resource::Account
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
7
|
it "gets all accounts", :vcr do
|
|
15
8
|
VCR.use_cassette("accounts.get") do
|
|
16
9
|
accounts = client.accounts.get
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'support/client_helper'
|
|
3
|
+
|
|
4
|
+
describe "OandaAPI::Resource::Labs::CalendarEvent" do
|
|
5
|
+
let(:client) { ClientHelper.client }
|
|
6
|
+
|
|
7
|
+
it "gets economic calendar events related to an instrument", :vcr do
|
|
8
|
+
VCR.use_cassette("calendar(instrument_and_period).get") do
|
|
9
|
+
events = client.calendar(instrument: "EUR_CAD", period: 604800).get
|
|
10
|
+
expect(events.first).to be_an OandaAPI::Resource::Labs::CalendarEvent
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "gets all economic calendar events for a period", :vcr do
|
|
15
|
+
VCR.use_cassette("calendar(period).get") do
|
|
16
|
+
events = client.calendar(period: 86400).get
|
|
17
|
+
expect(events.first).to be_an OandaAPI::Resource::Labs::CalendarEvent
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "can use the alias: calendar_events", :vcr do
|
|
22
|
+
VCR.use_cassette("calendar_events(period).get") do
|
|
23
|
+
events = client.calendar_events(period: 86400).get
|
|
24
|
+
expect(events.first).to be_an OandaAPI::Resource::Labs::CalendarEvent
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -3,10 +3,10 @@ require 'support/client_helper'
|
|
|
3
3
|
|
|
4
4
|
describe "OandaAPI::Resource::Order" do
|
|
5
5
|
let(:account) { ClientHelper.account }
|
|
6
|
-
let(:price)
|
|
6
|
+
let(:price) { ->(instrument) { ClientHelper.instrument(instrument).bid - 0.1 } }
|
|
7
7
|
|
|
8
8
|
it "creates an order", :vcr do
|
|
9
|
-
VCR.use_cassette("
|
|
9
|
+
VCR.use_cassette("order(options).create") do
|
|
10
10
|
order = account.order(instrument: "EUR_USD",
|
|
11
11
|
type: "market",
|
|
12
12
|
side: "buy",
|
|
@@ -17,16 +17,16 @@ describe "OandaAPI::Resource::Order" do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "gets all open orders", :vcr do
|
|
20
|
-
VCR.use_cassette("
|
|
21
|
-
ClientHelper.create_order(type: "limit", price: price)
|
|
20
|
+
VCR.use_cassette("orders.get") do
|
|
21
|
+
ClientHelper.create_order(type: "limit", instrument: "EUR_USD", price: price["EUR_USD"])
|
|
22
22
|
orders = account.orders.get
|
|
23
23
|
expect(orders.first).to be_an OandaAPI::Resource::Order
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "gets a filtered list of open orders", :vcr do
|
|
28
|
-
VCR.use_cassette("
|
|
29
|
-
ClientHelper.create_order(
|
|
28
|
+
VCR.use_cassette("orders(options).get") do
|
|
29
|
+
ClientHelper.create_order(type: "limit", instrument: "USD_JPY", price: price["USD_JPY"])
|
|
30
30
|
|
|
31
31
|
orders = account.orders(instrument: "USD_JPY").get
|
|
32
32
|
expect(orders.first).to be_an OandaAPI::Resource::Order
|
|
@@ -34,8 +34,8 @@ describe "OandaAPI::Resource::Order" do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "gets a specific open order", :vcr do
|
|
37
|
-
VCR.use_cassette("
|
|
38
|
-
order_id = ClientHelper.create_order(type: "limit", price: price)
|
|
37
|
+
VCR.use_cassette("order(id).get") do
|
|
38
|
+
order_id = ClientHelper.create_order(type: "limit", instrument: "EUR_USD", price: price["EUR_USD"])
|
|
39
39
|
.order_opened
|
|
40
40
|
.id
|
|
41
41
|
expect(account.order(order_id).get).to be_an OandaAPI::Resource::Order
|
|
@@ -43,8 +43,8 @@ describe "OandaAPI::Resource::Order" do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "modifies an open order", :vcr do
|
|
46
|
-
VCR.use_cassette("
|
|
47
|
-
order_id = ClientHelper.create_order(type: "limit", price: price)
|
|
46
|
+
VCR.use_cassette("order(options).update") do
|
|
47
|
+
order_id = ClientHelper.create_order(type: "limit", instrument: "EUR_USD", price: price["EUR_USD"])
|
|
48
48
|
.order_opened
|
|
49
49
|
.id
|
|
50
50
|
updated_order = account.order(id: order_id, units: 9_000).update
|
|
@@ -53,8 +53,8 @@ describe "OandaAPI::Resource::Order" do
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it "closes an open order", :vcr do
|
|
56
|
-
VCR.use_cassette("
|
|
57
|
-
order_id = ClientHelper.create_order(type: "limit", price: price)
|
|
56
|
+
VCR.use_cassette("order(id).close") do
|
|
57
|
+
order_id = ClientHelper.create_order(type: "limit", instrument: "EUR_USD", price: price["EUR_USD"])
|
|
58
58
|
.order_opened
|
|
59
59
|
.id
|
|
60
60
|
before_order_ids = account.orders.get.map(&:id)
|
|
@@ -5,7 +5,7 @@ describe "OandaAPI::Resource::Position" do
|
|
|
5
5
|
let(:account) { ClientHelper.account }
|
|
6
6
|
|
|
7
7
|
it "gets all open positions", :vcr do
|
|
8
|
-
VCR.use_cassette("
|
|
8
|
+
VCR.use_cassette("positions.get") do
|
|
9
9
|
ClientHelper.create_trade
|
|
10
10
|
positions = account.positions.get
|
|
11
11
|
expect(positions.first).to be_an OandaAPI::Resource::Position
|
|
@@ -13,7 +13,7 @@ describe "OandaAPI::Resource::Position" do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "gets the position for an instrument", :vcr do
|
|
16
|
-
VCR.use_cassette("
|
|
16
|
+
VCR.use_cassette("positions(instrument).get") do
|
|
17
17
|
ClientHelper.create_trade(instrument: "USD_JPY")
|
|
18
18
|
position = account.positions("USD_JPY").get
|
|
19
19
|
expect(position).to be_an OandaAPI::Resource::Position
|
|
@@ -21,7 +21,7 @@ describe "OandaAPI::Resource::Position" do
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "closes an existing position", :vcr do
|
|
24
|
-
VCR.use_cassette("
|
|
24
|
+
VCR.use_cassette("positions(instrument).close") do
|
|
25
25
|
ClientHelper.create_trade(instrument: "USD_JPY")
|
|
26
26
|
|
|
27
27
|
# Verify we have an open position.
|
|
@@ -3,18 +3,20 @@ require 'support/client_helper'
|
|
|
3
3
|
|
|
4
4
|
describe "OandaAPI::Resource" do
|
|
5
5
|
let(:client) { ClientHelper.client }
|
|
6
|
+
let(:account) { ClientHelper.account }
|
|
6
7
|
|
|
7
8
|
describe "Instrument" do
|
|
8
9
|
it "gets all instruments", :vcr do
|
|
9
10
|
VCR.use_cassette("instruments.get") do
|
|
10
|
-
instruments = client.instruments.get
|
|
11
|
+
instruments = client.instruments(account_id: ClientHelper.account_id).get
|
|
11
12
|
expect(instruments.first).to be_an OandaAPI::Resource::Instrument
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
it "gets a filtered list of instruments", :vcr do
|
|
16
17
|
VCR.use_cassette("instruments(options).get") do
|
|
17
|
-
instruments = client.instruments(
|
|
18
|
+
instruments = client.instruments( account_id: ClientHelper.account_id,
|
|
19
|
+
instruments: %w(EUR_USD EUR_CAD),
|
|
18
20
|
fields: %w(pip precision))
|
|
19
21
|
.get
|
|
20
22
|
expect(instruments.first).to be_an OandaAPI::Resource::Instrument
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'support/client_helper'
|
|
3
|
+
|
|
4
|
+
describe "OandaAPI::Resource::Labs::SpreadHistory" do
|
|
5
|
+
let(:client) { ClientHelper.client }
|
|
6
|
+
|
|
7
|
+
it "gets spread history for an instrument and a period", :vcr do
|
|
8
|
+
VCR.use_cassette("spreads.get") do
|
|
9
|
+
spread_history = client.spreads(instrument: "EUR_CAD", period: 3600).get
|
|
10
|
+
expect(spread_history).to be_an OandaAPI::Resource::Labs::SpreadHistory
|
|
11
|
+
|
|
12
|
+
expect(spread_history.averages.first.spread).to be_a Numeric
|
|
13
|
+
expect(spread_history.averages.first.timestamp).to be_a Fixnum
|
|
14
|
+
expect(spread_history.averages.first.time).to be_a Time
|
|
15
|
+
|
|
16
|
+
expect(spread_history.maximums.first.spread).to be_a Numeric
|
|
17
|
+
expect(spread_history.maximums.first.timestamp).to be_a Fixnum
|
|
18
|
+
expect(spread_history.maximums.first.time).to be_a Time
|
|
19
|
+
|
|
20
|
+
expect(spread_history.minimums.first.spread).to be_a Numeric
|
|
21
|
+
expect(spread_history.minimums.first.timestamp).to be_a Fixnum
|
|
22
|
+
expect(spread_history.minimums.first.time).to be_a Time
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "can use the alias: spread_history", :vcr do
|
|
27
|
+
VCR.use_cassette("spread_history.get") do
|
|
28
|
+
spread_history = client.spread_history(instrument: "EUR_CAD", period: 3600).get
|
|
29
|
+
expect(spread_history).to be_an OandaAPI::Resource::Labs::SpreadHistory
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -5,7 +5,7 @@ describe "OandaAPI::Resource::Trade" do
|
|
|
5
5
|
let(:account) { ClientHelper.account }
|
|
6
6
|
|
|
7
7
|
it "gets a list of trades", :vcr do
|
|
8
|
-
VCR.use_cassette("
|
|
8
|
+
VCR.use_cassette("trades.get") do
|
|
9
9
|
ClientHelper.create_trade
|
|
10
10
|
trades = account.trades.get
|
|
11
11
|
expect(trades.first).to be_an OandaAPI::Resource::Trade
|
|
@@ -13,7 +13,7 @@ describe "OandaAPI::Resource::Trade" do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "gets a filtered list of trades", :vcr do
|
|
16
|
-
VCR.use_cassette("
|
|
16
|
+
VCR.use_cassette("trades(filter).get") do
|
|
17
17
|
ClientHelper.create_trade(instrument: "USD_JPY")
|
|
18
18
|
trades = account.trades(instrument: "USD_JPY").get
|
|
19
19
|
expect(trades.first).to be_an OandaAPI::Resource::Trade
|
|
@@ -21,7 +21,7 @@ describe "OandaAPI::Resource::Trade" do
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "gets information on a specific trade", :vcr do
|
|
24
|
-
VCR.use_cassette("
|
|
24
|
+
VCR.use_cassette("trade(id).get") do
|
|
25
25
|
trade_id = ClientHelper.create_trade.trade_opened.id
|
|
26
26
|
trade = account.trade(trade_id).get
|
|
27
27
|
expect(trade).to be_an OandaAPI::Resource::Trade
|
|
@@ -29,7 +29,7 @@ describe "OandaAPI::Resource::Trade" do
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "modifies an open trade " do
|
|
32
|
-
VCR.use_cassette("
|
|
32
|
+
VCR.use_cassette("trade(options).modify") do
|
|
33
33
|
order = ClientHelper.create_trade
|
|
34
34
|
modified_order =
|
|
35
35
|
account.trade(id: order.trade_opened.id, take_profit: order.price + 2.0)
|
|
@@ -39,7 +39,7 @@ describe "OandaAPI::Resource::Trade" do
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "closes an open trade" do
|
|
42
|
-
VCR.use_cassette("
|
|
42
|
+
VCR.use_cassette("trade(id).close") do
|
|
43
43
|
ClientHelper.create_trade(instrument: "USD_JPY").trade_opened.id
|
|
44
44
|
|
|
45
45
|
# Get the oldest open trade for USD_JPY, so we can close that trade.
|
|
@@ -5,7 +5,7 @@ describe "OandaAPI::Transaction" do
|
|
|
5
5
|
let(:account) { ClientHelper.account }
|
|
6
6
|
|
|
7
7
|
it "gets transaction history" do
|
|
8
|
-
VCR.use_cassette("
|
|
8
|
+
VCR.use_cassette("transactions(options).get") do
|
|
9
9
|
ClientHelper.create_trade(instrument: "USD_JPY")
|
|
10
10
|
transactions = account.transactions(instrument: "USD_JPY").get
|
|
11
11
|
expect(transactions.first).to be_an OandaAPI::Resource::Transaction
|
|
@@ -13,7 +13,7 @@ describe "OandaAPI::Transaction" do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "gets information for a specific transaction" do
|
|
16
|
-
VCR.use_cassette("
|
|
16
|
+
VCR.use_cassette("transaction(id).get") do
|
|
17
17
|
ClientHelper.create_trade(instrument: "USD_JPY")
|
|
18
18
|
id = account.transactions(instrument: "USD_JPY").get.first.id
|
|
19
19
|
transaction = account.transaction(id).get
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
describe "OandaAPI::ResourceBase" do
|
|
3
|
-
class
|
|
3
|
+
class SomeResource < OandaAPI::ResourceBase
|
|
4
4
|
attr_accessor :webbed_feet
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class SomeResourceCustomized < OandaAPI::ResourceBase
|
|
8
8
|
attr_accessor :webbed_feet
|
|
9
9
|
|
|
10
10
|
def custom_attributes
|
|
@@ -12,40 +12,80 @@ describe "OandaAPI::ResourceBase" do
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
describe ".class_from_symbol" do
|
|
16
|
+
it "returns the Class for a resource name" do
|
|
17
|
+
expect(OandaAPI::ResourceBase.class_from_symbol(:account)).to be OandaAPI::Resource::Account
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:baby_klass) { module OandaAPI; class Mama < OandaAPI::ResourceBase; end; end; module OandaAPI; class Baby < Mama; end; end; OandaAPI::Baby }
|
|
21
|
+
it "works for any resource that decends from OandaAPI::ResourceBase" do
|
|
22
|
+
expect(baby_klass).to be OandaAPI::Baby
|
|
23
|
+
expect(OandaAPI::ResourceBase.class_from_symbol(:baby)).to be baby_klass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe ".labs_resource?" do
|
|
28
|
+
it "is true for a 'Labs' resource" do
|
|
29
|
+
expect(OandaAPI::ResourceBase.labs_resource?(OandaAPI::Resource::Labs::CalendarEvent)).to be true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "is false for a non 'Labs' resource" do
|
|
33
|
+
expect(OandaAPI::ResourceBase.labs_resource?(OandaAPI::Resource::Account)).to be false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let(:flux_capacitor_klass) { module OandaAPI; module Resource; module Labs; module RocketScience class FluxCapacitor < OandaAPI::ResourceBase; end; end; end; end; end; OandaAPI::Resource::Labs::RocketScience::FluxCapacitor }
|
|
37
|
+
it "works for any resource under the Labs:: namespace" do
|
|
38
|
+
expect(flux_capacitor_klass).to be OandaAPI::Resource::Labs::RocketScience::FluxCapacitor
|
|
39
|
+
expect(OandaAPI::ResourceBase.labs_resource?(flux_capacitor_klass)).to be true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe ".pluralize" do
|
|
44
|
+
it "pluralizes resource class names" do
|
|
45
|
+
expect(OandaAPI::ResourceBase.pluralize(:account)).to eq "accounts"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "doesn't pluralize resource name exceptions (these are never pluralized in the API)" do
|
|
49
|
+
OandaAPI::ResourceBase::NOT_PLURALIZED.each do |special_case_resource|
|
|
50
|
+
expect(OandaAPI::ResourceBase.pluralize(special_case_resource)).to eq special_case_resource.to_s
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
15
55
|
describe "#initialize" do
|
|
16
56
|
it "initializes writer methods with matching attributes" do
|
|
17
|
-
obj =
|
|
57
|
+
obj = SomeResource.new webbed_feet: "webbed feet"
|
|
18
58
|
expect(obj.webbed_feet).to eq "webbed feet"
|
|
19
59
|
end
|
|
20
60
|
|
|
21
61
|
it "initializes snake_case writer methods with matching camelCase attributes" do
|
|
22
|
-
obj =
|
|
62
|
+
obj = SomeResource.new webbedFeet: "webbed feet"
|
|
23
63
|
expect(obj.webbed_feet).to eq "webbed feet"
|
|
24
64
|
end
|
|
25
65
|
end
|
|
26
66
|
|
|
27
67
|
describe "#location" do
|
|
28
68
|
it "sets location" do
|
|
29
|
-
obj =
|
|
69
|
+
obj = SomeResource.new location: "location"
|
|
30
70
|
expect(obj.location).to eq "location"
|
|
31
71
|
end
|
|
32
72
|
end
|
|
33
73
|
|
|
34
74
|
describe "#to_json" do
|
|
35
75
|
it "serializes all of an instance's attributes" do
|
|
36
|
-
obj =
|
|
76
|
+
obj = SomeResource.new webbedFeet: "webbed feet", location: "location", extraAttribute: "extra"
|
|
37
77
|
h = JSON.parse obj.to_json
|
|
38
78
|
expect(h).to include("webbed_feet" => "webbed feet", "extra_attribute" => "extra", "location" => "location")
|
|
39
79
|
end
|
|
40
80
|
|
|
41
81
|
it "serializes all of an instance's customized attributes" do
|
|
42
|
-
obj =
|
|
82
|
+
obj = SomeResourceCustomized.new webbedFeet: "webbed feet"
|
|
43
83
|
h = JSON.parse obj.to_json
|
|
44
84
|
expect(h).to include("webbed_feet" => "customized webbed feet")
|
|
45
85
|
end
|
|
46
86
|
|
|
47
87
|
it "serializes when nested" do
|
|
48
|
-
obj =
|
|
88
|
+
obj = SomeResourceCustomized.new webbedFeet: "webbed feet"
|
|
49
89
|
a = JSON.parse [obj].to_json
|
|
50
90
|
expect(a.first).to include("webbed_feet" => "customized webbed feet")
|
|
51
91
|
end
|