-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add account config and activity endpoints. Structured as submodules of Account
- Loading branch information
1 parent
884a33d
commit a8cf838
Showing
8 changed files
with
199 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": { | ||
"APCA-API-KEY-ID": "***", | ||
"APCA-API-SECRET-KEY": "***" | ||
}, | ||
"method": "get", | ||
"options": { | ||
"recv_timeout": 30000 | ||
}, | ||
"request_body": "", | ||
"url": "https://paper-api.alpaca.markets/v2/account/activities/FFFFF" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "{\"code\":40010001,\"message\":\"invalid activity type: FFFFF\"}", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Thu, 11 Jun 2020 02:19:55 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Content-Length": "58", | ||
"Connection": "keep-alive", | ||
"Vary": "Origin" | ||
}, | ||
"status_code": 422, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": { | ||
"APCA-API-KEY-ID": "***", | ||
"APCA-API-SECRET-KEY": "***" | ||
}, | ||
"method": "get", | ||
"options": { | ||
"recv_timeout": 30000 | ||
}, | ||
"request_body": "", | ||
"url": "https://paper-api.alpaca.markets/v2/account/activities/FILL" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "[{\"id\":\"20200603093014199::486a1a31-4d0c-494b-aaca-afa36477ddb8\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:14.199812Z\",\"type\":\"fill\",\"price\":\"886.55\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"c47ff82f-fa83-4083-9121-3623f4b3cb8d\",\"cum_qty\":\"5\"},{\"id\":\"20200603093004179::5fcf57bf-f076-4e6b-97b9-85407d7258f0\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:04.17912Z\",\"type\":\"fill\",\"price\":\"324.9\",\"qty\":\"2\",\"side\":\"sell\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"888e4b05-b624-48b9-a6cd-a1edf680acbf\",\"cum_qty\":\"2\"},{\"id\":\"20200603093002274::f8f99c37-0633-4c5b-83cf-0ac21225dbbe\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:02.274467Z\",\"type\":\"fill\",\"price\":\"1437.01\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"3dd828ae-7f70-449f-a54b-28758db2323d\",\"cum_qty\":\"5\"},{\"id\":\"20200602093229623::deef5aa4-42d7-414d-a467-07952a29ce5b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:32:29.623585Z\",\"type\":\"fill\",\"price\":\"889.68\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"5\"},{\"id\":\"20200602093022170::6e0a9fb0-1505-4021-b7f7-cdc2f86d201a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:22.170536Z\",\"type\":\"partial_fill\",\"price\":\"893.5\",\"qty\":\"4\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"1\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"4\"},{\"id\":\"20200602093021488::83d1ccf5-d406-4441-9b61-2c657f168a7a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:21.488152Z\",\"type\":\"fill\",\"price\":\"321.41\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"142b4101-86a9-42f5-b43e-be2f15419c83\",\"cum_qty\":\"1\"},{\"id\":\"20200602093015030::d088575b-d22b-43f0-8581-9273eb36d8bb\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:15.030543Z\",\"type\":\"fill\",\"price\":\"1431.01\",\"qty\":\"5\",\"side\":\"buy\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"c8c18333-c7b0-4513-9e26-b66d110f64cd\",\"cum_qty\":\"5\"},{\"id\":\"20200602093005948::a594c3f5-aa4a-4718-b565-12f3e5b68d6b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:05.948784Z\",\"type\":\"fill\",\"price\":\"321.25\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"534fcff6-a666-4495-bb61-5c405b39bada\",\"cum_qty\":\"1\"}]", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Thu, 11 Jun 2020 02:19:56 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Transfer-Encoding": "chunked", | ||
"Connection": "keep-alive", | ||
"Vary": "Accept-Encoding" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
31 changes: 31 additions & 0 deletions
31
fixture/vcr_cassettes/account_activity/list_specific_success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": { | ||
"APCA-API-KEY-ID": "***", | ||
"APCA-API-SECRET-KEY": "***" | ||
}, | ||
"method": "get", | ||
"options": { | ||
"recv_timeout": 30000 | ||
}, | ||
"request_body": "", | ||
"url": "https://paper-api.alpaca.markets/v2/account/activities?activity_types=FILL%2CTRANS" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "[{\"id\":\"20200603093014199::486a1a31-4d0c-494b-aaca-afa36477ddb8\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:14.199812Z\",\"type\":\"fill\",\"price\":\"886.55\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"c47ff82f-fa83-4083-9121-3623f4b3cb8d\",\"cum_qty\":\"5\"},{\"id\":\"20200603093004179::5fcf57bf-f076-4e6b-97b9-85407d7258f0\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:04.17912Z\",\"type\":\"fill\",\"price\":\"324.9\",\"qty\":\"2\",\"side\":\"sell\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"888e4b05-b624-48b9-a6cd-a1edf680acbf\",\"cum_qty\":\"2\"},{\"id\":\"20200603093002274::f8f99c37-0633-4c5b-83cf-0ac21225dbbe\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:02.274467Z\",\"type\":\"fill\",\"price\":\"1437.01\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"3dd828ae-7f70-449f-a54b-28758db2323d\",\"cum_qty\":\"5\"},{\"id\":\"20200602093229623::deef5aa4-42d7-414d-a467-07952a29ce5b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:32:29.623585Z\",\"type\":\"fill\",\"price\":\"889.68\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"5\"},{\"id\":\"20200602093022170::6e0a9fb0-1505-4021-b7f7-cdc2f86d201a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:22.170536Z\",\"type\":\"partial_fill\",\"price\":\"893.5\",\"qty\":\"4\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"1\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"4\"},{\"id\":\"20200602093021488::83d1ccf5-d406-4441-9b61-2c657f168a7a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:21.488152Z\",\"type\":\"fill\",\"price\":\"321.41\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"142b4101-86a9-42f5-b43e-be2f15419c83\",\"cum_qty\":\"1\"},{\"id\":\"20200602093015030::d088575b-d22b-43f0-8581-9273eb36d8bb\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:15.030543Z\",\"type\":\"fill\",\"price\":\"1431.01\",\"qty\":\"5\",\"side\":\"buy\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"c8c18333-c7b0-4513-9e26-b66d110f64cd\",\"cum_qty\":\"5\"},{\"id\":\"20200602093005948::a594c3f5-aa4a-4718-b565-12f3e5b68d6b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:05.948784Z\",\"type\":\"fill\",\"price\":\"321.25\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"534fcff6-a666-4495-bb61-5c405b39bada\",\"cum_qty\":\"1\"}]", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Thu, 11 Jun 2020 02:19:35 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Transfer-Encoding": "chunked", | ||
"Connection": "keep-alive", | ||
"Vary": "Accept-Encoding" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "", | ||
"headers": { | ||
"APCA-API-KEY-ID": "***", | ||
"APCA-API-SECRET-KEY": "***" | ||
}, | ||
"method": "get", | ||
"options": { | ||
"recv_timeout": 30000 | ||
}, | ||
"request_body": "", | ||
"url": "https://paper-api.alpaca.markets/v2/account/activities" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "[{\"id\":\"20200603093014199::486a1a31-4d0c-494b-aaca-afa36477ddb8\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:14.199812Z\",\"type\":\"fill\",\"price\":\"886.55\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"c47ff82f-fa83-4083-9121-3623f4b3cb8d\",\"cum_qty\":\"5\"},{\"id\":\"20200603093004179::5fcf57bf-f076-4e6b-97b9-85407d7258f0\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:04.17912Z\",\"type\":\"fill\",\"price\":\"324.9\",\"qty\":\"2\",\"side\":\"sell\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"888e4b05-b624-48b9-a6cd-a1edf680acbf\",\"cum_qty\":\"2\"},{\"id\":\"20200603093002274::f8f99c37-0633-4c5b-83cf-0ac21225dbbe\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-03T13:30:02.274467Z\",\"type\":\"fill\",\"price\":\"1437.01\",\"qty\":\"5\",\"side\":\"sell\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"3dd828ae-7f70-449f-a54b-28758db2323d\",\"cum_qty\":\"5\"},{\"id\":\"20200602093229623::deef5aa4-42d7-414d-a467-07952a29ce5b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:32:29.623585Z\",\"type\":\"fill\",\"price\":\"889.68\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"0\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"5\"},{\"id\":\"20200602093022170::6e0a9fb0-1505-4021-b7f7-cdc2f86d201a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:22.170536Z\",\"type\":\"partial_fill\",\"price\":\"893.5\",\"qty\":\"4\",\"side\":\"buy\",\"symbol\":\"TSLA\",\"leaves_qty\":\"1\",\"order_id\":\"36e3e15f-6fe2-4a32-8229-543a08a92fbf\",\"cum_qty\":\"4\"},{\"id\":\"20200602093021488::83d1ccf5-d406-4441-9b61-2c657f168a7a\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:21.488152Z\",\"type\":\"fill\",\"price\":\"321.41\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"142b4101-86a9-42f5-b43e-be2f15419c83\",\"cum_qty\":\"1\"},{\"id\":\"20200602093015030::d088575b-d22b-43f0-8581-9273eb36d8bb\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:15.030543Z\",\"type\":\"fill\",\"price\":\"1431.01\",\"qty\":\"5\",\"side\":\"buy\",\"symbol\":\"GOOG\",\"leaves_qty\":\"0\",\"order_id\":\"c8c18333-c7b0-4513-9e26-b66d110f64cd\",\"cum_qty\":\"5\"},{\"id\":\"20200602093005948::a594c3f5-aa4a-4718-b565-12f3e5b68d6b\",\"activity_type\":\"FILL\",\"transaction_time\":\"2020-06-02T13:30:05.948784Z\",\"type\":\"fill\",\"price\":\"321.25\",\"qty\":\"1\",\"side\":\"buy\",\"symbol\":\"AAPL\",\"leaves_qty\":\"0\",\"order_id\":\"534fcff6-a666-4495-bb61-5c405b39bada\",\"cum_qty\":\"1\"}]", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Thu, 11 Jun 2020 02:19:54 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Transfer-Encoding": "chunked", | ||
"Connection": "keep-alive", | ||
"Vary": "Accept-Encoding" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Alpaca.Account.Activity do | ||
@moduledoc """ | ||
A resource that allows us to perform operations on an Account Activity | ||
An account activity has the following methods we can call on it | ||
``` | ||
get/1 | ||
list/1 | ||
``` | ||
The `get/1` method allows us to get a singular account activity by calling | ||
`Alpaca.Account.Activity.get(activity_type)`. Where `activity_type` is the | ||
type of activity you want to retrieve information for. | ||
The `list/1` method allows us to list all account activities by calling `Alpaca.Account.Activity.list(params)`. | ||
Where the params is a map, and in this case takes only one param which is `activity_types`. A comma separated | ||
string of activities types | ||
""" | ||
use Alpaca.Resource, | ||
endpoint: "account/activities", | ||
exclude: [:create, :edit, :delete, :delete_all] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Alpaca.Account.ActivityTest do | ||
use ExUnit.Case, async: true | ||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney | ||
|
||
alias Alpaca.Account.Activity | ||
|
||
describe "list/1" do | ||
test "gets the list of account activities successfully" do | ||
use_cassette "account_activity/list_success" do | ||
assert {:ok, account_activities} = Activity.list() | ||
assert length(account_activities) == 8 | ||
end | ||
end | ||
|
||
test "gets the list of account activities successfully with defined types" do | ||
use_cassette "account_activity/list_specific_success" do | ||
assert {:ok, account_activities} = Activity.list(%{activity_types: "FILL,TRANS"}) | ||
assert length(account_activities) == 8 | ||
end | ||
end | ||
end | ||
|
||
describe "get/1" do | ||
test "gets the Account Activity successfully by symbol" do | ||
use_cassette "account_activity/get_success" do | ||
assert {:ok, account_activities} = Activity.get("FILL") | ||
assert length(account_activities) == 8 | ||
|
||
Enum.each(account_activities, fn aa -> | ||
assert aa.activity_type == "FILL" | ||
end) | ||
end | ||
end | ||
|
||
test "cannot find the Account Activity" do | ||
use_cassette "account_activity/get_not_found" do | ||
activity_type = "FFFFF" | ||
message = "invalid activity type: FFFFF" | ||
|
||
assert {:error, %{status: 422, body: %{code: 40_010_001, message: ^message}}} = | ||
Activity.get(activity_type) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters