tradier 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/.yardopts
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Tradier Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Tradier
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tradier.png)][gem]
|
4
|
+
[![Build Status](https://secure.travis-ci.org/tradier/tradier.rb.png?branch=master)][travis]
|
5
|
+
[![Dependency Status](https://gemnasium.com/tradier/tradier.rb.png?travis)][gemnasium]
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/tradier/tradier.rb/badge.png?branch=master)][coveralls]
|
7
|
+
|
8
|
+
[gem]: https://rubygems.org/gems/tradier
|
9
|
+
[travis]: http://travis-ci.org/tradier/tradier.rb
|
10
|
+
[gemnasium]: https://gemnasium.com/tradier/tradier.rb
|
11
|
+
[coveralls]: https://coveralls.io/r/tradier/tradier.rb
|
12
|
+
|
13
|
+
Rubygem for interacting with the Tradier API.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
gem install tradier
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create an instance of a `Tradier::Client`:
|
22
|
+
|
23
|
+
require 'tradier'
|
24
|
+
|
25
|
+
client = Tradier::Client.new(:access_token => 'token')
|
26
|
+
|
27
|
+
### Placing Orders
|
28
|
+
|
29
|
+
Orders can be placed using the `create_order` method. Here are some basic examples:
|
30
|
+
|
31
|
+
Place an equity order:
|
32
|
+
|
33
|
+
client.create_order({
|
34
|
+
:account => '123456789'
|
35
|
+
:class => 'equity',
|
36
|
+
:symbol => 'AAPL',
|
37
|
+
:duration => 'day',
|
38
|
+
:side => 'buy',
|
39
|
+
:quantity => '100',
|
40
|
+
:type => 'market'
|
41
|
+
})
|
42
|
+
|
43
|
+
Placing an option order:
|
44
|
+
|
45
|
+
client.create_order({
|
46
|
+
:account => '123456789'
|
47
|
+
:class => 'option',
|
48
|
+
:symbol => 'AAPL',
|
49
|
+
:option_symbol => 'AAPL140118C00195000',
|
50
|
+
:duration => 'day',
|
51
|
+
:side => 'buy',
|
52
|
+
:quantity => '100',
|
53
|
+
:type => 'market'
|
54
|
+
})
|
55
|
+
|
56
|
+
|
57
|
+
For a complete list of the types of orders accepted, refer to [Tradier's trading API documentation][trading]
|
58
|
+
|
59
|
+
[trading]: https://developer.tradier.com/documentation/trading/getting-started
|
60
|
+
|
61
|
+
### Interacting with Accounts
|
62
|
+
|
63
|
+
Obtain a user's profile/accounts:
|
64
|
+
|
65
|
+
client.profile
|
66
|
+
|
67
|
+
#### Balances
|
68
|
+
|
69
|
+
Obtain an account's balances:
|
70
|
+
|
71
|
+
client.balance('12345678')
|
72
|
+
|
73
|
+
#### Positions
|
74
|
+
|
75
|
+
Obtain an account's positions
|
76
|
+
|
77
|
+
client.positions('12345678')
|
78
|
+
|
79
|
+
Obtain positions for all of a user's accounts:
|
80
|
+
|
81
|
+
client.positions
|
82
|
+
|
83
|
+
#### Orders
|
84
|
+
|
85
|
+
Obtain an account's order
|
86
|
+
|
87
|
+
client.orders('12345678')
|
88
|
+
|
89
|
+
Obtain order for all of a user's accounts:
|
90
|
+
|
91
|
+
client.orders
|
92
|
+
|
93
|
+
### Market Data
|
94
|
+
|
95
|
+
To obtain a quote, simply request:
|
96
|
+
|
97
|
+
client.quote('SYMBOL')
|
98
|
+
|
99
|
+
Or multiple quotes at one time:
|
100
|
+
|
101
|
+
client.quote(['SYMBOL', 'SYMBOL2'])
|
102
|
+
|
103
|
+
Option chains can be requested using a symbol and expiration:
|
104
|
+
|
105
|
+
client.chain('SYMBOL', :expiration => '2013-11-14')
|
106
|
+
|
107
|
+
|
108
|
+
Refer to the complete [documentation][rdoc] for a complete listing of methods and classes.
|
109
|
+
|
110
|
+
[rdoc]: http://rdoc.info/gems/tradier
|
111
|
+
|
112
|
+
## Copyright
|
113
|
+
|
114
|
+
Copyright (c) 2013 Tradier Inc. See [LICENSE](LICENSE.md) for detail.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
+
t.ruby_opts = '-w'
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
11
|
+
task :test => :spec
|
12
|
+
|
13
|
+
require 'yard'
|
14
|
+
namespace :doc do
|
15
|
+
YARD::Rake::YardocTask.new do |task|
|
16
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
17
|
+
task.options = ['--markup', 'markdown']
|
18
|
+
end
|
19
|
+
end
|
data/lib/tradier.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'tradier/error'
|
2
|
+
require 'tradier/client'
|
3
|
+
require 'tradier/configurable'
|
4
|
+
require 'tradier/default'
|
5
|
+
|
6
|
+
module Tradier
|
7
|
+
class << self
|
8
|
+
include Tradier::Configurable
|
9
|
+
|
10
|
+
# Delegate to a Tradier::Client
|
11
|
+
#
|
12
|
+
# @return [Tradier::Client]
|
13
|
+
def client
|
14
|
+
@client = Tradier::Client.new(options) unless defined?(@client) && @client.hash == options.hash
|
15
|
+
@client
|
16
|
+
end
|
17
|
+
|
18
|
+
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
|
19
|
+
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def method_missing(method_name, *args, &block)
|
24
|
+
return super unless client.respond_to?(method_name)
|
25
|
+
client.send(method_name, *args, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Tradier.setup
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'tradier/base'
|
2
|
+
|
3
|
+
module Tradier
|
4
|
+
class Account < Tradier::Base
|
5
|
+
attr_reader :account_number, :type
|
6
|
+
|
7
|
+
def margin?
|
8
|
+
type.downcase == 'margin'
|
9
|
+
end
|
10
|
+
|
11
|
+
def cash?
|
12
|
+
type.downcase == 'cash'
|
13
|
+
end
|
14
|
+
|
15
|
+
def positions
|
16
|
+
@attrs[:positions][:position].map { |a| Tradier::Position.new(a) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def orders
|
20
|
+
@attrs[:orders][:order].map { |a| Tradier::Order.new(a) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def gainloss
|
24
|
+
end
|
25
|
+
|
26
|
+
def history
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'tradier/api/utils'
|
2
|
+
|
3
|
+
module Tradier
|
4
|
+
module API
|
5
|
+
module Accounts
|
6
|
+
include Tradier::API::Utils
|
7
|
+
|
8
|
+
# @see https://developer.tradier.com/documentation/user/get-profile
|
9
|
+
# @rate_limited Yes
|
10
|
+
# @authentication Requires user context
|
11
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
12
|
+
# @return [Tradier::Profile] The user's profile.
|
13
|
+
def profile
|
14
|
+
object_from_response(Tradier::Profile, :get, '/user/profile', {})
|
15
|
+
end
|
16
|
+
alias user_profile profile
|
17
|
+
|
18
|
+
# @see https://developer.tradier.com/documentation/user/get-balances
|
19
|
+
# @see https://developer.tradier.com/documentation/accounts/get-account-balance
|
20
|
+
# @rate_limited Yes
|
21
|
+
# @authentication Requires user context
|
22
|
+
# @overload balances
|
23
|
+
# Request a user's balances.
|
24
|
+
# @return [Array<Tradier::Balance>] An array of balances.
|
25
|
+
# @overload balances(account_number)
|
26
|
+
# Request an individual account's balance.
|
27
|
+
# @param [String] account_number An account number.
|
28
|
+
# @return [Tradier::Balance] The account balance object when a single account is requested.
|
29
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
30
|
+
def balances(account_number=nil, options={})
|
31
|
+
if account_number
|
32
|
+
object_from_response(Tradier::Balance, :get, "/accounts/#{account_number}/balances", options)
|
33
|
+
else
|
34
|
+
object_from_response(Tradier::API::Utils::Balance, :get, "/user/balances", options).body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
alias balance balances
|
38
|
+
|
39
|
+
# @see https://developer.tradier.com/documentation/user/get-positions
|
40
|
+
# @see https://developer.tradier.com/documentation/accounts/get-account-positions
|
41
|
+
# @rate_limited Yes
|
42
|
+
# @authentication Requires user context
|
43
|
+
# @overload positions
|
44
|
+
# Request a user's positions.
|
45
|
+
# @return [Array<Tradier::Account>] An array of accounts with positions.
|
46
|
+
# @overload positions(account_number)
|
47
|
+
# Request an individual account's positions.
|
48
|
+
# @param [String] account_number An account number.
|
49
|
+
# @return [Array<Tradier::Position>] An array of [Tradier::Position] objects for a given account.
|
50
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
51
|
+
def positions(account_number=nil, options={})
|
52
|
+
if account_number
|
53
|
+
object_from_response(Tradier::API::Utils::Position, :get, "/accounts/#{account_number}/positions", options).body
|
54
|
+
else
|
55
|
+
object_from_response(Tradier::API::Utils::Account, :get, '/user/positions', options).body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
alias position positions
|
59
|
+
|
60
|
+
# @see https://developer.tradier.com/documentation/user/get-orders
|
61
|
+
# @see https://developer.tradier.com/documentation/accounts/get-account-orders
|
62
|
+
# @rate_limited Yes
|
63
|
+
# @authentication Requires user context
|
64
|
+
# @overload orders
|
65
|
+
# Request a user's orders.
|
66
|
+
# @return [Array<Tradier::Account>] An array of accounts with orders.
|
67
|
+
# @overload orders(account_number)
|
68
|
+
# Request a specific account's orders.
|
69
|
+
# @param [String] account_number An account number (optional).
|
70
|
+
# @return [Array<Tradier::Order>] An array of [Tradier::Order] objects for a given account.
|
71
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
72
|
+
def orders(account_number=nil, options={})
|
73
|
+
if account_number
|
74
|
+
object_from_response(Tradier::API::Utils::Order, :get, "/accounts/#{account_number}/orders", options).body
|
75
|
+
else
|
76
|
+
object_from_response(Tradier::API::Utils::Account, :get, '/user/orders', options).body
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# @see https://developer.tradier.com/documentation/user/get-gainloss
|
81
|
+
# @see https://developer.tradier.com/documentation/accounts/get-account-gainloss
|
82
|
+
# @rate_limited Yes
|
83
|
+
# @authentication Requires user context
|
84
|
+
# @overload gainloss
|
85
|
+
# Request a user's cost basis.
|
86
|
+
# @return [Array<Tradier::Account>] An array of accounts with cost-basis.
|
87
|
+
# @overload gainloss(account_number)
|
88
|
+
# Request a specific account's cost basis.
|
89
|
+
# @param [String] account_number An account number (optional).
|
90
|
+
# @return [Array<Tradier::Position>] An array of [Tradier::Position] objects for a given account.
|
91
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
92
|
+
def gainloss(account_number=nil, options={})
|
93
|
+
if account_number
|
94
|
+
object_from_response(Tradier::API::Utils::Gainloss, :get, "/accounts/#{account_number}/gainloss", options).body
|
95
|
+
else
|
96
|
+
object_from_response(Tradier::API::Utils::Account, :get, '/user/gainloss', options).body
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# @see https://developer.tradier.com/documentation/user/get-history
|
101
|
+
# @see https://developer.tradier.com/documentation/accounts/get-account-history
|
102
|
+
# @rate_limited Yes
|
103
|
+
# @authentication Requires user context
|
104
|
+
# @overload events
|
105
|
+
# Request a user's events.
|
106
|
+
# @return [Array<Tradier::Account>] An array of accounts with history.
|
107
|
+
# @overload events(account_number)
|
108
|
+
# Request a specific account's events.
|
109
|
+
# @param [String] account_number An account number (optional).
|
110
|
+
# @return [Array<Tradier::Event>] An array of [Tradier::Event] objects for a given account.
|
111
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
112
|
+
def events(account_number=nil, options={})
|
113
|
+
if account_number
|
114
|
+
object_from_response(Tradier::API::Utils::Event, :get, "/accounts/#{account_number}/history", options).body
|
115
|
+
else
|
116
|
+
object_from_response(Tradier::API::Utils::Account, :get, '/user/history', options).body
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'tradier/api/utils'
|
2
|
+
|
3
|
+
module Tradier
|
4
|
+
module API
|
5
|
+
module Markets
|
6
|
+
include Tradier::API::Utils
|
7
|
+
|
8
|
+
# @see https://developer.tradier.com/documentation/markets/get-quotes
|
9
|
+
# @rate_limited Yes
|
10
|
+
# @authentication Requires user context
|
11
|
+
# Obtain quotes.
|
12
|
+
# @param [String] symbols A comma delimited list of symbols.
|
13
|
+
# @return [Array<Tradier::Quote>] An array of expiration dates.
|
14
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
15
|
+
def quotes(symbols, options={})
|
16
|
+
options.merge!('symbols' => normalized_symbols(symbols))
|
17
|
+
object_from_response(Tradier::API::Utils::Quote, :get, '/markets/quotes', options).body
|
18
|
+
end
|
19
|
+
alias quote quotes
|
20
|
+
|
21
|
+
# @see https://developer.tradier.com/documentation/markets/get-options-chains
|
22
|
+
# @rate_limited Yes
|
23
|
+
# @authentication Requires user context
|
24
|
+
# Obtain an option chain.
|
25
|
+
# @param [String] symbol The underlier's symbol.
|
26
|
+
# @return [Array<Tradier::OptionQuote>] An array of option quotes.
|
27
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
28
|
+
def chains(symbol, options={})
|
29
|
+
options.merge!('symbol' => symbol)
|
30
|
+
object_from_response(Tradier::API::Utils::OptionQuote, :get, '/markets/options/chains', options).body
|
31
|
+
end
|
32
|
+
alias chain chains
|
33
|
+
|
34
|
+
# @see https://developer.tradier.com/documentation/markets/get-options-expirations
|
35
|
+
# @rate_limited Yes
|
36
|
+
# @authentication Requires user context
|
37
|
+
# Obtain an underlier's expiration dates.
|
38
|
+
# @param [String] symbol The underlier's symbol.
|
39
|
+
# @return [Array<Date>] An array of expiration dates.
|
40
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
41
|
+
def expirations(symbol)
|
42
|
+
object_from_response(Tradier::API::Utils::Expiration, :get, '/markets/options/expirations', :symbol => symbol).body
|
43
|
+
end
|
44
|
+
|
45
|
+
# @see https://developer.tradier.com/documentation/markets/get-options-strikes
|
46
|
+
# @rate_limited Yes
|
47
|
+
# @authentication Requires user context
|
48
|
+
# Obtain an underlier's expiration strikes for an expiration date.
|
49
|
+
# @param [String] symbol The underlier symbol.
|
50
|
+
# @param [String] expiration The expiration date.
|
51
|
+
# @return [Array<String>] An array of strike prices.
|
52
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
53
|
+
def strikes(symbol, expiration)
|
54
|
+
object_from_response(Tradier::API::Utils::Strike, :get, '/markets/options/strikes', :symbol => symbol, :expiration => expiration).body
|
55
|
+
end
|
56
|
+
|
57
|
+
# @see https://developer.tradier.com/documentation/markets/get-clock
|
58
|
+
# @rate_limited Yes
|
59
|
+
# @authentication Requires user context
|
60
|
+
# Obtain the market clock
|
61
|
+
# @return [Tradier::Clock] A clock.
|
62
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
63
|
+
def clock(options={})
|
64
|
+
object_from_response(Tradier::Clock, :get, '/markets/clock', options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @see https://developer.tradier.com/documentation/markets/get-calendar
|
68
|
+
# @rate_limited Yes
|
69
|
+
# @authentication Requires user context
|
70
|
+
# Obtain the market calendar
|
71
|
+
# @return [Tradier::Calendar] A calendar.
|
72
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
73
|
+
def calendar(options={})
|
74
|
+
object_from_response(Tradier::Calendar, :get, '/markets/calendar', options)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @see https://developer.tradier.com/documentation/markets/get-timesales
|
78
|
+
# @rate_limited Yes
|
79
|
+
# @authentication Requires user context
|
80
|
+
# Get time and sales for a given symbol.
|
81
|
+
# @param [String] symbol The symbol.
|
82
|
+
# @return [Array<Tradier::Timesales>] An array of Time and Sales quotes.
|
83
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
84
|
+
def timesales(symbol, options={})
|
85
|
+
options.merge!('symbol' => symbol)
|
86
|
+
object_from_response(Tradier::API::Utils::Timesales, :get, '/markets/timesales', options).body
|
87
|
+
end
|
88
|
+
|
89
|
+
# @see https://developer.tradier.com/documentation/markets/get-history
|
90
|
+
# @rate_limited Yes
|
91
|
+
# @authentication Requires user context
|
92
|
+
# Get historical pricing for a given symbol.
|
93
|
+
# @param [String] symbol The symbol.
|
94
|
+
# @return [Array<Tradier::Event>] An array of historical quotes.
|
95
|
+
# @raise [Tradier::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
96
|
+
def history(symbol, options={})
|
97
|
+
options.merge!('symbol' => symbol)
|
98
|
+
object_from_response(Tradier::API::Utils::History, :get, '/markets/history', options).body
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def normalized_symbols(symbols)
|
104
|
+
if symbols.is_a? Array
|
105
|
+
symbols.map(&:strip).join(',')
|
106
|
+
else
|
107
|
+
symbols
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|