questrade_api 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/questrade_api/client.rb +9 -97
- data/lib/questrade_api/modules/account_call.rb +57 -0
- data/lib/questrade_api/modules/market_call.rb +42 -0
- data/lib/questrade_api/rest/account.rb +7 -7
- data/lib/questrade_api/rest/activity.rb +1 -1
- data/lib/questrade_api/rest/balance.rb +1 -1
- data/lib/questrade_api/rest/base.rb +2 -2
- data/lib/questrade_api/rest/candle.rb +1 -1
- data/lib/questrade_api/rest/execution.rb +1 -1
- data/lib/questrade_api/rest/market.rb +1 -1
- data/lib/questrade_api/rest/option.rb +1 -1
- data/lib/questrade_api/rest/order.rb +1 -1
- data/lib/questrade_api/rest/position.rb +1 -1
- data/lib/questrade_api/rest/quote.rb +2 -2
- data/lib/questrade_api/rest/symbol.rb +29 -5
- data/lib/questrade_api/rest/time.rb +6 -2
- data/lib/questrade_api/version.rb +1 -1
- data/spec/fixtures/json/symbol_01.json +51 -0
- data/spec/questrade_api/modules/account_call_spec.rb +70 -0
- data/spec/questrade_api/modules/market_call_spec.rb +68 -0
- data/spec/questrade_api/rest/account_spec.rb +6 -6
- data/spec/questrade_api/rest/activity_spec.rb +2 -2
- data/spec/questrade_api/rest/balance_spec.rb +2 -2
- data/spec/questrade_api/rest/candle_spec.rb +2 -2
- data/spec/questrade_api/rest/execution_spec.rb +2 -2
- data/spec/questrade_api/rest/market_spec.rb +2 -2
- data/spec/questrade_api/rest/option_spec.rb +2 -2
- data/spec/questrade_api/rest/order_spec.rb +2 -2
- data/spec/questrade_api/rest/position_spec.rb +2 -2
- data/spec/questrade_api/rest/quote_spec.rb +3 -3
- data/spec/questrade_api/rest/symbol_spec.rb +71 -6
- data/spec/questrade_api/rest/time_spec.rb +14 -3
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3648ccbf7f83b5173c5606b74b047e0e3c0e71d0
|
4
|
+
data.tar.gz: 8ae0d104853ccb59ae7604ba53749dde2c5bb625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8153c221b4f6e8250bfe1e0aa6c83fda5432e702c38cafb398b22dd610a437b397dc759755638c4d33cb92931a18cb4b3284b8995cec581f07b13350eb9bdd3
|
7
|
+
data.tar.gz: c59f4a154528e5d44d56ce8bc93c6cad553454327f3ebd4ec072aedb343ec8068d1db04260aa3102a86c2e54656018f8e22e978d9dbc823223d4546d3371768d
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/brunomeira/questrade_api.svg?branch=master)](https://travis-ci.org/brunomeira/questrade_api)
|
2
2
|
[![Code Climate](https://codeclimate.com/github/brunomeira/questrade_api/badges/gpa.svg)](https://codeclimate.com/github/brunomeira/questrade_api)
|
3
3
|
|
4
|
-
#
|
4
|
+
# The Questrade Ruby Api Gem
|
5
5
|
|
6
6
|
A Ruby interface to use the [Questrade API](http://www.questrade.com/api).
|
7
7
|
|
@@ -53,7 +53,7 @@ client.search_symbols(prefix: 'BMO')
|
|
53
53
|
# In case you already have a valid access token and its respective URL, you can use the QuestradeApi::REST objects. Example:
|
54
54
|
# authorization can be any object that responds to url and access_token
|
55
55
|
authorization = QuestradeApi::Authorization.new(access_token: 'access_token', api_server: 'url')
|
56
|
-
accounts = QuestradeApi::REST::Account.
|
56
|
+
accounts = QuestradeApi::REST::Account.fetch(accounts)
|
57
57
|
```
|
58
58
|
For more advanced options, check out our [documentation](http://www.rubydoc.info/gems/questrade_api/0.0.4).
|
59
59
|
|
data/lib/questrade_api/client.rb
CHANGED
@@ -1,119 +1,31 @@
|
|
1
1
|
require 'questrade_api/authorization'
|
2
|
-
require 'questrade_api/rest/time'
|
3
|
-
require 'questrade_api/rest/account'
|
4
|
-
require 'questrade_api/rest/balance'
|
5
|
-
require 'questrade_api/rest/position'
|
6
|
-
require 'questrade_api/rest/execution'
|
7
|
-
require 'questrade_api/rest/activity'
|
8
|
-
require 'questrade_api/rest/order'
|
9
2
|
|
10
|
-
require 'questrade_api/
|
11
|
-
require 'questrade_api/
|
12
|
-
require 'questrade_api/rest/quote'
|
13
|
-
require 'questrade_api/rest/candle'
|
14
|
-
require 'questrade_api/rest/option'
|
3
|
+
require 'questrade_api/modules/account_call'
|
4
|
+
require 'questrade_api/modules/market_call'
|
15
5
|
|
16
6
|
module QuestradeApi
|
17
7
|
# @author Bruno Meira <goesmeira@gmail.com>
|
18
8
|
class Client
|
19
|
-
|
9
|
+
include QuestradeApi::AccountCall
|
10
|
+
include QuestradeApi::MarketCall
|
11
|
+
|
12
|
+
attr_accessor :authorization
|
20
13
|
|
21
14
|
# @see QuestradeApi::Client#initialize for more details
|
22
15
|
def initialize(params = {}, mode = :practice)
|
23
|
-
|
16
|
+
self.authorization = QuestradeApi::Authorization.new(params, mode)
|
24
17
|
refresh_token if refresh_token?
|
25
18
|
end
|
26
19
|
|
27
20
|
# Fetches a new access_token. (see QuestradeApi::Authorization#refresh_token)
|
28
21
|
def refresh_token
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
# Fetch current server time.
|
33
|
-
#
|
34
|
-
# @return [DateTime] if no issues to call /time endpoint occurs.
|
35
|
-
# @return [nil] if current server time cannot be fetched.
|
36
|
-
def time
|
37
|
-
time = QuestradeApi::REST::Time.new(@authorization)
|
38
|
-
time.get
|
39
|
-
|
40
|
-
time.data && time.data.time
|
41
|
-
end
|
42
|
-
|
43
|
-
# Fetch all accounts associated with user.
|
44
|
-
#
|
45
|
-
# @return [Array<QuestradeApi::REST::Account>]
|
46
|
-
def accounts
|
47
|
-
QuestradeApi::REST::Account.all(@authorization).accounts
|
48
|
-
end
|
49
|
-
|
50
|
-
# Fetch all positions associated with account.
|
51
|
-
#
|
52
|
-
# @param account_id [String] to which positions will be fetched.
|
53
|
-
#
|
54
|
-
# @return [Array<QuestradeApi::REST::Position>]
|
55
|
-
def positions(account_id)
|
56
|
-
QuestradeApi::REST::Position.all(@authorization, account_id).positions
|
57
|
-
end
|
58
|
-
|
59
|
-
# Fetch all balances associated with account.
|
60
|
-
#
|
61
|
-
# @param account_id [String] to which balances will be fetched.
|
62
|
-
#
|
63
|
-
# @return [OpenStruct(per_currency_balances)]
|
64
|
-
def balances(account_id)
|
65
|
-
QuestradeApi::REST::Balance.all(@authorization, account_id)
|
66
|
-
end
|
67
|
-
|
68
|
-
def executions(account_id, params = {})
|
69
|
-
QuestradeApi::REST::Execution.all(@authorization, account_id, params)
|
70
|
-
end
|
71
|
-
|
72
|
-
def activities(account_id, params = {})
|
73
|
-
QuestradeApi::REST::Activity.all(@authorization, account_id, params)
|
74
|
-
end
|
75
|
-
|
76
|
-
def orders(account_id, params = {})
|
77
|
-
QuestradeApi::REST::Activity.all(@authorization, account_id, params)
|
78
|
-
end
|
79
|
-
|
80
|
-
def markets
|
81
|
-
QuestradeApi::REST::Market.all(@authorization)
|
82
|
-
end
|
83
|
-
|
84
|
-
def symbols(params)
|
85
|
-
QuestradeApi::REST::Symbol.all(@authorization, params)
|
86
|
-
end
|
87
|
-
|
88
|
-
def search_symbols(params)
|
89
|
-
QuestradeApi::REST::Symbol.search(@authorization, params)
|
90
|
-
end
|
91
|
-
|
92
|
-
def quotes(ids)
|
93
|
-
QuestradeApi::REST::Quote.all(@authorization, ids)
|
94
|
-
end
|
95
|
-
|
96
|
-
def quote(id)
|
97
|
-
quote =
|
98
|
-
QuestradeApi::REST::Quote.new(authorization: @authorization, id: id)
|
99
|
-
|
100
|
-
quote.get
|
101
|
-
|
102
|
-
quote
|
103
|
-
end
|
104
|
-
|
105
|
-
def candles(symbol_id, params)
|
106
|
-
QuestradeApi::REST::Candle.all(@authorization, symbol_id, params)
|
107
|
-
end
|
108
|
-
|
109
|
-
def symbol_options(symbol_id)
|
110
|
-
QuestradeApi::REST::Option.all(@authorization, symbol_id)
|
22
|
+
authorization.refresh_token
|
111
23
|
end
|
112
24
|
|
113
25
|
private
|
114
26
|
|
115
27
|
def refresh_token?
|
116
|
-
data =
|
28
|
+
data = authorization.data
|
117
29
|
data.refresh_token && !data.api_server && !data.access_token
|
118
30
|
end
|
119
31
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'questrade_api/rest/time'
|
2
|
+
require 'questrade_api/rest/account'
|
3
|
+
require 'questrade_api/rest/balance'
|
4
|
+
require 'questrade_api/rest/position'
|
5
|
+
require 'questrade_api/rest/execution'
|
6
|
+
require 'questrade_api/rest/activity'
|
7
|
+
require 'questrade_api/rest/order'
|
8
|
+
|
9
|
+
module QuestradeApi
|
10
|
+
module AccountCall
|
11
|
+
# Fetch current server time.
|
12
|
+
#
|
13
|
+
# @return [DateTime] if no issues to call /time endpoint occurs.
|
14
|
+
# @return [Faraday::Response] if current server time cannot be fetched.
|
15
|
+
def time
|
16
|
+
time = QuestradeApi::REST::Time.new(authorization)
|
17
|
+
time.fetch
|
18
|
+
end
|
19
|
+
|
20
|
+
# Fetch all accounts associated with user.
|
21
|
+
#
|
22
|
+
# @return [Array<QuestradeApi::REST::Account>]
|
23
|
+
def accounts
|
24
|
+
QuestradeApi::REST::Account.fetch(authorization)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Fetch all positions associated with account.
|
28
|
+
#
|
29
|
+
# @param account_id [String] to which positions will be fetched.
|
30
|
+
#
|
31
|
+
# @return [OpenStruct(accounts: Array<QuestradeApi::REST::Position>)]
|
32
|
+
def positions(account_id)
|
33
|
+
QuestradeApi::REST::Position.fetch(authorization, account_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Fetch all balances associated with account.
|
37
|
+
#
|
38
|
+
# @param account_id [String] to which balances will be fetched.
|
39
|
+
#
|
40
|
+
# @return [OpenStruct(per_currency_balances)]
|
41
|
+
def balances(account_id)
|
42
|
+
QuestradeApi::REST::Balance.fetch(authorization, account_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def executions(account_id, params = {})
|
46
|
+
QuestradeApi::REST::Execution.fetch(authorization, account_id, params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def activities(account_id, params = {})
|
50
|
+
QuestradeApi::REST::Activity.fetch(authorization, account_id, params)
|
51
|
+
end
|
52
|
+
|
53
|
+
def orders(account_id, params = {})
|
54
|
+
QuestradeApi::REST::Order.fetch(authorization, account_id, params)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'questrade_api/rest/market'
|
2
|
+
require 'questrade_api/rest/symbol'
|
3
|
+
require 'questrade_api/rest/quote'
|
4
|
+
require 'questrade_api/rest/candle'
|
5
|
+
require 'questrade_api/rest/option'
|
6
|
+
|
7
|
+
module QuestradeApi
|
8
|
+
module MarketCall
|
9
|
+
def markets
|
10
|
+
QuestradeApi::REST::Market.fetch(authorization)
|
11
|
+
end
|
12
|
+
|
13
|
+
def symbols(params)
|
14
|
+
QuestradeApi::REST::Symbol.fetch(authorization, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def search_symbols(params)
|
18
|
+
QuestradeApi::REST::Symbol.search(authorization, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def quotes(ids)
|
22
|
+
QuestradeApi::REST::Quote.fetch(authorization, ids)
|
23
|
+
end
|
24
|
+
|
25
|
+
def quote(id)
|
26
|
+
quote =
|
27
|
+
QuestradeApi::REST::Quote.new(authorization: authorization, id: id)
|
28
|
+
|
29
|
+
quote.fetch
|
30
|
+
|
31
|
+
quote
|
32
|
+
end
|
33
|
+
|
34
|
+
def candles(symbol_id, params)
|
35
|
+
QuestradeApi::REST::Candle.fetch(authorization, symbol_id, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def symbol_options(symbol_id)
|
39
|
+
QuestradeApi::REST::Option.fetch(authorization, symbol_id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -25,34 +25,34 @@ module QuestradeApi
|
|
25
25
|
#
|
26
26
|
# Fetch activities associated with account.
|
27
27
|
#
|
28
|
-
# @param see QuestradeApi::REST::Activity.
|
28
|
+
# @param see QuestradeApi::REST::Activity.fetch
|
29
29
|
#
|
30
30
|
# @return [OpenStruct(executions: [QuestradeApi::REST::Activity)]
|
31
31
|
def activities(params)
|
32
|
-
QuestradeApi::REST::Activity.
|
32
|
+
QuestradeApi::REST::Activity.fetch(authorization, id, params)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Fetch executions associated with account.
|
36
36
|
#
|
37
|
-
# @param see QuestradeApi::REST::Execution.
|
37
|
+
# @param see QuestradeApi::REST::Execution.fetch
|
38
38
|
#
|
39
39
|
# @return [OpenStruct(executions: [QuestradeApi::REST::Execution)]
|
40
40
|
def executions(params)
|
41
|
-
QuestradeApi::REST::Execution.
|
41
|
+
QuestradeApi::REST::Execution.fetch(authorization, id, params)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Fetch balances associated with account.
|
45
45
|
#
|
46
46
|
# @return [OpenStruct(per_currency_balances)]
|
47
47
|
def balances
|
48
|
-
QuestradeApi::REST::Balance.
|
48
|
+
QuestradeApi::REST::Balance.fetch(authorization, id)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Fetch positions associated with account.
|
52
52
|
#
|
53
53
|
# @return [OpenStruct(positions: [QuestradeApi::REST::Position])]
|
54
54
|
def positions
|
55
|
-
QuestradeApi::REST::Position.
|
55
|
+
QuestradeApi::REST::Position.fetch(authorization, id)
|
56
56
|
end
|
57
57
|
|
58
58
|
# Fetch accounts for specific authorized user.
|
@@ -62,7 +62,7 @@ module QuestradeApi
|
|
62
62
|
#
|
63
63
|
# @return [OpenStruct(accounts: [QuestradeApi::REST::Account])] if call to server is successful
|
64
64
|
# @return [Faraday::Response] if call to server is not successful
|
65
|
-
def self.
|
65
|
+
def self.fetch(authorization)
|
66
66
|
response = super(access_token: authorization.access_token,
|
67
67
|
endpoint: endpoint,
|
68
68
|
url: authorization.url)
|
@@ -21,7 +21,7 @@ module QuestradeApi
|
|
21
21
|
# @param params [Hash] with the range of dates the activities will be fetched
|
22
22
|
# @option params [String] :startTime The start time. ex: '2011-02-16T00:00:00.000000-05:00'
|
23
23
|
# @option params [String] :endTime The end time. ex: '2011-02-16T00:00:00.000000-05:00'
|
24
|
-
def self.
|
24
|
+
def self.fetch(authorization, account_number, params)
|
25
25
|
response = super(access_token: authorization.access_token,
|
26
26
|
endpoint: endpoint(account_number),
|
27
27
|
url: authorization.url,
|
@@ -20,7 +20,7 @@ module QuestradeApi
|
|
20
20
|
# @param account_number [String] with the account the activities will be fetched
|
21
21
|
# @return [OpenStruct(per_currency_balances, combined_balances, sod_per_currency_balances, sod_combined_balances)] If call succeeds. Each method returns an array of QuestradeApi::REST::Balance
|
22
22
|
# @return [Faraday::Response] if call fails.
|
23
|
-
def self.
|
23
|
+
def self.fetch(authorization, account_number)
|
24
24
|
response = super(access_token: authorization.access_token,
|
25
25
|
endpoint: endpoint(account_number),
|
26
26
|
url: authorization.url)
|
@@ -56,7 +56,7 @@ module QuestradeApi
|
|
56
56
|
@raw_body = JSON.parse(response.body)
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def fetch(params = {})
|
60
60
|
response = @connection.get do |req|
|
61
61
|
req.path = params[:endpoint] || self.class.endpoint
|
62
62
|
|
@@ -71,7 +71,7 @@ module QuestradeApi
|
|
71
71
|
end
|
72
72
|
|
73
73
|
class << self
|
74
|
-
def
|
74
|
+
def fetch(params = {})
|
75
75
|
connection = connection(params)
|
76
76
|
|
77
77
|
connection.get do |req|
|
@@ -8,7 +8,7 @@ module QuestradeApi
|
|
8
8
|
build_data(params[:data]) if @raw_body
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.fetch(authorization, symbol_id, params)
|
12
12
|
response = super(access_token: authorization.access_token,
|
13
13
|
endpoint: endpoint(symbol_id),
|
14
14
|
url: authorization.url,
|
@@ -21,7 +21,7 @@ module QuestradeApi
|
|
21
21
|
# @param params [Hash] with the range of dates the activities will be fetched
|
22
22
|
# @option params [String] :startTime The start time. ex: '2011-02-16T00:00:00.000000-05:00'
|
23
23
|
# @option params [String] :endTime The end time. ex: '2011-02-16T00:00:00.000000-05:00'
|
24
|
-
def self.
|
24
|
+
def self.fetch(authorization, account_number, params)
|
25
25
|
|
26
26
|
response = super(access_token: authorization.access_token,
|
27
27
|
endpoint: endpoint(account_number),
|
@@ -8,7 +8,7 @@ module QuestradeApi
|
|
8
8
|
build_data(params[:data]) if @raw_body
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.fetch(authorization, symbol_id)
|
12
12
|
response = super(access_token: authorization.access_token,
|
13
13
|
endpoint: endpoint(symbol_id),
|
14
14
|
url: authorization.url)
|
@@ -15,7 +15,7 @@ module QuestradeApi
|
|
15
15
|
build_data(params[:data]) if @raw_body
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
18
|
+
def self.fetch(authorization, account_number, params)
|
19
19
|
|
20
20
|
response = super(access_token: authorization.access_token,
|
21
21
|
endpoint: endpoint(account_number),
|
@@ -12,7 +12,7 @@ module QuestradeApi
|
|
12
12
|
build_data(params[:data]) if @raw_body
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.fetch(authorization, account_number)
|
16
16
|
response = super(access_token: authorization.access_token,
|
17
17
|
endpoint: endpoint(account_number),
|
18
18
|
url: authorization.url)
|
@@ -13,7 +13,7 @@ module QuestradeApi
|
|
13
13
|
build_data(params[:data]) if @raw_body
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def fetch
|
17
17
|
response = super(endpoint: endpoint)
|
18
18
|
|
19
19
|
if response.status == 200
|
@@ -23,7 +23,7 @@ module QuestradeApi
|
|
23
23
|
response
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.
|
26
|
+
def self.fetch(authorization, ids)
|
27
27
|
response = super(access_token: authorization.access_token,
|
28
28
|
endpoint: endpoint,
|
29
29
|
url: authorization.url,
|
@@ -14,15 +14,29 @@ module QuestradeApi
|
|
14
14
|
build_data(params[:data]) if @raw_body
|
15
15
|
end
|
16
16
|
|
17
|
+
def fetch
|
18
|
+
response = super(endpoint: endpoint)
|
19
|
+
|
20
|
+
if response.status == 200
|
21
|
+
parse_symbols(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
def endpoint
|
28
|
+
self.class.endpoint + "#{id}"
|
29
|
+
end
|
30
|
+
|
17
31
|
def self.endpoint(extra = '')
|
18
32
|
"#{BASE_ENDPOINT}/symbols/#{extra}"
|
19
33
|
end
|
20
34
|
|
21
35
|
def self.search(authorization, params = {})
|
22
|
-
response = superclass.
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
response = superclass.fetch(access_token: authorization.access_token,
|
37
|
+
endpoint: endpoint('search'),
|
38
|
+
url: authorization.url,
|
39
|
+
params: params)
|
26
40
|
|
27
41
|
if response.status == 200
|
28
42
|
result = OpenStruct.new(symbols: [])
|
@@ -33,7 +47,7 @@ module QuestradeApi
|
|
33
47
|
response
|
34
48
|
end
|
35
49
|
|
36
|
-
def self.
|
50
|
+
def self.fetch(authorization, params = {})
|
37
51
|
params[:ids] = params[:ids].join(',') if params[:ids]
|
38
52
|
params[:names] = params[:names].join(',') if params[:names]
|
39
53
|
|
@@ -73,6 +87,16 @@ module QuestradeApi
|
|
73
87
|
end
|
74
88
|
|
75
89
|
private_class_method :parse_symbols
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def parse_symbols(body)
|
94
|
+
raw = JSON.parse(body)
|
95
|
+
|
96
|
+
raw['symbols'].each do |symbol|
|
97
|
+
build_data(symbol)
|
98
|
+
end
|
99
|
+
end
|
76
100
|
end
|
77
101
|
end
|
78
102
|
end
|
@@ -10,10 +10,14 @@ module QuestradeApi
|
|
10
10
|
super(authorization)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def fetch
|
14
14
|
response = super
|
15
15
|
|
16
|
-
|
16
|
+
if raw_body
|
17
|
+
build_data(raw_body)
|
18
|
+
data.time = DateTime.parse(data.time)
|
19
|
+
response = data.time
|
20
|
+
end
|
17
21
|
|
18
22
|
response
|
19
23
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
{
|
2
|
+
"symbols": [
|
3
|
+
{
|
4
|
+
"symbol": "AAPL",
|
5
|
+
"symbolId": 8049,
|
6
|
+
"prevDayClosePrice": 102.5,
|
7
|
+
"highPrice52": 102.9,
|
8
|
+
"lowPrice52": 63.89,
|
9
|
+
"averageVol3Months": 43769680,
|
10
|
+
"averageVol20Days": 12860370,
|
11
|
+
"outstandingShares": 5987867000,
|
12
|
+
"eps": 6.2,
|
13
|
+
"pe": 16.54,
|
14
|
+
"dividend": 0.47,
|
15
|
+
"yield": 1.84,
|
16
|
+
"exDate": "2014-08-07T00:00:00.000000-04:00",
|
17
|
+
"marketCap": 613756367500,
|
18
|
+
"tradeUnit": 1,
|
19
|
+
"optionType": null,
|
20
|
+
"optionDurationType": null,
|
21
|
+
"optionRoot": "",
|
22
|
+
"optionContractDeliverables": {
|
23
|
+
"underlyings": [],
|
24
|
+
"cashInLieu": 0
|
25
|
+
},
|
26
|
+
"optionExerciseType": null,
|
27
|
+
"listingExchange": "NASDAQ",
|
28
|
+
"description": "APPLE INC",
|
29
|
+
"securityType": "Stock",
|
30
|
+
"optionExpiryDate": null,
|
31
|
+
"dividendDate": "2014-08-14T00:00:00.000000-04:00",
|
32
|
+
"optionStrikePrice": null,
|
33
|
+
"isTradable": true,
|
34
|
+
"isQuotable": true,
|
35
|
+
"hasOptions": true,
|
36
|
+
"minTicks": [
|
37
|
+
{
|
38
|
+
"pivot": 0,
|
39
|
+
"minTick": 0.0001
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"pivot": 1,
|
43
|
+
"minTick": 0.01
|
44
|
+
}
|
45
|
+
],
|
46
|
+
"industrySector": "BasicMaterials",
|
47
|
+
"industryGroup": "Steel",
|
48
|
+
"industrySubGroup": "Steel"
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'questrade_api/modules/account_call'
|
4
|
+
|
5
|
+
describe QuestradeApi::AccountCall do
|
6
|
+
class DummyClass
|
7
|
+
attr_accessor :authorization
|
8
|
+
|
9
|
+
def initialize(authorization)
|
10
|
+
@authorization = authorization
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:authorization) do
|
15
|
+
OpenStruct.new(access_token: '123', url: 'test')
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { DummyClass.new(authorization).extend(QuestradeApi::AccountCall) }
|
19
|
+
|
20
|
+
context '.time' do
|
21
|
+
it 'calls proper endpoint' do
|
22
|
+
time = DateTime.now
|
23
|
+
expect_any_instance_of(QuestradeApi::REST::Time).to receive(:fetch).and_return(time)
|
24
|
+
|
25
|
+
expect(subject.time).to be(time)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '.accounts' do
|
30
|
+
it 'calls proper endpoint' do
|
31
|
+
expect(QuestradeApi::REST::Account).to receive(:fetch).and_return([])
|
32
|
+
expect(subject.accounts).to eq([])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '.positions' do
|
37
|
+
it 'calls proper endpoint' do
|
38
|
+
expect(QuestradeApi::REST::Position).to receive(:fetch).and_return([])
|
39
|
+
expect(subject.positions('1')).to eq([])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '.balances' do
|
44
|
+
it 'calls proper endpoint' do
|
45
|
+
expect(QuestradeApi::REST::Balance).to receive(:fetch).and_return([])
|
46
|
+
expect(subject.balances('1')).to eq([])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '.executions' do
|
51
|
+
it 'calls proper endpoint' do
|
52
|
+
expect(QuestradeApi::REST::Execution).to receive(:fetch).and_return([])
|
53
|
+
expect(subject.executions('1')).to eq([])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '.activities' do
|
58
|
+
it 'calls proper endpoint' do
|
59
|
+
expect(QuestradeApi::REST::Activity).to receive(:fetch).and_return([])
|
60
|
+
expect(subject.activities('1')).to eq([])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '.orders' do
|
65
|
+
it 'calls proper endpoint' do
|
66
|
+
expect(QuestradeApi::REST::Order).to receive(:fetch).and_return([])
|
67
|
+
expect(subject.orders('1')).to eq([])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'questrade_api/modules/market_call'
|
4
|
+
|
5
|
+
describe QuestradeApi::MarketCall do
|
6
|
+
class DummyClass
|
7
|
+
attr_accessor :authorization
|
8
|
+
|
9
|
+
def initialize(authorization)
|
10
|
+
@authorization = authorization
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:authorization) do
|
15
|
+
OpenStruct.new(access_token: '123', url: 'test')
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { DummyClass.new(authorization).extend(QuestradeApi::MarketCall) }
|
19
|
+
|
20
|
+
context '.markets' do
|
21
|
+
it 'calls proper endpoint' do
|
22
|
+
expect(QuestradeApi::REST::Market).to receive(:fetch).and_return([])
|
23
|
+
expect(subject.markets).to eq([])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '.symbols' do
|
28
|
+
it 'calls proper endpoint' do
|
29
|
+
expect(QuestradeApi::REST::Symbol).to receive(:fetch).and_return([])
|
30
|
+
expect(subject.symbols('')).to eq([])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '.search_symbols' do
|
35
|
+
it 'calls proper endpoint' do
|
36
|
+
expect(QuestradeApi::REST::Symbol).to receive(:search).and_return([])
|
37
|
+
expect(subject.search_symbols('')).to eq([])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '.quotes' do
|
42
|
+
it 'calls proper endpoint' do
|
43
|
+
expect(QuestradeApi::REST::Quote).to receive(:fetch).and_return([])
|
44
|
+
expect(subject.quotes([123])).to eq([])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context '.quote' do
|
49
|
+
it 'calls proper endpoint' do
|
50
|
+
expect_any_instance_of(QuestradeApi::REST::Quote).to receive(:fetch).and_return([])
|
51
|
+
expect(subject.quote(1)).to be_a(QuestradeApi::REST::Quote)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '.candles' do
|
56
|
+
it 'calls proper endpoint' do
|
57
|
+
expect(QuestradeApi::REST::Candle).to receive(:fetch).and_return([])
|
58
|
+
expect(subject.candles('', '12')).to eq([])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context '.symbol_options' do
|
63
|
+
it 'calls proper endpoint' do
|
64
|
+
expect(QuestradeApi::REST::Market).to receive(:fetch).and_return([])
|
65
|
+
expect(subject.markets).to eq([])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -15,7 +15,7 @@ describe QuestradeApi::REST::Account do
|
|
15
15
|
|
16
16
|
it 'returns a list of activities' do
|
17
17
|
expect(QuestradeApi::REST::Activity)
|
18
|
-
.to(receive(:
|
18
|
+
.to(receive(:fetch).with(authorization, id, {}))
|
19
19
|
.once
|
20
20
|
|
21
21
|
subject.activities({})
|
@@ -23,7 +23,7 @@ describe QuestradeApi::REST::Account do
|
|
23
23
|
|
24
24
|
it 'returns a list of executions' do
|
25
25
|
expect(QuestradeApi::REST::Execution)
|
26
|
-
.to(receive(:
|
26
|
+
.to(receive(:fetch).with(authorization, id, {}))
|
27
27
|
.once
|
28
28
|
|
29
29
|
subject.executions({})
|
@@ -31,7 +31,7 @@ describe QuestradeApi::REST::Account do
|
|
31
31
|
|
32
32
|
it 'returns a list of positions' do
|
33
33
|
expect(QuestradeApi::REST::Position)
|
34
|
-
.to(receive(:
|
34
|
+
.to(receive(:fetch).with(authorization, id))
|
35
35
|
.once
|
36
36
|
|
37
37
|
subject.positions
|
@@ -39,21 +39,21 @@ describe QuestradeApi::REST::Account do
|
|
39
39
|
|
40
40
|
it 'returns a list of balances' do
|
41
41
|
expect(QuestradeApi::REST::Balance)
|
42
|
-
.to(receive(:
|
42
|
+
.to(receive(:fetch).with(authorization, id))
|
43
43
|
.once
|
44
44
|
|
45
45
|
subject.balances
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context '.
|
49
|
+
context '.fetch' do
|
50
50
|
it "returns an object that contains a list of all user's accounts" do
|
51
51
|
full_url = url + QuestradeApi::REST::Account.endpoint
|
52
52
|
stub_request(:get, full_url).to_return(status: 200,
|
53
53
|
body: json_string('accounts.json'),
|
54
54
|
headers: {})
|
55
55
|
|
56
|
-
response = QuestradeApi::REST::Account.
|
56
|
+
response = QuestradeApi::REST::Account.fetch(authorization)
|
57
57
|
|
58
58
|
expect(response.accounts.size).to be(2)
|
59
59
|
|
@@ -10,7 +10,7 @@ describe QuestradeApi::REST::Activity do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all user's activities for the specific period" do
|
15
15
|
start_time = '2011-02-16T00:00:00.000000-05:00'
|
16
16
|
end_time = '2011-02-16T00:00:00.000000-05:00'
|
@@ -19,7 +19,7 @@ describe QuestradeApi::REST::Activity do
|
|
19
19
|
url + QuestradeApi::REST::Activity.endpoint(account_id) + "?#{params}"
|
20
20
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('activities.json'))
|
21
21
|
|
22
|
-
response = QuestradeApi::REST::Activity.
|
22
|
+
response = QuestradeApi::REST::Activity.fetch(authorization, account_id,
|
23
23
|
{ startTime: start_time,
|
24
24
|
endTime: end_time })
|
25
25
|
|
@@ -10,13 +10,13 @@ describe QuestradeApi::REST::Balance do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all user's balances" do
|
15
15
|
full_url =
|
16
16
|
url + QuestradeApi::REST::Balance.endpoint(account_id)
|
17
17
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('balances.json'))
|
18
18
|
|
19
|
-
response = QuestradeApi::REST::Balance.
|
19
|
+
response = QuestradeApi::REST::Balance.fetch(authorization, account_id)
|
20
20
|
|
21
21
|
expect(response.per_currency_balances.size).to be(2)
|
22
22
|
expect(response.combined_balances.size).to be(1)
|
@@ -8,7 +8,7 @@ describe QuestradeApi::REST::Candle do
|
|
8
8
|
let(:url) { 'http://test.com'}
|
9
9
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
10
10
|
|
11
|
-
context '.
|
11
|
+
context '.fetch' do
|
12
12
|
it 'fetches candle for an specific symbol' do
|
13
13
|
start_time = '2014-10-01T00:00:00-05:00'
|
14
14
|
end_time = '2014-10-01T00:00:00-05:00'
|
@@ -22,7 +22,7 @@ describe QuestradeApi::REST::Candle do
|
|
22
22
|
interval: interval
|
23
23
|
}
|
24
24
|
|
25
|
-
response = QuestradeApi::REST::Candle.
|
25
|
+
response = QuestradeApi::REST::Candle.fetch(authorization, 1010, params)
|
26
26
|
|
27
27
|
expect(response.candles.size).to be(1)
|
28
28
|
|
@@ -10,7 +10,7 @@ describe QuestradeApi::REST::Execution do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all user's executions for the specific period" do
|
15
15
|
start_time = '2014-03-31T13:38:29-04:00'
|
16
16
|
end_time = '2014-03-31T13:38:29-04:00'
|
@@ -19,7 +19,7 @@ describe QuestradeApi::REST::Execution do
|
|
19
19
|
url + QuestradeApi::REST::Execution.endpoint(account_id) + "?#{params}"
|
20
20
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('executions.json'))
|
21
21
|
|
22
|
-
response = QuestradeApi::REST::Execution.
|
22
|
+
response = QuestradeApi::REST::Execution.fetch(authorization, account_id,
|
23
23
|
startTime: start_time,
|
24
24
|
endTime: end_time)
|
25
25
|
|
@@ -10,13 +10,13 @@ describe QuestradeApi::REST::Market do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all supported" do
|
15
15
|
full_url = url + QuestradeApi::REST::Market.endpoint
|
16
16
|
|
17
17
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('markets.json'))
|
18
18
|
|
19
|
-
response = QuestradeApi::REST::Market.
|
19
|
+
response = QuestradeApi::REST::Market.fetch(authorization)
|
20
20
|
|
21
21
|
expect(response.markets.size).to be(1)
|
22
22
|
|
@@ -8,12 +8,12 @@ describe QuestradeApi::REST::Option do
|
|
8
8
|
let(:url) { 'http://test.com'}
|
9
9
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
10
10
|
|
11
|
-
context '.
|
11
|
+
context '.fetch' do
|
12
12
|
it 'fetches option chain for an specific symbol' do
|
13
13
|
stub_request(:get, 'http://test.com/v1/symbol/9291/options')
|
14
14
|
.to_return(status: 200, body: json_string('options.json'))
|
15
15
|
|
16
|
-
response = QuestradeApi::REST::Option.
|
16
|
+
response = QuestradeApi::REST::Option.fetch(authorization, 9291)
|
17
17
|
|
18
18
|
expect(response.options.size).to be(1)
|
19
19
|
|
@@ -10,7 +10,7 @@ describe QuestradeApi::REST::Order do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all user's orders" do
|
15
15
|
time = '2014-03-31T13:38:29-04:00'
|
16
16
|
params = "startTime=#{time}&endTime=#{time}&stateFilter=All"
|
@@ -19,7 +19,7 @@ describe QuestradeApi::REST::Order do
|
|
19
19
|
|
20
20
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('orders.json'))
|
21
21
|
|
22
|
-
response = QuestradeApi::REST::Order.
|
22
|
+
response = QuestradeApi::REST::Order.fetch(authorization, account_id,
|
23
23
|
startTime: time, endTime: time, stateFilter: 'All')
|
24
24
|
|
25
25
|
expect(response.orders.size).to be(1)
|
@@ -10,13 +10,13 @@ describe QuestradeApi::REST::Position do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '.
|
13
|
+
context '.fetch' do
|
14
14
|
it "returns an object that contains a list of all user's positions" do
|
15
15
|
full_url = url + QuestradeApi::REST::Position.endpoint(account_id)
|
16
16
|
|
17
17
|
stub_request(:get, full_url).to_return(status: 200, body: json_string('positions.json'))
|
18
18
|
|
19
|
-
response = QuestradeApi::REST::Position.
|
19
|
+
response = QuestradeApi::REST::Position.fetch(authorization, account_id)
|
20
20
|
|
21
21
|
expect(response.positions.size).to be(1)
|
22
22
|
|
@@ -27,7 +27,7 @@ describe QuestradeApi::REST::Quote do
|
|
27
27
|
|
28
28
|
expect(subject.data).to be_nil
|
29
29
|
|
30
|
-
subject.
|
30
|
+
subject.fetch
|
31
31
|
|
32
32
|
expect(subject.data.to_h).to eq(
|
33
33
|
symbol: "THI.TO",
|
@@ -52,12 +52,12 @@ describe QuestradeApi::REST::Quote do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context '.
|
55
|
+
context '.fetch' do
|
56
56
|
it 'fetches quote for an specific symbol' do
|
57
57
|
stub_request(:get, 'http://test.com/v1/markets/quotes?ids=12,11')
|
58
58
|
.to_return(status: 200, body: json_string('quotes.json'))
|
59
59
|
|
60
|
-
response = QuestradeApi::REST::Quote.
|
60
|
+
response = QuestradeApi::REST::Quote.fetch(authorization, [12, 11])
|
61
61
|
|
62
62
|
expect(response.quotes.size).to be(1)
|
63
63
|
|
@@ -10,8 +10,73 @@ describe QuestradeApi::REST::Symbol do
|
|
10
10
|
let(:url) { 'http://test.com'}
|
11
11
|
let(:authorization) { OpenStruct.new(access_token: access_token, url: url) }
|
12
12
|
|
13
|
-
context '#
|
14
|
-
|
13
|
+
context '#fetch' do
|
14
|
+
subject { QuestradeApi::REST::Symbol.new(authorization, id: 10) }
|
15
|
+
|
16
|
+
it 'fetches symbol data' do
|
17
|
+
stub_request(:get, "http://test.com/v1/symbols/10")
|
18
|
+
.to_return(status: 200, body: json_string('symbol_01.json'))
|
19
|
+
|
20
|
+
|
21
|
+
expect(subject.data).to be_nil
|
22
|
+
subject.fetch
|
23
|
+
expect(subject.data.to_h).to eq(
|
24
|
+
symbol: 'AAPL',
|
25
|
+
symbol_id: 8049,
|
26
|
+
prev_day_close_price: 102.5,
|
27
|
+
high_price52: 102.9,
|
28
|
+
low_price52: 63.89,
|
29
|
+
average_vol3_months: 43769680,
|
30
|
+
average_vol20_days: 12860370,
|
31
|
+
outstanding_shares: 5987867000,
|
32
|
+
eps: 6.2,
|
33
|
+
pe: 16.54,
|
34
|
+
dividend: 0.47,
|
35
|
+
yield: 1.84,
|
36
|
+
ex_date: "2014-08-07T00:00:00.000000-04:00",
|
37
|
+
market_cap: 613756367500,
|
38
|
+
trade_unit: 1,
|
39
|
+
option_type: nil,
|
40
|
+
option_duration_type: nil,
|
41
|
+
option_root: "",
|
42
|
+
option_contract_deliverables: {
|
43
|
+
'underlyings' => [],
|
44
|
+
'cashInLieu' => 0
|
45
|
+
},
|
46
|
+
option_exercise_type: nil,
|
47
|
+
listing_exchange: "NASDAQ",
|
48
|
+
description: "APPLE INC",
|
49
|
+
security_type: "Stock",
|
50
|
+
option_expiry_date: nil,
|
51
|
+
dividend_date: "2014-08-14T00:00:00.000000-04:00",
|
52
|
+
option_strike_price: nil,
|
53
|
+
is_tradable: true,
|
54
|
+
is_quotable: true,
|
55
|
+
has_options: true,
|
56
|
+
min_ticks: [
|
57
|
+
{
|
58
|
+
'pivot' => 0,
|
59
|
+
'minTick' => 0.0001
|
60
|
+
},
|
61
|
+
{
|
62
|
+
'pivot' => 1,
|
63
|
+
'minTick' => 0.01
|
64
|
+
}
|
65
|
+
],
|
66
|
+
industry_sector: "BasicMaterials",
|
67
|
+
industry_group: "Steel",
|
68
|
+
industry_sub_group: "Steel")
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context '#endpoint' do
|
74
|
+
subject { QuestradeApi::REST::Symbol.new(authorization, id: 10) }
|
75
|
+
|
76
|
+
it 'calls endpoint' do
|
77
|
+
url = "/v1/symbols/10"
|
78
|
+
expect(subject.endpoint).to eq(url)
|
79
|
+
end
|
15
80
|
end
|
16
81
|
|
17
82
|
context '.search' do
|
@@ -68,14 +133,14 @@ describe QuestradeApi::REST::Symbol do
|
|
68
133
|
end
|
69
134
|
end
|
70
135
|
|
71
|
-
context '.
|
136
|
+
context '.fetch' do
|
72
137
|
let(:ids) { [8049, 8050] }
|
73
138
|
let(:names) { ['AAPL', 'GOOGL'] }
|
74
139
|
|
75
140
|
it 'calls endpoint passing a list of ids' do
|
76
141
|
stub_request(:get, "http://test.com/v1/symbols/?ids=8049,8050")
|
77
142
|
.to_return(status: 200, body: '{}').times(1)
|
78
|
-
response = QuestradeApi::REST::Symbol.
|
143
|
+
response = QuestradeApi::REST::Symbol.fetch(authorization, ids: ids)
|
79
144
|
|
80
145
|
expect(response.symbols.size).to be(0)
|
81
146
|
end
|
@@ -83,7 +148,7 @@ describe QuestradeApi::REST::Symbol do
|
|
83
148
|
it 'calls endpoint passing a list of names' do
|
84
149
|
stub_request(:get, "http://test.com/v1/symbols/?names=AAPL,GOOGL")
|
85
150
|
.to_return(status: 200, body: '{}')
|
86
|
-
response = QuestradeApi::REST::Symbol.
|
151
|
+
response = QuestradeApi::REST::Symbol.fetch(authorization, names: names)
|
87
152
|
|
88
153
|
expect(response.symbols.size).to be(0)
|
89
154
|
end
|
@@ -92,7 +157,7 @@ describe QuestradeApi::REST::Symbol do
|
|
92
157
|
stub_request(:get, "http://test.com/v1/symbols/")
|
93
158
|
.to_return(status: 200, body: json_string('symbols.json'))
|
94
159
|
|
95
|
-
response = QuestradeApi::REST::Symbol.
|
160
|
+
response = QuestradeApi::REST::Symbol.fetch(authorization)
|
96
161
|
|
97
162
|
expect(response.symbols.size).to be(1)
|
98
163
|
|
@@ -11,7 +11,7 @@ describe QuestradeApi::REST::Time do
|
|
11
11
|
|
12
12
|
subject { QuestradeApi::REST::Time.new(authorization) }
|
13
13
|
|
14
|
-
context '#
|
14
|
+
context '#fetch' do
|
15
15
|
let(:url) { 'http://test.com/v1/time' }
|
16
16
|
|
17
17
|
it 'calls the proper endpoint with proper data' do
|
@@ -19,10 +19,21 @@ describe QuestradeApi::REST::Time do
|
|
19
19
|
|
20
20
|
stub_request(:get, url).to_return(status: 200,
|
21
21
|
body: json_string('time.json'))
|
22
|
-
subject.
|
22
|
+
subject.fetch
|
23
|
+
|
24
|
+
expected_return = DateTime.parse('2017-01-24T12:14:42.730000-04:00')
|
23
25
|
|
24
26
|
expect(subject.data).to_not be_nil
|
25
|
-
expect(subject.data.time).to eq(
|
27
|
+
expect(subject.data.time).to eq(expected_return)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns time' do
|
31
|
+
stub_request(:get, url).to_return(status: 200,
|
32
|
+
body: json_string('time.json'))
|
33
|
+
result = subject.fetch
|
34
|
+
|
35
|
+
expected_return = DateTime.parse('2017-01-24T12:14:42.730000-04:00')
|
36
|
+
expect(result).to eq(expected_return)
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: questrade_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Meira
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
79
|
- ".yardopts"
|
80
|
+
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- Guardfile
|
82
83
|
- LICENSE
|
@@ -85,6 +86,8 @@ files:
|
|
85
86
|
- lib/questrade_api.rb
|
86
87
|
- lib/questrade_api/authorization.rb
|
87
88
|
- lib/questrade_api/client.rb
|
89
|
+
- lib/questrade_api/modules/account_call.rb
|
90
|
+
- lib/questrade_api/modules/market_call.rb
|
88
91
|
- lib/questrade_api/modules/util.rb
|
89
92
|
- lib/questrade_api/rest/account.rb
|
90
93
|
- lib/questrade_api/rest/activity.rb
|
@@ -112,11 +115,14 @@ files:
|
|
112
115
|
- spec/fixtures/json/positions.json
|
113
116
|
- spec/fixtures/json/quote_01.json
|
114
117
|
- spec/fixtures/json/quotes.json
|
118
|
+
- spec/fixtures/json/symbol_01.json
|
115
119
|
- spec/fixtures/json/symbols.json
|
116
120
|
- spec/fixtures/json/symbols_search.json
|
117
121
|
- spec/fixtures/json/time.json
|
118
122
|
- spec/questrade_api/authorization_spec.rb
|
119
123
|
- spec/questrade_api/client_spec.rb
|
124
|
+
- spec/questrade_api/modules/account_call_spec.rb
|
125
|
+
- spec/questrade_api/modules/market_call_spec.rb
|
120
126
|
- spec/questrade_api/rest/account_spec.rb
|
121
127
|
- spec/questrade_api/rest/activity_spec.rb
|
122
128
|
- spec/questrade_api/rest/balance_spec.rb
|
@@ -167,11 +173,14 @@ test_files:
|
|
167
173
|
- spec/fixtures/json/positions.json
|
168
174
|
- spec/fixtures/json/quote_01.json
|
169
175
|
- spec/fixtures/json/quotes.json
|
176
|
+
- spec/fixtures/json/symbol_01.json
|
170
177
|
- spec/fixtures/json/symbols.json
|
171
178
|
- spec/fixtures/json/symbols_search.json
|
172
179
|
- spec/fixtures/json/time.json
|
173
180
|
- spec/questrade_api/authorization_spec.rb
|
174
181
|
- spec/questrade_api/client_spec.rb
|
182
|
+
- spec/questrade_api/modules/account_call_spec.rb
|
183
|
+
- spec/questrade_api/modules/market_call_spec.rb
|
175
184
|
- spec/questrade_api/rest/account_spec.rb
|
176
185
|
- spec/questrade_api/rest/activity_spec.rb
|
177
186
|
- spec/questrade_api/rest/balance_spec.rb
|