-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from jrusso1020/last-trade
Last Trade Data API
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 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://data.alpaca.markets/v1/last/stocks/FFFFF" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "{\"code\":40410000,\"message\":\"resource not found\"}", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Sat, 20 Jun 2020 18:54:17 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Content-Length": "48", | ||
"Connection": "keep-alive", | ||
"Vary": "Origin" | ||
}, | ||
"status_code": 404, | ||
"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://data.alpaca.markets/v1/last/stocks/AAPL" | ||
}, | ||
"response": { | ||
"binary": false, | ||
"body": "{\"status\":\"success\",\"symbol\":\"AAPL\",\"last\":{\"price\":347.71,\"size\":100,\"exchange\":2,\"cond1\":12,\"cond2\":0,\"cond3\":0,\"cond4\":0,\"timestamp\":1592600755847000064}}", | ||
"headers": { | ||
"Server": "nginx/1.16.1", | ||
"Date": "Sat, 20 Jun 2020 18:54:18 GMT", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Content-Length": "157", | ||
"Connection": "keep-alive", | ||
"Vary": "Origin" | ||
}, | ||
"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,20 @@ | ||
defmodule Alpaca.Last.Trade do | ||
@moduledoc """ | ||
A resource that allows us to query for the last trade of a symbol | ||
An last trade activity has the following methods we can call on it | ||
``` | ||
get/1 | ||
``` | ||
The `get/1` method allows us to get a singulat last trade for a given symbol by calling | ||
`Alpaca.Last.Trade.get(symbol)`. Where `symbol` is the | ||
stock symbol you want to retrieve last trade information for. | ||
""" | ||
alias Alpaca.Client | ||
|
||
use Alpaca.Resource, | ||
endpoint: "last/stocks", | ||
exclude: [:list, :create, :edit, :delete, :delete_all, :update], | ||
opts: [version: "v1", api_host: Client.data_api_host()] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Alpaca.TradeTest do | ||
use ExUnit.Case, async: true | ||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney | ||
|
||
alias Alpaca.Last.Trade | ||
|
||
describe "get/1" do | ||
test "gets the last trade successfully" do | ||
use_cassette "last_trade/get_success" do | ||
assert {:ok, %{status: "success", symbol: "AAPL", last: last}} = Trade.get("AAPL") | ||
end | ||
end | ||
|
||
test "gets the last trade unsuccessfully" do | ||
use_cassette "last_trade/get_failure" do | ||
assert {:error, %{status: 404, body: %{code: 40_410_000, message: "resource not found"}}} = | ||
Trade.get("FFFFF") | ||
end | ||
end | ||
end | ||
end |