alpaca-trade-api 0.2.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +5 -5
- data/README.md +39 -7
- data/alpaca-trade-api.gemspec +1 -1
- data/lib/alpaca/trade/api.rb +4 -0
- data/lib/alpaca/trade/api/bar.rb +4 -4
- data/lib/alpaca/trade/api/client.rb +95 -3
- data/lib/alpaca/trade/api/clock.rb +2 -2
- data/lib/alpaca/trade/api/errors.rb +2 -0
- data/lib/alpaca/trade/api/last_trade.rb +15 -0
- data/lib/alpaca/trade/api/non_trade_activity.rb +21 -0
- data/lib/alpaca/trade/api/order.rb +25 -18
- data/lib/alpaca/trade/api/trade_activity.rb +29 -0
- data/lib/alpaca/trade/api/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22068a0419de69587d795ef7ea3cfe4e0bcfb60f533d3af8806dd9e098124eea
|
4
|
+
data.tar.gz: 1a33fa8bbc2a45634a65948161c1999b1526d9a30ad996eea0c5d80152085826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16e4be2df3ba8f55cea8cf2c0630dc9cafba60ea8a52b05cbb089679fdf2a6ee4d2d03f39e4513afb0b1356d6a84033d061a2c63ba1d214f2bc60904af0173c0
|
7
|
+
data.tar.gz: a9cbe4f030829c9ab095c22614c748e4df9b2d56b8b349310f41e35a646857cbdb93b4ff680f5fe1910d0e9b0262262f6e930a59b806f090bf73bf38bc6d2979
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.4
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.6.0] - 2020-05-26
|
8
|
+
### Added
|
9
|
+
- Implemented Client#account_activities. Thanks @travishooper.
|
10
|
+
|
11
|
+
## [0.5.0] - 2020-05-25
|
12
|
+
### Added
|
13
|
+
- Implemented Client#last_trade. Thanks @nathanworden.
|
14
|
+
|
15
|
+
## [0.4.1] - 2020-04-25
|
16
|
+
### Fixed
|
17
|
+
- Added explicit `BigDecimal` require.
|
18
|
+
|
19
|
+
## [0.4.0] - 2020-02-16
|
20
|
+
### Added
|
21
|
+
- Supporting [Bracket Orders](https://docs.alpaca.markets/trading-on-alpaca/orders/#bracket-orders)
|
22
|
+
- Validating time frame in Client#bars
|
23
|
+
|
24
|
+
## [0.3.0] - 2019-09-19
|
25
|
+
### Added
|
26
|
+
- Implemented new endpoints:
|
27
|
+
* Client#cancel_orders
|
28
|
+
* Client#close_position
|
29
|
+
* Client#close_positions
|
30
|
+
* Client#replace_order
|
31
|
+
- Added limit as a parameter to Client#bars
|
32
|
+
- Renamed Clock#open to Clock#is_open and fixed assignment.
|
33
|
+
|
7
34
|
## [0.2.0] - 2019-07-10
|
8
35
|
### Added
|
9
36
|
- Implemented Client#calendar.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
alpaca-trade-api (0.
|
4
|
+
alpaca-trade-api (0.6.0)
|
5
5
|
faraday (~> 0.15)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,13 +14,13 @@ GEM
|
|
14
14
|
safe_yaml (~> 1.0.0)
|
15
15
|
diff-lcs (1.3)
|
16
16
|
docile (1.3.2)
|
17
|
-
faraday (0.
|
17
|
+
faraday (0.17.3)
|
18
18
|
multipart-post (>= 1.2, < 3)
|
19
19
|
hashdiff (0.4.0)
|
20
20
|
json (2.2.0)
|
21
21
|
multipart-post (2.1.1)
|
22
22
|
public_suffix (3.1.1)
|
23
|
-
rake (
|
23
|
+
rake (13.0.1)
|
24
24
|
rb-readline (0.5.5)
|
25
25
|
rspec (3.8.0)
|
26
26
|
rspec-core (~> 3.8.0)
|
@@ -54,7 +54,7 @@ DEPENDENCIES
|
|
54
54
|
alpaca-trade-api!
|
55
55
|
bundler (~> 2.0)
|
56
56
|
byebug
|
57
|
-
rake (~>
|
57
|
+
rake (~> 13.0)
|
58
58
|
rb-readline
|
59
59
|
rspec (~> 3.0)
|
60
60
|
simplecov (~> 0.16)
|
@@ -62,4 +62,4 @@ DEPENDENCIES
|
|
62
62
|
webmock (~> 3.0)
|
63
63
|
|
64
64
|
BUNDLED WITH
|
65
|
-
2.
|
65
|
+
2.1.4
|
data/README.md
CHANGED
@@ -26,23 +26,55 @@ By default, the library is configured to use the Paper Trading host - `https://p
|
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
Alpaca::Trade::Api.configure do |config|
|
29
|
-
config.endpoint = 'https://api.
|
29
|
+
config.endpoint = 'https://api.alpaca.markets'
|
30
30
|
config.key_id = 'A_KEY_ID'
|
31
31
|
config.key_secret = 'A_S3CRET'
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
-
### Account
|
36
35
|
|
37
|
-
|
36
|
+
### Example
|
38
37
|
|
39
|
-
|
38
|
+
Here's an example on how to use the library to read details of an account's orders in paper trading.
|
40
39
|
|
41
|
-
|
40
|
+
```ruby
|
41
|
+
require 'alpaca/trade/api'
|
42
42
|
|
43
|
-
|
43
|
+
Alpaca::Trade::Api.configure do |config|
|
44
|
+
config.endpoint = 'https://paper-api.alpaca.markets'
|
45
|
+
config.key_id = 'xxxxxxxx'
|
46
|
+
config.key_secret = 'xxxxx'
|
47
|
+
end
|
48
|
+
|
49
|
+
client = Alpaca::Trade::Api::Client.new
|
50
|
+
puts client.orders.last.inspect
|
51
|
+
```
|
44
52
|
|
45
|
-
|
53
|
+
### Supported endpoints
|
54
|
+
|
55
|
+
Here's a table with all currently supported endpoints in this library:
|
56
|
+
|
57
|
+
| Object | Action | Method |
|
58
|
+
|-----------------------------------------------------------------------------------------------|----------------------------------------|-------------------------------------------|
|
59
|
+
| [Account](https://docs.alpaca.markets/api-documentation/api-v2/account/) | [GET] Get the account | Client#account |
|
60
|
+
| [Account Activities](https://docs.alpaca.markets/api-documentation/api-v2/account-activities) | [GET] Get a list of account activities | Client#account_activities(activity_type:) |
|
61
|
+
| [Orders](https://docs.alpaca.markets/api-documentation/api-v2/orders/) | [GET] Get a list of orders | Client#orders |
|
62
|
+
| | [POST] Request a new order | Client#new_order |
|
63
|
+
| | [GET] Get an order | Client#order(id:) |
|
64
|
+
| | [GET] Get an order by client order id | Client#order(id:) |
|
65
|
+
| | [PATCH] Replace an order | Client#replace_order |
|
66
|
+
| | [DELETE] Cancel all orders | Client#cancel_orders |
|
67
|
+
| | [DELETE] Cancel an order | Client#cancel_order(id:) |
|
68
|
+
| [Positions](https://docs.alpaca.markets/api-documentation/api-v2/positions/) | [GET] Get open positions | Client#positions |
|
69
|
+
| | [GET] Get an open position | Client#position(symbol:) |
|
70
|
+
| | [DELETE] Close all positions | Client#close_positions |
|
71
|
+
| | [DELETE] Close a position | Client#close_position(symbol:) |
|
72
|
+
| [Assets](https://docs.alpaca.markets/api-documentation/api-v2/assets/) | [GET] Get assets | Client#assets |
|
73
|
+
| | [GET] Get assets/:id | Client#asset(symbol:) |
|
74
|
+
| | [GET] Get an asset | Client#asset(symbol:) |
|
75
|
+
| [Calendar](https://docs.alpaca.markets/api-documentation/api-v2/calendar/) | [GET] Get the calendar | Client#calendar(start_date:, end_date:) |
|
76
|
+
| [Clock](https://docs.alpaca.markets/api-documentation/api-v2/clock/) | [GET] Get the clock | Client#clock |
|
77
|
+
| [Bars](https://docs.alpaca.markets/api-documentation/api-v2/market-data/bars/) | [GET] Get a list of bars | Client#bars(timeframe, symbols, limit:) |
|
46
78
|
|
47
79
|
## Development
|
48
80
|
|
data/alpaca-trade-api.gemspec
CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency "bundler", "~> 2.0"
|
40
40
|
spec.add_development_dependency "byebug"
|
41
41
|
spec.add_development_dependency 'rb-readline'
|
42
|
-
spec.add_development_dependency "rake", "~>
|
42
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
43
43
|
spec.add_development_dependency "rspec", "~> 3.0"
|
44
44
|
spec.add_development_dependency "simplecov", "~> 0.16"
|
45
45
|
spec.add_development_dependency "vcr", "~> 5.0"
|
data/lib/alpaca/trade/api.rb
CHANGED
@@ -8,12 +8,16 @@ require 'alpaca/trade/api/asset'
|
|
8
8
|
require 'alpaca/trade/api/bar'
|
9
9
|
require 'alpaca/trade/api/calendar'
|
10
10
|
require 'alpaca/trade/api/clock'
|
11
|
+
require 'alpaca/trade/api/last_trade'
|
12
|
+
require 'alpaca/trade/api/non_trade_activity'
|
11
13
|
require 'alpaca/trade/api/order'
|
12
14
|
require 'alpaca/trade/api/position'
|
15
|
+
require 'alpaca/trade/api/trade_activity'
|
13
16
|
|
14
17
|
require 'alpaca/trade/api/client'
|
15
18
|
require 'alpaca/trade/api/errors'
|
16
19
|
|
20
|
+
require 'bigdecimal/util'
|
17
21
|
require 'json'
|
18
22
|
|
19
23
|
module Alpaca
|
data/lib/alpaca/trade/api/bar.rb
CHANGED
@@ -8,10 +8,10 @@ module Alpaca
|
|
8
8
|
|
9
9
|
def initialize(json)
|
10
10
|
@time = Time.at(json['t'])
|
11
|
-
@open = BigDecimal(json['o']
|
12
|
-
@high = BigDecimal(json['h']
|
13
|
-
@low = BigDecimal(json['l']
|
14
|
-
@close = BigDecimal(json['c']
|
11
|
+
@open = BigDecimal(json['o'].to_s)
|
12
|
+
@high = BigDecimal(json['h'].to_s)
|
13
|
+
@low = BigDecimal(json['l'].to_s)
|
14
|
+
@close = BigDecimal(json['c'].to_s)
|
15
15
|
@volume = json['v']
|
16
16
|
end
|
17
17
|
end
|
@@ -9,6 +9,8 @@ module Alpaca
|
|
9
9
|
class Client
|
10
10
|
attr_reader :data_endpoint, :endpoint, :key_id, :key_secret
|
11
11
|
|
12
|
+
TIMEFRAMES = ['minute', '1Min', '5Min', '15Min', 'day', '1D']
|
13
|
+
|
12
14
|
def initialize(endpoint: Alpaca::Trade::Api.configuration.endpoint,
|
13
15
|
key_id: Alpaca::Trade::Api.configuration.key_id,
|
14
16
|
key_secret: Alpaca::Trade::Api.configuration.key_secret)
|
@@ -23,6 +25,14 @@ module Alpaca
|
|
23
25
|
Account.new(JSON.parse(response.body))
|
24
26
|
end
|
25
27
|
|
28
|
+
def account_activities(activity_type:)
|
29
|
+
response = get_request(endpoint, "/v2/account/activities/#{activity_type}")
|
30
|
+
raise InvalidActivityType, JSON.parse(response.body)['message'] if response.status == 422
|
31
|
+
json = JSON.parse(response.body)
|
32
|
+
activity_class = (TradeActivity::ATTRIBUTES - json.first.to_h.keys).none? ? TradeActivity : NonTradeActivity
|
33
|
+
json.map { |item| activity_class.new(item) }
|
34
|
+
end
|
35
|
+
|
26
36
|
def asset(symbol:)
|
27
37
|
response = get_request(endpoint, "v2/assets/#{symbol}")
|
28
38
|
Asset.new(JSON.parse(response.body))
|
@@ -34,8 +44,9 @@ module Alpaca
|
|
34
44
|
json.map { |item| Asset.new(item) }
|
35
45
|
end
|
36
46
|
|
37
|
-
def bars(timeframe, symbols)
|
38
|
-
|
47
|
+
def bars(timeframe, symbols, limit: 100)
|
48
|
+
validate_timeframe(timeframe)
|
49
|
+
response = get_request(data_endpoint, "v1/bars/#{timeframe}", symbols: symbols.join(','), limit: limit)
|
39
50
|
json = JSON.parse(response.body)
|
40
51
|
json.keys.each_with_object({}) do |symbol, hash|
|
41
52
|
hash[symbol] = json[symbol].map { |bar| Bar.new(bar) }
|
@@ -43,6 +54,7 @@ module Alpaca
|
|
43
54
|
end
|
44
55
|
|
45
56
|
def calendar(start_date: Date.today, end_date: (Date.today + 30))
|
57
|
+
# FIX, use start_date.strftime('%F')
|
46
58
|
params = { "start" => start_date.iso8601, "end" => end_date.iso8601 }
|
47
59
|
response = get_request(endpoint, "v2/calendar", params)
|
48
60
|
json = JSON.parse(response.body)
|
@@ -55,13 +67,54 @@ module Alpaca
|
|
55
67
|
raise OrderNotCancelable if response.status == 422
|
56
68
|
end
|
57
69
|
|
70
|
+
def cancel_orders
|
71
|
+
response = delete_request(endpoint, 'v2/orders')
|
72
|
+
|
73
|
+
json = JSON.parse(response.body)
|
74
|
+
json.map do |item|
|
75
|
+
{
|
76
|
+
'id' => item['id'],
|
77
|
+
'status' => item['status'],
|
78
|
+
'body' => Order.new(item['body']),
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
58
83
|
def clock
|
59
84
|
response = get_request(endpoint, 'v2/clock')
|
60
85
|
Clock.new(JSON.parse(response.body))
|
61
86
|
end
|
62
87
|
|
88
|
+
def close_position(symbol:)
|
89
|
+
response = delete_request(endpoint, "v2/positions/#{symbol}")
|
90
|
+
raise NoPositionForSymbol, JSON.parse(response.body)['message'] if response.status == 404
|
91
|
+
|
92
|
+
Position.new(JSON.parse(response.body))
|
93
|
+
end
|
94
|
+
|
95
|
+
def close_positions
|
96
|
+
response = delete_request(endpoint, 'v2/positions')
|
97
|
+
|
98
|
+
json = JSON.parse(response.body)
|
99
|
+
json.map do |item|
|
100
|
+
{
|
101
|
+
'symbol' => item['symbol'],
|
102
|
+
'status' => item['status'],
|
103
|
+
'body' => Position.new(item['body']),
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def last_trade(symbol:)
|
109
|
+
response = get_request(data_endpoint, "v1/last/stocks/#{symbol}")
|
110
|
+
raise InvalidRequest, JSON.parse(response.body)['message'] if response.status == 404
|
111
|
+
|
112
|
+
LastTrade.new(JSON.parse(response.body))
|
113
|
+
end
|
114
|
+
|
63
115
|
def new_order(symbol:, qty:, side:, type:, time_in_force:, limit_price: nil,
|
64
|
-
stop_price: nil, extended_hours
|
116
|
+
stop_price: nil, extended_hours: false, client_order_id: nil, order_class: nil,
|
117
|
+
take_profit: nil, stop_loss: nil)
|
65
118
|
|
66
119
|
params = {
|
67
120
|
symbol: symbol,
|
@@ -70,7 +123,10 @@ module Alpaca
|
|
70
123
|
type: type,
|
71
124
|
time_in_force: time_in_force,
|
72
125
|
limit_price: limit_price,
|
126
|
+
order_class: order_class,
|
73
127
|
stop_price: stop_price,
|
128
|
+
take_profit: take_profit,
|
129
|
+
stop_loss: stop_loss,
|
74
130
|
extended_hours: extended_hours,
|
75
131
|
client_order_id: client_order_id
|
76
132
|
}
|
@@ -108,6 +164,24 @@ module Alpaca
|
|
108
164
|
json.map { |item| Position.new(item) }
|
109
165
|
end
|
110
166
|
|
167
|
+
def replace_order(id:, qty: nil, time_in_force: nil, limit_price: nil,
|
168
|
+
stop_price: nil, client_order_id: nil)
|
169
|
+
|
170
|
+
params = {
|
171
|
+
qty: qty,
|
172
|
+
time_in_force: time_in_force,
|
173
|
+
limit_price: limit_price,
|
174
|
+
stop_price: stop_price,
|
175
|
+
client_order_id: client_order_id
|
176
|
+
}
|
177
|
+
response = patch_request(endpoint, "v2/orders/#{id}", params.compact)
|
178
|
+
raise InsufficientFunds, JSON.parse(response.body)['message'] if response.status == 403
|
179
|
+
raise InvalidOrderId, JSON.parse(response.body)['message'] if response.status == 404
|
180
|
+
raise InvalidRequest, JSON.parse(response.body)['message'] if response.status == 422
|
181
|
+
|
182
|
+
Order.new(JSON.parse(response.body))
|
183
|
+
end
|
184
|
+
|
111
185
|
private
|
112
186
|
|
113
187
|
def delete_request(endpoint, uri)
|
@@ -133,6 +207,18 @@ module Alpaca
|
|
133
207
|
response
|
134
208
|
end
|
135
209
|
|
210
|
+
def patch_request(endpoint, uri, params = {})
|
211
|
+
conn = Faraday.new(url: endpoint)
|
212
|
+
response = conn.patch(uri) do |req|
|
213
|
+
req.body = params.to_json
|
214
|
+
req.headers['APCA-API-KEY-ID'] = key_id
|
215
|
+
req.headers['APCA-API-SECRET-KEY'] = key_secret
|
216
|
+
end
|
217
|
+
|
218
|
+
possibly_raise_exception(response)
|
219
|
+
response
|
220
|
+
end
|
221
|
+
|
136
222
|
def post_request(endpoint, uri, params = {})
|
137
223
|
conn = Faraday.new(url: endpoint)
|
138
224
|
response = conn.post(uri) do |req|
|
@@ -156,6 +242,12 @@ module Alpaca
|
|
156
242
|
raise InternalServerError, JSON.parse(response.body)['message']
|
157
243
|
end
|
158
244
|
end
|
245
|
+
|
246
|
+
def validate_timeframe(timeframe)
|
247
|
+
unless TIMEFRAMES.include?(timeframe)
|
248
|
+
raise ArgumentError, "Invalid timeframe: #{timeframe}. Valid arguments are: #{TIMEFRAMES}"
|
249
|
+
end
|
250
|
+
end
|
159
251
|
end
|
160
252
|
end
|
161
253
|
end
|
@@ -4,11 +4,11 @@ module Alpaca
|
|
4
4
|
module Trade
|
5
5
|
module Api
|
6
6
|
class Clock
|
7
|
-
attr_reader :timestamp, :
|
7
|
+
attr_reader :timestamp, :is_open, :next_open, :next_close
|
8
8
|
|
9
9
|
def initialize(json)
|
10
10
|
@timestamp = json['timestamp']
|
11
|
-
@
|
11
|
+
@is_open = json['is_open']
|
12
12
|
@next_open = json['next_open']
|
13
13
|
@next_close = json['next_close']
|
14
14
|
end
|
@@ -6,7 +6,9 @@ module Alpaca
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
class InsufficientFunds < Error; end
|
8
8
|
class InternalServerError < Error; end
|
9
|
+
class InvalidActivityType < Error; end
|
9
10
|
class InvalidOrderId < Error; end
|
11
|
+
class InvalidRequest < Error; end
|
10
12
|
class MissingParameters < Error; end
|
11
13
|
class NoPositionForSymbol < Error; end
|
12
14
|
class OrderNotCancelable < Error; end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alpaca
|
4
|
+
module Trade
|
5
|
+
module Api
|
6
|
+
class NonTradeActivity
|
7
|
+
attr_reader :id, :activity_type, :date, :net_ammount, :symbol, :qty, :per_share_amount
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@id = json['id']
|
11
|
+
@activity_type = json['activity_type']
|
12
|
+
@date = json['date']
|
13
|
+
@net_ammount = json['net_ammount']
|
14
|
+
@symbol = json['symbol']
|
15
|
+
@qty = json['qty']
|
16
|
+
@per_share_amount = json['per_share_amount']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -4,34 +4,41 @@ module Alpaca
|
|
4
4
|
module Trade
|
5
5
|
module Api
|
6
6
|
class Order
|
7
|
-
attr_reader :id, :
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
7
|
+
attr_reader :id, :asset_class, :asset_id, :canceled_at, :client_order_id,
|
8
|
+
:created_at, :expired_at, :extended_hours, :failed_at, :filled_at, :filled_avg_price,
|
9
|
+
:filled_qty, :legs, :limit_price, :order_class, :qty, :replaced_at, :replaced_by,
|
10
|
+
:replaces, :side, :status, :stop_price, :submitted_at, :symbol, :time_in_force,
|
11
|
+
:type, :updated_at
|
11
12
|
|
12
13
|
def initialize(json)
|
13
14
|
@id = json['id']
|
15
|
+
|
16
|
+
@asset_class = json['asset_class']
|
17
|
+
@asset_id = json['asset_id']
|
18
|
+
@canceled_at = json['canceled_at']
|
14
19
|
@client_order_id = json['client_order_id']
|
15
20
|
@created_at = json['created_at']
|
16
|
-
@updated_at = json['updated_at']
|
17
|
-
@submitted_at = json['submitted_at']
|
18
|
-
@filled_at = json['filled_at']
|
19
21
|
@expired_at = json['expired_at']
|
20
|
-
@
|
22
|
+
@extended_hours = json['extended_hours']
|
21
23
|
@failed_at = json['failed_at']
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@asset_class = json['asset_class']
|
25
|
-
@qty = json['qty']
|
24
|
+
@filled_at = json['filled_at']
|
25
|
+
@filled_avg_price = json['filled_avg_price']
|
26
26
|
@filled_qty = json['filled_qty']
|
27
|
-
@
|
28
|
-
@side = json['side']
|
29
|
-
@time_in_force = json['time_in_force']
|
27
|
+
@legs = (json['legs'] || []).map {|leg| Order.new(leg)}
|
30
28
|
@limit_price = json['limit_price']
|
31
|
-
@
|
32
|
-
@
|
29
|
+
@order_class = json['order_class']
|
30
|
+
@qty = json['qty']
|
31
|
+
@replaced_at = json['replaced_at']
|
32
|
+
@replaced_by = json['replaced_by']
|
33
|
+
@replaces = json['replaces']
|
34
|
+
@side = json['side']
|
33
35
|
@status = json['status']
|
34
|
-
@
|
36
|
+
@stop_price = json['stop_price']
|
37
|
+
@submitted_at = json['submitted_at']
|
38
|
+
@symbol = json['symbol']
|
39
|
+
@time_in_force = json['time_in_force']
|
40
|
+
@type = json['type']
|
41
|
+
@updated_at = json['updated_at']
|
35
42
|
end
|
36
43
|
end
|
37
44
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alpaca
|
4
|
+
module Trade
|
5
|
+
module Api
|
6
|
+
class TradeActivity
|
7
|
+
ATTRIBUTES = %w(id activity_type transaction_time type price qty side
|
8
|
+
symbol leaves_qty order_id cum_qty)
|
9
|
+
|
10
|
+
attr_reader :id, :activity_type, :transaction_time, :type, :price, :qty,
|
11
|
+
:side, :symbol, :leaves_qty, :order_id, :cum_qty
|
12
|
+
|
13
|
+
def initialize(json)
|
14
|
+
@id = json['id']
|
15
|
+
@activity_type = json['activity_type']
|
16
|
+
@transaction_time = json['transaction_time']
|
17
|
+
@type = json['type']
|
18
|
+
@price = json['price']
|
19
|
+
@qty = json['qty']
|
20
|
+
@side = json['side']
|
21
|
+
@symbol = json['symbol']
|
22
|
+
@leaves_qty = json['leaves_qty']
|
23
|
+
@order_id = json['order_id']
|
24
|
+
@cum_qty = json['cum_qty']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alpaca-trade-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cloves Carneiro Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,8 +165,11 @@ files:
|
|
165
165
|
- lib/alpaca/trade/api/clock.rb
|
166
166
|
- lib/alpaca/trade/api/configuration.rb
|
167
167
|
- lib/alpaca/trade/api/errors.rb
|
168
|
+
- lib/alpaca/trade/api/last_trade.rb
|
169
|
+
- lib/alpaca/trade/api/non_trade_activity.rb
|
168
170
|
- lib/alpaca/trade/api/order.rb
|
169
171
|
- lib/alpaca/trade/api/position.rb
|
172
|
+
- lib/alpaca/trade/api/trade_activity.rb
|
170
173
|
- lib/alpaca/trade/api/version.rb
|
171
174
|
homepage: https://github.com/ccjr/alpaca-trade-api
|
172
175
|
licenses:
|