questrade_client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +2 -0
- data/lib/questrade_client.rb +1 -0
- data/lib/questrade_client/account.rb +78 -0
- data/lib/questrade_client/client.rb +4 -0
- data/lib/questrade_client/market.rb +87 -0
- data/lib/questrade_client/questrade.rb +1 -0
- data/lib/questrade_client/questrade/account.rb +21 -0
- data/lib/questrade_client/symbol.rb +53 -0
- data/lib/questrade_client/version.rb +1 -1
- metadata +6 -3
- data/lib/questrade_client/.client.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b18f7922f87c8f75bf1019fec336f92c0bd120eb
|
4
|
+
data.tar.gz: efb8e2b915e91ccb3b239133709f6cab4bc94f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b14a49e7b136bf20303309f2946c1f9861d0dc4a99344d4aef418a04a5cd1e2ce5868ce00706345b8b573940a71571cf5f33d30d423b80eb6253292e7ae4b20
|
7
|
+
data.tar.gz: bc1c756e572bb1e88301708aed540c3c0a38229ba3d1832e64b40258cc0365c4919a3004f6c5f5339f374f11cb133bb3b146eab05b800af5a1ec96efd76d8d05
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/lib/questrade_client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module QuestradeClient
|
2
2
|
module Account
|
3
|
+
|
3
4
|
# Retrieves current server time.
|
4
5
|
#
|
5
6
|
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/time
|
@@ -11,5 +12,82 @@ module QuestradeClient
|
|
11
12
|
DateTime.parse(get('/time')['time'])
|
12
13
|
end
|
13
14
|
|
15
|
+
# Retrieves the accounts associated with the user on behalf of which the API client is authorized.
|
16
|
+
#
|
17
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts
|
18
|
+
#
|
19
|
+
# @return [Array[Hash]] List of accounts
|
20
|
+
# @example
|
21
|
+
# client.accounts
|
22
|
+
def accounts
|
23
|
+
get('/accounts')['accounts']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieves positions in a specified account.
|
27
|
+
#
|
28
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-positions
|
29
|
+
#
|
30
|
+
# @return [Array[Hash]] List of positions for the account
|
31
|
+
# @param id [String] The ID of the account
|
32
|
+
# @example
|
33
|
+
# client.positions(id)
|
34
|
+
def positions(id)
|
35
|
+
get("/accounts/#{id}/positions")['positions']
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieves per-currency and combined balances for a specified account.
|
39
|
+
#
|
40
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
|
41
|
+
#
|
42
|
+
# @return [Hash] Balance data for this account
|
43
|
+
# @param id [String] The ID of the account
|
44
|
+
# @example
|
45
|
+
# client.balances(id)
|
46
|
+
def balances(id)
|
47
|
+
get("/accounts/#{id}/balances")
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieves executions for a specific account.
|
51
|
+
#
|
52
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-executions
|
53
|
+
#
|
54
|
+
# FIXME: Add support for start and end time
|
55
|
+
# @return [Array[Hash]] List of executions
|
56
|
+
# @param id [String] The ID of the account
|
57
|
+
# @example
|
58
|
+
# client.executions(id)
|
59
|
+
def executions(id)
|
60
|
+
get("/accounts/#{id}/executions")['executions']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Retrieves orders for specified account
|
64
|
+
#
|
65
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-orders
|
66
|
+
#
|
67
|
+
# FIXME: Add support for start and end time
|
68
|
+
# FIXME: Add support for statefilter
|
69
|
+
# @return [Array[Hash]] List of orders
|
70
|
+
# @param id [String] The ID of the account
|
71
|
+
# @param orderid [String] Only retrieve the order matching the specified order ID (optional)
|
72
|
+
# @example
|
73
|
+
# client.orders(id)
|
74
|
+
def orders(id, orderid = nil)
|
75
|
+
get("/accounts/#{id}/orders#{orderid ? "/#{orderid}" : ''}")['orders']
|
76
|
+
end
|
77
|
+
|
78
|
+
# Retrieve account activities, including cash transactions, dividends, trades, etc.
|
79
|
+
#
|
80
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-activities
|
81
|
+
#
|
82
|
+
# FIXME: Add support for start and end time
|
83
|
+
# @return [Array[Hash]] List of orders
|
84
|
+
# @param id [String] The ID of the account
|
85
|
+
# @param orderid [String] Only retrieve the order matching the specified order ID (optional)
|
86
|
+
# @example
|
87
|
+
# client.activities(id)
|
88
|
+
def activities(id)
|
89
|
+
get("/accounts/#{id}/activities")['activities']
|
90
|
+
end
|
91
|
+
|
14
92
|
end
|
15
93
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'questrade_client/account'
|
2
|
+
require 'questrade_client/symbol'
|
3
|
+
require 'questrade_client/market'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
|
4
6
|
module QuestradeClient
|
@@ -42,6 +44,8 @@ module QuestradeClient
|
|
42
44
|
end
|
43
45
|
|
44
46
|
include QuestradeClient::Account
|
47
|
+
include QuestradeClient::Symbol
|
48
|
+
include QuestradeClient::Market
|
45
49
|
|
46
50
|
private
|
47
51
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module QuestradeClient
|
2
|
+
module Market
|
3
|
+
CANDLESTICK_INTERVALS = {
|
4
|
+
oneminute: 'OneMinute', # one candlestick per 1 minute.
|
5
|
+
twominutes: 'TwoMinutes', # one candlestick per 2 minutes.
|
6
|
+
threeminutes: 'ThreeMinutes', # one candlestick per 3 minutes.
|
7
|
+
fourminutes: 'FourMinutes', # one candlestick per 4 minutes.
|
8
|
+
fiveminutes: 'FiveMinutes', # one candlestick per 5 minutes.
|
9
|
+
tenminutes: 'TenMinutes', # one candlestick per 10 minutes.
|
10
|
+
fifteenminutes: 'FifteenMinutes', # one candlestick per 15 minutes.
|
11
|
+
twentyminutes: 'TwentyMinutes', # one candlestick per 20 minutes.
|
12
|
+
halfhour: 'HalfHour', # one candlestick per 30 minutes.
|
13
|
+
onehour: 'OneHour', # one candlestick per 1 hour.
|
14
|
+
twohours: 'TwoHours', # one candlestick per 2 hours.
|
15
|
+
fourhours: 'FourHours', # one candlestick per 4 hours.
|
16
|
+
oneday: 'OneDay', # one candlestick per 1 day.
|
17
|
+
oneweek: 'OneWeek', # one candlestick per 1 week.
|
18
|
+
onemonth: 'OneMonth', # one candlestick per 1 month.
|
19
|
+
oneyear: 'OneYear' # one candlestick per 1 year.
|
20
|
+
}
|
21
|
+
|
22
|
+
# Retrieves information about supported markets.
|
23
|
+
#
|
24
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets
|
25
|
+
#
|
26
|
+
# @return [Array[Hash]] List of market data
|
27
|
+
# @example
|
28
|
+
# client.markets
|
29
|
+
def markets
|
30
|
+
get('/markets')['markets']
|
31
|
+
end
|
32
|
+
|
33
|
+
# Retrieves a single Level 1 market data quote for one or more symbols.
|
34
|
+
#
|
35
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-id
|
36
|
+
#
|
37
|
+
# @return [Array[Hash]] List of market data
|
38
|
+
# @param args [Int|Array[Int]] The ID of the symbol, or a list of symbol ids
|
39
|
+
# @example
|
40
|
+
# client.quotes(9292)
|
41
|
+
# client.quotes([9292,8081])
|
42
|
+
def quotes(args)
|
43
|
+
if args.is_a?(Integer)
|
44
|
+
get("/markets/quotes/#{args}")['quotes']
|
45
|
+
elsif args.is_a?(Array)
|
46
|
+
get("/markets/quotes?ids=#{args.join(',')}")['quotes']
|
47
|
+
else
|
48
|
+
fail "Malformed argument: #{args}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Retrieves a single Level 1 market data quote and Greek data for one or more option symbols.
|
53
|
+
#
|
54
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-options
|
55
|
+
#
|
56
|
+
# FIXME - implement (docs are WRONG, it's a POST, not a GET)
|
57
|
+
def quoteoptions()
|
58
|
+
fail "Not yet implemented"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Retrieve a calculated L1 market data quote for a single or many multi-leg strategies
|
62
|
+
#
|
63
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-quotes-strategies
|
64
|
+
#
|
65
|
+
# FIXME - implement (docs are WRONG, it's a POST, not a GET)
|
66
|
+
def quotestrategies()
|
67
|
+
fail "Not yet implemented"
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Retrieves historical market data in the form of OHLC candlesticks for a specified symbol.
|
72
|
+
# This call is limited to returning 2,000 candlesticks in a single response.
|
73
|
+
#
|
74
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/markets-candles-id
|
75
|
+
#
|
76
|
+
# @return [Array[Hash]] List of market data
|
77
|
+
# FIXME: REQUIRES start and end time
|
78
|
+
# @param id [Integer] the id of the symbol to retrieve candlestick data for
|
79
|
+
# @param interval [Symbol] the candlestick interval to use, see allowable values in CANDLESTICK_INTERVALS
|
80
|
+
# @example
|
81
|
+
# client.candles(9292, :oneday)
|
82
|
+
def candles(id, interval)
|
83
|
+
fail "Interval #{interval} is unsupported" unless CANDLESTICK_INTERVALS.includes?(interval)
|
84
|
+
get("/markets/candles/#{id}?interval=#{CANDLESTICK_INTERVALS[interval]}")['quotes']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'questrade_client/questrade/account'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
class JSONSerialized < OpenStruct
|
3
|
+
end
|
4
|
+
|
5
|
+
module QuestradeClient
|
6
|
+
class Questrade
|
7
|
+
|
8
|
+
def initialize(refresh_token, practice = false)
|
9
|
+
@client = QuestradeClient.login(refresh_token, practice)
|
10
|
+
end
|
11
|
+
|
12
|
+
def accounts
|
13
|
+
@client.accounts.map do |account_data|
|
14
|
+
Account.new(account_data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Account < JSONSerialized
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module QuestradeClient
|
2
|
+
module Symbol
|
3
|
+
|
4
|
+
# Retrieves the accounts associated with the user on behalf of which the API client is authorized.
|
5
|
+
#
|
6
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts
|
7
|
+
#
|
8
|
+
# @return [Array[Hash]] List of symbol data
|
9
|
+
# @param args [Int|Array[Int|String]] The ID of the symbol, or a list of symbol ids or names
|
10
|
+
# @example
|
11
|
+
# client.symbols(9292)
|
12
|
+
# client.symbols(['BMO', 'SHOP', 'VTI'])
|
13
|
+
# client.symbols([9292, 8089])
|
14
|
+
def symbols(args)
|
15
|
+
if args.is_a?(Integer)
|
16
|
+
get("/symbols/#{args}")['symbols']
|
17
|
+
elsif args.length > 1 && args.first.is_a?(String)
|
18
|
+
get("/symbols?names=#{args.join(',')}")['symbols']
|
19
|
+
elsif args.length > 1 && args.first.is_a?(Integer)
|
20
|
+
get("/symbols?ids=#{args.join(',')}")['symbols']
|
21
|
+
else
|
22
|
+
fail "Malformed argument: #{args}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieves symbol(s) using several search criteria.
|
27
|
+
#
|
28
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-search
|
29
|
+
#
|
30
|
+
# @return [Array[Hash]] List of symbol data
|
31
|
+
# FIXME: add offset
|
32
|
+
# @param prefix [String] Prefix to use in search
|
33
|
+
# @example
|
34
|
+
# client.symbolsearch('BMO')
|
35
|
+
def symbolsearch(prefix, offset=nil)
|
36
|
+
get("/symbols/search?prefix=#{prefix}")['symbols']
|
37
|
+
end
|
38
|
+
|
39
|
+
# Retrieves an option chain for a particular underlying symbol.
|
40
|
+
#
|
41
|
+
# Docs: http://www.questrade.com/api/documentation/rest-operations/market-calls/symbols-id-options
|
42
|
+
#
|
43
|
+
# @return [Array[Hash]] List of option chain data for symbol
|
44
|
+
# @param [Integer] Symbol id to find options for
|
45
|
+
# @example
|
46
|
+
# client.symboloptions(9292)
|
47
|
+
def symboloptions(symbolid)
|
48
|
+
get("/symbols/#{symbolid}/options")['optionChain']
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: questrade_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Hamel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -169,9 +169,12 @@ files:
|
|
169
169
|
- bin/rubocop
|
170
170
|
- bin/setup
|
171
171
|
- lib/questrade_client.rb
|
172
|
-
- lib/questrade_client/.client.rb.swp
|
173
172
|
- lib/questrade_client/account.rb
|
174
173
|
- lib/questrade_client/client.rb
|
174
|
+
- lib/questrade_client/market.rb
|
175
|
+
- lib/questrade_client/questrade.rb
|
176
|
+
- lib/questrade_client/questrade/account.rb
|
177
|
+
- lib/questrade_client/symbol.rb
|
175
178
|
- lib/questrade_client/version.rb
|
176
179
|
- questrade_client.gemspec
|
177
180
|
homepage: https://github.com/dalehamel/questrade_client
|
Binary file
|