alpaca-trade-api 0.4.0 → 0.8.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 +16 -0
- data/Gemfile.lock +38 -34
- data/README.md +21 -20
- data/alpaca-trade-api.gemspec +2 -2
- data/lib/alpaca/trade/api.rb +4 -0
- data/lib/alpaca/trade/api/asset.rb +2 -1
- data/lib/alpaca/trade/api/client.rb +20 -4
- data/lib/alpaca/trade/api/errors.rb +1 -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/trade_activity.rb +29 -0
- data/lib/alpaca/trade/api/version.rb +1 -1
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4655ddb2a2cedffa2c5eb1f5eb76fccb77077ae877f2b35a1becf22f50524946
|
4
|
+
data.tar.gz: 357663cde64a002a63fa9810984320184774edd5581fca1ae93dd3daa489e1a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa58e42529f6901b14a010d9e406477744d2d15f64bc549983b082e4bd6ea9b771cd8ba2cae4df32efcf1dfd2aac21ebb7c6f9a8a61464f7991c59ba11ae2020
|
7
|
+
data.tar.gz: e79db3dbd7a4e0bd788e2930bbba1f0dc9cbe1f7949532f6495b5bd04f1b48fdd5e494c735c8c9fc83a0277638fd73556073cb8ba7c60551e4f043d9967389ef
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ 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.7.0] - 2021-02-27
|
8
|
+
### Added
|
9
|
+
- Support for `faraday` 1.x.
|
10
|
+
|
11
|
+
## [0.6.0] - 2020-05-26
|
12
|
+
### Added
|
13
|
+
- Implemented Client#account_activities. Thanks @travishooper.
|
14
|
+
|
15
|
+
## [0.5.0] - 2020-05-25
|
16
|
+
### Added
|
17
|
+
- Implemented Client#last_trade. Thanks @nathanworden.
|
18
|
+
|
19
|
+
## [0.4.1] - 2020-04-25
|
20
|
+
### Fixed
|
21
|
+
- Added explicit `BigDecimal` require.
|
22
|
+
|
7
23
|
## [0.4.0] - 2020-02-16
|
8
24
|
### Added
|
9
25
|
- Supporting [Bracket Orders](https://docs.alpaca.markets/trading-on-alpaca/orders/#bracket-orders)
|
data/Gemfile.lock
CHANGED
@@ -1,48 +1,52 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
alpaca-trade-api (0.
|
5
|
-
faraday (
|
4
|
+
alpaca-trade-api (0.7.0)
|
5
|
+
faraday (>= 0.15, < 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
byebug (11.
|
13
|
-
crack (0.4.
|
14
|
-
|
15
|
-
diff-lcs (1.
|
16
|
-
docile (1.3.
|
17
|
-
faraday (
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
byebug (11.1.3)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
docile (1.3.5)
|
17
|
+
faraday (1.3.0)
|
18
|
+
faraday-net_http (~> 1.0)
|
18
19
|
multipart-post (>= 1.2, < 3)
|
19
|
-
|
20
|
-
|
20
|
+
ruby2_keywords
|
21
|
+
faraday-net_http (1.0.1)
|
22
|
+
hashdiff (1.0.1)
|
21
23
|
multipart-post (2.1.1)
|
22
|
-
public_suffix (
|
23
|
-
rake (
|
24
|
+
public_suffix (4.0.6)
|
25
|
+
rake (13.0.3)
|
24
26
|
rb-readline (0.5.5)
|
25
|
-
|
26
|
-
|
27
|
-
rspec-
|
28
|
-
rspec-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
rexml (3.2.4)
|
28
|
+
rspec (3.10.0)
|
29
|
+
rspec-core (~> 3.10.0)
|
30
|
+
rspec-expectations (~> 3.10.0)
|
31
|
+
rspec-mocks (~> 3.10.0)
|
32
|
+
rspec-core (3.10.1)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-expectations (3.10.1)
|
32
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-mocks (3.
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-mocks (3.10.2)
|
35
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-support (3.
|
38
|
-
|
39
|
-
simplecov (0.
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-support (3.10.2)
|
41
|
+
ruby2_keywords (0.0.4)
|
42
|
+
simplecov (0.21.2)
|
40
43
|
docile (~> 1.1)
|
41
|
-
|
42
|
-
|
43
|
-
simplecov-html (0.
|
44
|
-
|
45
|
-
|
44
|
+
simplecov-html (~> 0.11)
|
45
|
+
simplecov_json_formatter (~> 0.1)
|
46
|
+
simplecov-html (0.12.3)
|
47
|
+
simplecov_json_formatter (0.1.2)
|
48
|
+
vcr (5.1.0)
|
49
|
+
webmock (3.12.0)
|
46
50
|
addressable (>= 2.3.6)
|
47
51
|
crack (>= 0.3.2)
|
48
52
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -54,7 +58,7 @@ DEPENDENCIES
|
|
54
58
|
alpaca-trade-api!
|
55
59
|
bundler (~> 2.0)
|
56
60
|
byebug
|
57
|
-
rake (~>
|
61
|
+
rake (~> 13.0)
|
58
62
|
rb-readline
|
59
63
|
rspec (~> 3.0)
|
60
64
|
simplecov (~> 0.16)
|
@@ -62,4 +66,4 @@ DEPENDENCIES
|
|
62
66
|
webmock (~> 3.0)
|
63
67
|
|
64
68
|
BUNDLED WITH
|
65
|
-
2.
|
69
|
+
2.1.4
|
data/README.md
CHANGED
@@ -54,26 +54,27 @@ puts client.orders.last.inspect
|
|
54
54
|
|
55
55
|
Here's a table with all currently supported endpoints in this library:
|
56
56
|
|
57
|
-
| Object
|
58
|
-
|
59
|
-
| [Account](https://docs.alpaca.markets/api-documentation/api-v2/account/)
|
60
|
-
| [
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
| [
|
76
|
-
| [
|
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:) |
|
77
78
|
|
78
79
|
## Development
|
79
80
|
|
data/alpaca-trade-api.gemspec
CHANGED
@@ -39,11 +39,11 @@ 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"
|
46
46
|
spec.add_development_dependency "webmock", "~> 3.0"
|
47
47
|
|
48
|
-
spec.add_dependency 'faraday', "
|
48
|
+
spec.add_dependency 'faraday', ">= 0.15", "< 2.0"
|
49
49
|
end
|
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
|
@@ -5,7 +5,7 @@ module Alpaca
|
|
5
5
|
module Api
|
6
6
|
class Asset
|
7
7
|
attr_reader :id, :asset_class, :exchange, :symbol, :status, :tradable, :marginable,
|
8
|
-
:shortable, :easy_to_borrow
|
8
|
+
:shortable, :easy_to_borrow, :fractionable
|
9
9
|
|
10
10
|
def initialize(json)
|
11
11
|
@id = json['id']
|
@@ -17,6 +17,7 @@ module Alpaca
|
|
17
17
|
@marginable = json['marginable']
|
18
18
|
@shortable = json['shortable']
|
19
19
|
@easy_to_borrow = json['easy_to_borrow']
|
20
|
+
@fractionable = json['fractionable']
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -25,6 +25,14 @@ module Alpaca
|
|
25
25
|
Account.new(JSON.parse(response.body))
|
26
26
|
end
|
27
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
|
+
|
28
36
|
def asset(symbol:)
|
29
37
|
response = get_request(endpoint, "v2/assets/#{symbol}")
|
30
38
|
Asset.new(JSON.parse(response.body))
|
@@ -97,16 +105,24 @@ module Alpaca
|
|
97
105
|
end
|
98
106
|
end
|
99
107
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
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
|
+
|
115
|
+
def new_order(symbol:, side:, type:, time_in_force:, qty: nil, notional: nil,
|
116
|
+
limit_price: nil, stop_price: nil, extended_hours: false, client_order_id: nil,
|
117
|
+
order_class: nil, take_profit: nil, stop_loss: nil)
|
103
118
|
|
104
119
|
params = {
|
105
120
|
symbol: symbol,
|
106
|
-
qty: qty,
|
107
121
|
side: side,
|
108
122
|
type: type,
|
109
123
|
time_in_force: time_in_force,
|
124
|
+
qty: qty,
|
125
|
+
notional: notional,
|
110
126
|
limit_price: limit_price,
|
111
127
|
order_class: order_class,
|
112
128
|
stop_price: stop_price,
|
@@ -6,6 +6,7 @@ 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
|
10
11
|
class InvalidRequest < Error; end
|
11
12
|
class MissingParameters < 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
|
@@ -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.8.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: 2021-04-29 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
|
@@ -126,16 +126,22 @@ dependencies:
|
|
126
126
|
name: faraday
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0.15'
|
132
|
+
- - "<"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '2.0'
|
132
135
|
type: :runtime
|
133
136
|
prerelease: false
|
134
137
|
version_requirements: !ruby/object:Gem::Requirement
|
135
138
|
requirements:
|
136
|
-
- - "
|
139
|
+
- - ">="
|
137
140
|
- !ruby/object:Gem::Version
|
138
141
|
version: '0.15'
|
142
|
+
- - "<"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '2.0'
|
139
145
|
description: Alpaca API lets you build and trade with real-time market data for free.
|
140
146
|
email:
|
141
147
|
- ccarneiroj@gmail.com
|
@@ -165,8 +171,11 @@ files:
|
|
165
171
|
- lib/alpaca/trade/api/clock.rb
|
166
172
|
- lib/alpaca/trade/api/configuration.rb
|
167
173
|
- lib/alpaca/trade/api/errors.rb
|
174
|
+
- lib/alpaca/trade/api/last_trade.rb
|
175
|
+
- lib/alpaca/trade/api/non_trade_activity.rb
|
168
176
|
- lib/alpaca/trade/api/order.rb
|
169
177
|
- lib/alpaca/trade/api/position.rb
|
178
|
+
- lib/alpaca/trade/api/trade_activity.rb
|
170
179
|
- lib/alpaca/trade/api/version.rb
|
171
180
|
homepage: https://github.com/ccjr/alpaca-trade-api
|
172
181
|
licenses:
|