alpaca-trade-api 0.5.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/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +21 -20
- data/lib/alpaca/trade/api.rb +2 -0
- data/lib/alpaca/trade/api/client.rb +8 -0
- data/lib/alpaca/trade/api/errors.rb +1 -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 +4 -2
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/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ 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
|
+
|
7
11
|
## [0.5.0] - 2020-05-25
|
8
12
|
### Added
|
9
13
|
- Implemented Client#last_trade. Thanks @nathanworden.
|
data/Gemfile.lock
CHANGED
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/lib/alpaca/trade/api.rb
CHANGED
@@ -9,8 +9,10 @@ require 'alpaca/trade/api/bar'
|
|
9
9
|
require 'alpaca/trade/api/calendar'
|
10
10
|
require 'alpaca/trade/api/clock'
|
11
11
|
require 'alpaca/trade/api/last_trade'
|
12
|
+
require 'alpaca/trade/api/non_trade_activity'
|
12
13
|
require 'alpaca/trade/api/order'
|
13
14
|
require 'alpaca/trade/api/position'
|
15
|
+
require 'alpaca/trade/api/trade_activity'
|
14
16
|
|
15
17
|
require 'alpaca/trade/api/client'
|
16
18
|
require 'alpaca/trade/api/errors'
|
@@ -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))
|
@@ -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.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: 2020-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,8 +166,10 @@ files:
|
|
166
166
|
- lib/alpaca/trade/api/configuration.rb
|
167
167
|
- lib/alpaca/trade/api/errors.rb
|
168
168
|
- lib/alpaca/trade/api/last_trade.rb
|
169
|
+
- lib/alpaca/trade/api/non_trade_activity.rb
|
169
170
|
- lib/alpaca/trade/api/order.rb
|
170
171
|
- lib/alpaca/trade/api/position.rb
|
172
|
+
- lib/alpaca/trade/api/trade_activity.rb
|
171
173
|
- lib/alpaca/trade/api/version.rb
|
172
174
|
homepage: https://github.com/ccjr/alpaca-trade-api
|
173
175
|
licenses:
|