-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
12 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,48 @@ | ||
.py("klongpy.ws") | ||
|
||
.comment("****") | ||
Auth Volley: | ||
|
||
receive: [{"T":"success","msg":"connected"}] | ||
send: {"action": "auth", "key": "{KEY_ID}", "secret": "{SECRET}"} | ||
receive: [{"T":"success","msg":"authenticated"}] | ||
|
||
send: {"action":"subscribe","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":["*"]} | ||
confirmation: [{"T":"subscription","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":["*"],"updatedBars":[],"dailyBars":["VOO"],"statuses":["*"],"lulds":[],"corrections":["AAPL"],"cancelErrors":["AAPL"]}] | ||
|
||
{"action": "unsubscribe", "bars": ["*"]} | ||
|
||
{ | ||
"T": "t", | ||
"i": 96921, | ||
"S": "AAPL", | ||
"x": "D", | ||
"p": 126.55, | ||
"s": 1, | ||
"t": "2021-02-22T15:51:44.208Z", | ||
"c": ["@", "I"], | ||
"z": "C" | ||
} | ||
**** | ||
|
||
auth:::{["action" "auth"]} | ||
auth,"key",,.os.env?"ALPACA_API_KEY" | ||
auth,"secret",,.os.env?"ALPACA_SECRET_KEY" | ||
|
||
subscription:::{["action" "subscribe"]} | ||
subscription,"trades",,["AAPL"] | ||
.p(subscription) | ||
subscribe::{x(subscription)} | ||
|
||
handleData::{.p(y)} | ||
|
||
handleError::{.d("error: ");.p(y)} | ||
|
||
sendAuth::{.p("sending auth");x(auth)} | ||
handleAuthFailure::{.p("failed to auth")} | ||
handleLogin::{.p("logged in");subscribe(x)} | ||
handleControl::{[msg];msg::y?"msg";:[msg="connected";sendAuth(x);:[msg="authenticated";handleLogin(x;y);handleAuthFailure(x;y)]]} | ||
handleMsg::{[q T];.p(y);T::y?"T";:[T="success";handleControl(x;y);:[T="error";handleError(x;y);handleData(x;y)]]} | ||
.ws.m::{[c];c::x;{handleMsg(c;x)}'y} | ||
|
||
c::.ws("wss://stream.data.alpaca.markets/v2/sip") |
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,30 @@ | ||
.comment("****") | ||
|
||
Get a list of all tickers from Alpaca. | ||
For each ticker, get the latest stored time from the dfs and use that as the start time for the next request | ||
map the new ticker data to the columns of the dfs | ||
append the new data to the dfs | ||
write the data back to the dfs | ||
|
||
**** | ||
|
||
.py("klongpy.db") | ||
.pyf("alpaca.trading.client";"TradingClient") | ||
.pyf("alpaca.data.historical";"StockHistoricalDataClient") | ||
.pyf("alpaca.data.requests";"StockLatestTradeRequest") | ||
|
||
keys:::{} | ||
keys,"api_key",,.os.env?"ALPACA_API_KEY" | ||
keys,"secret_key",,.os.env?"ALPACA_SECRET_KEY" | ||
|
||
args:::{};{args,x,,y}'keys | ||
|
||
tc::.pyc(TradingClient;[];args) | ||
account::.pyc(tc,"get_account";[];:{}) | ||
|
||
.d("cash: ");.p(.pyc(account,"cash";[];:{})) | ||
|
||
dc::.pyc(StockHistoricalDataClient;[];keys) | ||
tr::.pyc(StockLatestTradeRequest;[];:{["symbol_or_symbols" ["MSFT"]]}) | ||
prices::.pyc(dc,"get_stock_latest_trade";,tr;:{}) | ||
.d("prices: ");.p(prices) |
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