tradier 0.1.0
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.
- data/.yardopts +8 -0
- data/LICENSE.md +20 -0
- data/README.md +114 -0
- data/Rakefile +19 -0
- data/lib/tradier.rb +31 -0
- data/lib/tradier/account.rb +30 -0
- data/lib/tradier/api/accounts.rb +122 -0
- data/lib/tradier/api/markets.rb +113 -0
- data/lib/tradier/api/orders.rb +84 -0
- data/lib/tradier/api/utils.rb +47 -0
- data/lib/tradier/api/utils/account.rb +15 -0
- data/lib/tradier/api/utils/balance.rb +15 -0
- data/lib/tradier/api/utils/base.rb +46 -0
- data/lib/tradier/api/utils/event.rb +15 -0
- data/lib/tradier/api/utils/expiration.rb +19 -0
- data/lib/tradier/api/utils/gainloss.rb +15 -0
- data/lib/tradier/api/utils/history.rb +15 -0
- data/lib/tradier/api/utils/option_quote.rb +15 -0
- data/lib/tradier/api/utils/order.rb +15 -0
- data/lib/tradier/api/utils/position.rb +15 -0
- data/lib/tradier/api/utils/quote.rb +15 -0
- data/lib/tradier/api/utils/strike.rb +15 -0
- data/lib/tradier/api/utils/timesales.rb +15 -0
- data/lib/tradier/api/utils/watchlist.rb +15 -0
- data/lib/tradier/api/watchlists.rb +139 -0
- data/lib/tradier/balance.rb +17 -0
- data/lib/tradier/base.rb +76 -0
- data/lib/tradier/calendar.rb +23 -0
- data/lib/tradier/client.rb +89 -0
- data/lib/tradier/clock.rb +21 -0
- data/lib/tradier/configurable.rb +76 -0
- data/lib/tradier/core_ext/enumerable.rb +9 -0
- data/lib/tradier/default.rb +75 -0
- data/lib/tradier/error.rb +34 -0
- data/lib/tradier/error/bad_gateway.rb +11 -0
- data/lib/tradier/error/bad_request.rb +10 -0
- data/lib/tradier/error/client_error.rb +28 -0
- data/lib/tradier/error/configuration_error.rb +6 -0
- data/lib/tradier/error/decode_error.rb +9 -0
- data/lib/tradier/error/forbidden.rb +10 -0
- data/lib/tradier/error/gateway_timeout.rb +11 -0
- data/lib/tradier/error/internal_server_error.rb +11 -0
- data/lib/tradier/error/not_acceptable.rb +10 -0
- data/lib/tradier/error/not_found.rb +10 -0
- data/lib/tradier/error/raise_error.rb +31 -0
- data/lib/tradier/error/server_error.rb +28 -0
- data/lib/tradier/error/service_unavailable.rb +11 -0
- data/lib/tradier/error/too_many_requests.rb +12 -0
- data/lib/tradier/error/unauthorized.rb +10 -0
- data/lib/tradier/error/unprocessable_entity.rb +10 -0
- data/lib/tradier/event.rb +8 -0
- data/lib/tradier/history.rb +20 -0
- data/lib/tradier/option_quote.rb +37 -0
- data/lib/tradier/order.rb +14 -0
- data/lib/tradier/position.rb +7 -0
- data/lib/tradier/profile.rb +14 -0
- data/lib/tradier/quote.rb +12 -0
- data/lib/tradier/response/parse_json.rb +25 -0
- data/lib/tradier/response/raise_error.rb +31 -0
- data/lib/tradier/symbol.rb +147 -0
- data/lib/tradier/timesales.rb +11 -0
- data/lib/tradier/version.rb +3 -0
- data/lib/tradier/watchlist.rb +16 -0
- data/lib/tradier/watchlist_item.rb +17 -0
- data/spec/fixtures/account_balances.json +28 -0
- data/spec/fixtures/account_gainloss.json +18 -0
- data/spec/fixtures/account_history.json +96 -0
- data/spec/fixtures/account_orders.json +833 -0
- data/spec/fixtures/account_positions.json +22 -0
- data/spec/fixtures/calendar.json +400 -0
- data/spec/fixtures/chain.json +2972 -0
- data/spec/fixtures/clock.json +10 -0
- data/spec/fixtures/expirations.json +18 -0
- data/spec/fixtures/history.json +2086 -0
- data/spec/fixtures/option_quote.json +14 -0
- data/spec/fixtures/option_quotes.json +26 -0
- data/spec/fixtures/order.json +1 -0
- data/spec/fixtures/order_with_warnings.json +17 -0
- data/spec/fixtures/placed_order.json +6 -0
- data/spec/fixtures/quote.json +45 -0
- data/spec/fixtures/quotes.json +88 -0
- data/spec/fixtures/session.json +6 -0
- data/spec/fixtures/strikes.json +173 -0
- data/spec/fixtures/timesales.json +2956 -0
- data/spec/fixtures/user_balances.json +118 -0
- data/spec/fixtures/user_gainloss.json +6775 -0
- data/spec/fixtures/user_history.json +101 -0
- data/spec/fixtures/user_orders.json +57 -0
- data/spec/fixtures/user_positions.json +50 -0
- data/spec/fixtures/user_profile.json +103 -0
- data/spec/fixtures/watchlist.json +30 -0
- data/spec/fixtures/watchlist_item.json +6 -0
- data/spec/fixtures/watchlists.json +18 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/tradier/account_spec.rb +76 -0
- data/spec/tradier/api/accounts_spec.rb +195 -0
- data/spec/tradier/api/markets_spec.rb +219 -0
- data/spec/tradier/api/orders_spec.rb +94 -0
- data/spec/tradier/api/utils/expiration_spec.rb +8 -0
- data/spec/tradier/api/watchlists_spec.rb +164 -0
- data/spec/tradier/balance_spec.rb +4 -0
- data/spec/tradier/base_spec.rb +11 -0
- data/spec/tradier/calendar_spec.rb +27 -0
- data/spec/tradier/client_spec.rb +125 -0
- data/spec/tradier/clock_spec.rb +73 -0
- data/spec/tradier/error/client_error_spec.rb +22 -0
- data/spec/tradier/error/server_error_spec.rb +22 -0
- data/spec/tradier/error_spec.rb +26 -0
- data/spec/tradier/option_quote_spec.rb +61 -0
- data/spec/tradier/order_spec.rb +43 -0
- data/spec/tradier/position_spec.rb +4 -0
- data/spec/tradier/profile_spec.rb +28 -0
- data/spec/tradier/quote_spec.rb +29 -0
- data/spec/tradier/symbol_spec.rb +54 -0
- data/spec/tradier/watchlist_item_spec.rb +48 -0
- data/spec/tradier/watchlist_spec.rb +35 -0
- data/spec/tradier_spec.rb +105 -0
- data/tradier.gemspec +30 -0
- metadata +302 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tradier::API::Accounts do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Tradier::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#profile' do
|
10
|
+
context 'when passed an account number' do
|
11
|
+
before do
|
12
|
+
stub_get("/v1/user/profile").
|
13
|
+
to_return(:body => fixture("user_profile.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
it "requests the correct resource" do
|
16
|
+
@client.profile
|
17
|
+
expect(a_get("/v1/user/profile")).to have_been_made
|
18
|
+
end
|
19
|
+
it "returns a Tradier::Profile" do
|
20
|
+
profile = @client.profile
|
21
|
+
expect(profile).to be_a Tradier::Profile
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#balances' do
|
27
|
+
context 'when passed an account number' do
|
28
|
+
before do
|
29
|
+
stub_get("/v1/accounts/123456789/balances").
|
30
|
+
to_return(:body => fixture("account_balances.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
31
|
+
end
|
32
|
+
it "requests the correct resource" do
|
33
|
+
@client.balances("123456789")
|
34
|
+
expect(a_get("/v1/accounts/123456789/balances")).to have_been_made
|
35
|
+
end
|
36
|
+
it "returns a Tradier::Balance object" do
|
37
|
+
balance = @client.balances("123456789")
|
38
|
+
expect(balance).to be_a Tradier::Balance
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has populated attributes" do
|
42
|
+
balance = @client.balances("123456789")
|
43
|
+
expect(balance.attrs).to_not be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'when no account number' do
|
47
|
+
before do
|
48
|
+
stub_get("/v1/user/balances").
|
49
|
+
to_return(:body => fixture("user_balances.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
50
|
+
end
|
51
|
+
it "requests the correct resource" do
|
52
|
+
@client.balances
|
53
|
+
expect(a_get("/v1/user/balances")).to have_been_made
|
54
|
+
end
|
55
|
+
it "returns an array of Tradier::Balance objects" do
|
56
|
+
balances = @client.balances
|
57
|
+
expect(balances).to be_an Array
|
58
|
+
expect(balances.first).to be_a Tradier::Balance
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#positions' do
|
64
|
+
context 'when passed an account number' do
|
65
|
+
before do
|
66
|
+
stub_get("/v1/accounts/123456789/positions").
|
67
|
+
to_return(:body => fixture("account_positions.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
68
|
+
end
|
69
|
+
it "requests the correct resource" do
|
70
|
+
@client.positions("123456789")
|
71
|
+
expect(a_get("/v1/accounts/123456789/positions")).to have_been_made
|
72
|
+
end
|
73
|
+
it "returns a Tradier::Position" do
|
74
|
+
positions = @client.positions("123456789")
|
75
|
+
expect(positions).to be_an Array
|
76
|
+
expect(positions.first).to be_a Tradier::Position
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context 'when no account number' do
|
80
|
+
before do
|
81
|
+
stub_get("/v1/user/positions").
|
82
|
+
to_return(:body => fixture("user_positions.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
83
|
+
end
|
84
|
+
it "requests the correct resource" do
|
85
|
+
@client.positions
|
86
|
+
expect(a_get("/v1/user/positions")).to have_been_made
|
87
|
+
end
|
88
|
+
it "returns an array of Tradier::Position" do
|
89
|
+
positions = @client.positions
|
90
|
+
expect(positions).to be_an Array
|
91
|
+
expect(positions.first).to be_a Tradier::Account
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#orders' do
|
97
|
+
context 'when passed an account number' do
|
98
|
+
before do
|
99
|
+
stub_get("/v1/accounts/123456789/orders").
|
100
|
+
to_return(:body => fixture("account_orders.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
101
|
+
end
|
102
|
+
it "requests the correct resource" do
|
103
|
+
@client.orders("123456789")
|
104
|
+
expect(a_get("/v1/accounts/123456789/orders")).to have_been_made
|
105
|
+
end
|
106
|
+
it "returns a Tradier::Order" do
|
107
|
+
orders = @client.orders("123456789")
|
108
|
+
expect(orders).to be_an Array
|
109
|
+
expect(orders.first).to be_a Tradier::Order
|
110
|
+
end
|
111
|
+
end
|
112
|
+
context 'when no account number' do
|
113
|
+
before do
|
114
|
+
stub_get("/v1/user/orders").
|
115
|
+
to_return(:body => fixture("user_orders.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
116
|
+
end
|
117
|
+
it "requests the correct resource" do
|
118
|
+
@client.orders
|
119
|
+
expect(a_get("/v1/user/orders")).to have_been_made
|
120
|
+
end
|
121
|
+
it "returns an array of Tradier::Order" do
|
122
|
+
orders = @client.orders
|
123
|
+
expect(orders).to be_an Array
|
124
|
+
expect(orders.first).to be_a Tradier::Account
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#gainloss' do
|
130
|
+
context 'when passed an account number' do
|
131
|
+
before do
|
132
|
+
stub_get("/v1/accounts/123456789/gainloss").
|
133
|
+
to_return(:body => fixture("account_gainloss.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
134
|
+
end
|
135
|
+
it "requests the correct resource" do
|
136
|
+
@client.gainloss("123456789")
|
137
|
+
expect(a_get("/v1/accounts/123456789/gainloss")).to have_been_made
|
138
|
+
end
|
139
|
+
it "returns an array of Tradier::Position" do
|
140
|
+
gainloss = @client.gainloss("123456789")
|
141
|
+
expect(gainloss).to be_an Array
|
142
|
+
expect(gainloss.first).to be_a Tradier::Position
|
143
|
+
end
|
144
|
+
end
|
145
|
+
context 'when no account number' do
|
146
|
+
before do
|
147
|
+
stub_get("/v1/user/gainloss").
|
148
|
+
to_return(:body => fixture("user_gainloss.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
149
|
+
end
|
150
|
+
it "requests the correct resource" do
|
151
|
+
@client.gainloss
|
152
|
+
expect(a_get("/v1/user/gainloss")).to have_been_made
|
153
|
+
end
|
154
|
+
it "returns an array of Tradier::Position" do
|
155
|
+
gainloss = @client.gainloss
|
156
|
+
expect(gainloss).to be_an Array
|
157
|
+
expect(gainloss.first).to be_a Tradier::Account
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#events' do
|
163
|
+
context 'when passed an account number' do
|
164
|
+
before do
|
165
|
+
stub_get("/v1/accounts/123456789/history").
|
166
|
+
to_return(:body => fixture("account_history.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
167
|
+
end
|
168
|
+
it "requests the correct resource" do
|
169
|
+
@client.events("123456789")
|
170
|
+
expect(a_get("/v1/accounts/123456789/history")).to have_been_made
|
171
|
+
end
|
172
|
+
it "returns an array of Tradier::Event" do
|
173
|
+
events = @client.events("123456789")
|
174
|
+
expect(events).to be_an Array
|
175
|
+
expect(events.first).to be_a Tradier::Event
|
176
|
+
end
|
177
|
+
end
|
178
|
+
context 'when no account number' do
|
179
|
+
before do
|
180
|
+
stub_get("/v1/user/history").
|
181
|
+
to_return(:body => fixture("user_history.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
end
|
183
|
+
it "requests the correct resource" do
|
184
|
+
@client.events
|
185
|
+
expect(a_get("/v1/user/history")).to have_been_made
|
186
|
+
end
|
187
|
+
it "returns an array of Tradier::Events" do
|
188
|
+
events = @client.events
|
189
|
+
expect(events).to be_an Array
|
190
|
+
expect(events.first).to be_a Tradier::Account
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tradier::API::Markets do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Tradier::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#quotes" do
|
10
|
+
context "when a single symbol passed" do
|
11
|
+
before do
|
12
|
+
stub_get("/v1/markets/quotes").
|
13
|
+
with(:query => {:symbols => "AAPL"}).
|
14
|
+
to_return(:body => fixture("quote.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "requests the correct resource" do
|
18
|
+
@client.quotes("AAPL")
|
19
|
+
|
20
|
+
expect(a_get("/v1/markets/quotes").
|
21
|
+
with(:query => {:symbols => "AAPL"})).to have_been_made
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an array of quotes" do
|
25
|
+
quotes = @client.quotes("AAPL")
|
26
|
+
expect(quotes).to be_an Array
|
27
|
+
expect(quotes.size).to eq(1)
|
28
|
+
expect(quotes.first).to be_a Tradier::Quote
|
29
|
+
expect(quotes.first.symbol).to eq 'AAPL'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "when multiple symbols passed as a comma delimited string" do
|
33
|
+
before do
|
34
|
+
stub_get("/v1/markets/quotes").
|
35
|
+
with(:query => {:symbols => "AAPL,GE"}).
|
36
|
+
to_return(:body => fixture("quotes.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
37
|
+
end
|
38
|
+
|
39
|
+
it "requests the correct resource" do
|
40
|
+
@client.quotes("AAPL,GE")
|
41
|
+
|
42
|
+
expect(a_get("/v1/markets/quotes").
|
43
|
+
with(:query => {:symbols => "AAPL,GE"})).to have_been_made
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns an array of quotes" do
|
47
|
+
quotes = @client.quotes("AAPL,GE")
|
48
|
+
expect(quotes).to be_an Array
|
49
|
+
expect(quotes.size).to eq(2)
|
50
|
+
expect(quotes.first).to be_a Tradier::Quote
|
51
|
+
expect(quotes.first.symbol).to eq 'AAPL'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when multiple symbols passed as an array" do
|
56
|
+
before do
|
57
|
+
stub_get("/v1/markets/quotes").
|
58
|
+
with(:query => {:symbols => "AAPL,GE"}).
|
59
|
+
to_return(:body => fixture("quotes.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "requests the correct resource" do
|
63
|
+
@client.quotes(["AAPL","GE"])
|
64
|
+
|
65
|
+
expect(a_get("/v1/markets/quotes").
|
66
|
+
with(:query => {:symbols => "AAPL,GE"})).to have_been_made
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns an array of quotes" do
|
70
|
+
quotes = @client.quotes(["AAPL","GE"])
|
71
|
+
expect(quotes).to be_an Array
|
72
|
+
expect(quotes.size).to eq(2)
|
73
|
+
expect(quotes.first).to be_a Tradier::Quote
|
74
|
+
expect(quotes.first.symbol).to eq 'AAPL'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#chains" do
|
80
|
+
before do
|
81
|
+
stub_get("/v1/markets/options/chains").
|
82
|
+
with(:query => {:symbol => "AAPL", :month => '6', :year => 2013}).
|
83
|
+
to_return(:body => fixture("chain.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
84
|
+
end
|
85
|
+
|
86
|
+
it "requests the correct resource" do
|
87
|
+
@client.chains("AAPL", :month => 6, :year => 2013)
|
88
|
+
expect(a_get("/v1/markets/options/chains").
|
89
|
+
with(:query => {:symbol => "AAPL", :month => '6', :year => 2013})).to have_been_made
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns an array of quotes" do
|
93
|
+
chain = @client.chains("AAPL", :month => 6, :year => 2013)
|
94
|
+
expect(chain).to be_an Array
|
95
|
+
expect(chain.size).to eq(330)
|
96
|
+
expect(chain.first).to be_a Tradier::OptionQuote
|
97
|
+
expect(chain.first.symbol).to eq 'AAPL150117C01000000'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#expirations" do
|
102
|
+
before do
|
103
|
+
stub_get("/v1/markets/options/expirations").
|
104
|
+
with(:query => {:symbol => "AAPL"}).
|
105
|
+
to_return(:body => fixture("expirations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
106
|
+
end
|
107
|
+
|
108
|
+
it "requests the correct resource" do
|
109
|
+
@client.expirations("AAPL")
|
110
|
+
|
111
|
+
expect(a_get("/v1/markets/options/expirations").
|
112
|
+
with(:query => {:symbol => "AAPL"})).to have_been_made
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns an array of dates" do
|
116
|
+
expirations = @client.expirations("AAPL")
|
117
|
+
expect(expirations).to be_an Array
|
118
|
+
expect(expirations.size).to eq(12)
|
119
|
+
expect(expirations.first).to be_a Date
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#strikes" do
|
124
|
+
before do
|
125
|
+
stub_get("/v1/markets/options/strikes").
|
126
|
+
with(:query => {:symbol => "AAPL", :expiration => "2013-11-16"}).
|
127
|
+
to_return(:body => fixture("strikes.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
128
|
+
end
|
129
|
+
|
130
|
+
it "requests the correct resource" do
|
131
|
+
@client.strikes("AAPL", "2013-11-16")
|
132
|
+
|
133
|
+
expect(a_get("/v1/markets/options/strikes").
|
134
|
+
with(:query => {:symbol => "AAPL", :expiration => "2013-11-16"})).to have_been_made
|
135
|
+
end
|
136
|
+
|
137
|
+
it "returns an array of strikes" do
|
138
|
+
strikes = @client.strikes("AAPL", "2013-11-16")
|
139
|
+
expect(strikes).to be_an Array
|
140
|
+
expect(strikes.size).to eq(167)
|
141
|
+
expect(strikes.first).to be_a Float
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#clock' do
|
146
|
+
before do
|
147
|
+
stub_get("/v1/markets/clock").
|
148
|
+
to_return(:body => fixture("clock.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
149
|
+
end
|
150
|
+
|
151
|
+
it "requests the correct resource" do
|
152
|
+
@client.clock
|
153
|
+
expect(a_get("/v1/markets/clock")).to have_been_made
|
154
|
+
end
|
155
|
+
|
156
|
+
it "returns a clock object" do
|
157
|
+
clock = @client.clock
|
158
|
+
expect(clock).to be_a Tradier::Clock
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#calendar' do
|
163
|
+
before do
|
164
|
+
stub_get("/v1/markets/calendar").
|
165
|
+
to_return(:body => fixture("calendar.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
166
|
+
end
|
167
|
+
|
168
|
+
it "requests the correct resource" do
|
169
|
+
@client.calendar
|
170
|
+
expect(a_get("/v1/markets/calendar")).to have_been_made
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns a calendar object" do
|
174
|
+
calendar = @client.calendar
|
175
|
+
expect(calendar).to be_a Tradier::Calendar
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#timesales' do
|
180
|
+
before do
|
181
|
+
stub_get("/v1/markets/timesales").
|
182
|
+
with(:query => { :symbol => 'AAPL' }).
|
183
|
+
to_return(:body => fixture("timesales.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
184
|
+
end
|
185
|
+
|
186
|
+
it "requests the correct resource" do
|
187
|
+
@client.timesales('AAPL')
|
188
|
+
|
189
|
+
expect(a_get("/v1/markets/timesales").
|
190
|
+
with(:query => { :symbol => 'AAPL' })).to have_been_made
|
191
|
+
end
|
192
|
+
|
193
|
+
it "returns an array of Tradier::Timesales objects" do
|
194
|
+
timesales = @client.timesales('AAPL')
|
195
|
+
expect(timesales).to be_an Array
|
196
|
+
expect(timesales.first).to be_an Tradier::Timesales
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#history' do
|
201
|
+
before do
|
202
|
+
stub_get("/v1/markets/history").
|
203
|
+
with(:query => { :symbol => 'AAPL' }).
|
204
|
+
to_return(:body => fixture("history.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
205
|
+
end
|
206
|
+
|
207
|
+
it "requests the correct resource" do
|
208
|
+
@client.history('AAPL')
|
209
|
+
expect(a_get("/v1/markets/history").
|
210
|
+
with(:query => { :symbol => 'AAPL' })).to have_been_made
|
211
|
+
end
|
212
|
+
|
213
|
+
it "returns an array of Tradier::History objects" do
|
214
|
+
history = @client.history('AAPL')
|
215
|
+
expect(history).to be_an Array
|
216
|
+
expect(history.first).to be_a Tradier::History
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tradier::API::Accounts do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Tradier::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#create_order' do
|
10
|
+
context 'when passed an account number' do
|
11
|
+
before do
|
12
|
+
stub_post("/v1/accounts/123456789/orders").
|
13
|
+
to_return(:body => fixture("order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
it "requests the correct resource" do
|
16
|
+
@client.create_order(:account => 123456789)
|
17
|
+
expect(a_post("/v1/accounts/123456789/orders")).to have_been_made
|
18
|
+
end
|
19
|
+
it "returns a Tradier::Order" do
|
20
|
+
order = @client.create_order(:account => 123456789)
|
21
|
+
expect(order).to be_a Tradier::Order
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#preview_order' do
|
27
|
+
context 'when passed an account number' do
|
28
|
+
before do
|
29
|
+
stub_post("/v1/accounts/123456789/orders").
|
30
|
+
to_return(:body => fixture("order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
31
|
+
end
|
32
|
+
it "requests the correct resource" do
|
33
|
+
@client.preview_order(:account => 123456789)
|
34
|
+
expect(a_post("/v1/accounts/123456789/orders").with(body: 'preview=true')).to have_been_made
|
35
|
+
end
|
36
|
+
it "returns a Tradier::Order" do
|
37
|
+
order = @client.preview_order(:account => 123456789)
|
38
|
+
expect(order).to be_a Tradier::Order
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#cancel_order' do
|
44
|
+
context 'when passed an account number' do
|
45
|
+
before do
|
46
|
+
stub_delete("/v1/accounts/123456789/orders/54321").
|
47
|
+
to_return(:body => fixture("order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
48
|
+
end
|
49
|
+
it "requests the correct resource" do
|
50
|
+
@client.cancel_order(:account => 123456789, :id => 54321)
|
51
|
+
expect(a_delete("/v1/accounts/123456789/orders/54321")).to have_been_made
|
52
|
+
end
|
53
|
+
it "returns a Tradier::Order" do
|
54
|
+
order = @client.cancel_order(:account => 123456789, :id => 54321)
|
55
|
+
expect(order).to be_a Tradier::Order
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#order' do
|
61
|
+
context 'when passed an account number' do
|
62
|
+
before do
|
63
|
+
stub_get("/v1/accounts/123456789/orders/54321").
|
64
|
+
to_return(:body => fixture("order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
65
|
+
end
|
66
|
+
it "requests the correct resource" do
|
67
|
+
@client.order(:account => 123456789, :id => 54321)
|
68
|
+
expect(a_get("/v1/accounts/123456789/orders/54321")).to have_been_made
|
69
|
+
end
|
70
|
+
it "returns a Tradier::Order" do
|
71
|
+
order = @client.order(:account => 123456789, :id => 54321)
|
72
|
+
expect(order).to be_a Tradier::Order
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#update_order' do
|
78
|
+
context 'when passed an account number' do
|
79
|
+
before do
|
80
|
+
stub_put("/v1/accounts/123456789/orders/54321").
|
81
|
+
to_return(:body => fixture("order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
82
|
+
end
|
83
|
+
it "requests the correct resource" do
|
84
|
+
@client.update_order(:account => 123456789, :id => 54321, :price => 4.00)
|
85
|
+
expect(a_put("/v1/accounts/123456789/orders/54321")).to have_been_made
|
86
|
+
end
|
87
|
+
it "returns a Tradier::Order" do
|
88
|
+
order = @client.update_order(:account => 123456789, :id => 54321, :price => 4.00)
|
89
|
+
expect(order).to be_a Tradier::Order
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|