Last active
October 31, 2021 04:05
-
-
Save rpkyle/cedf2b34043362d303ed677f139c8375 to your computer and use it in GitHub Desktop.
Dash for Julia Stock Ticker Sample App
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
using Dash, DashHtmlComponents, DashCoreComponents, HTTP, CSV, Dates, Printf | |
r = HTTP.request("GET", "https://finance.yahoo.com/quote/AMZN/history?p=AMZN"); | |
crumb = match(r"(?:CrumbStore\"\:\{\"crumb\":\")(.*?)(?:\")", String(r.body)).captures; | |
session_cookie = match(r"(?:B=)(.*?)(?:;)", HTTP.header(r, "Set-Cookie")).captures; | |
app = dash(); | |
app.layout = html_div(style=Dict("width"=>"500")) do | |
dcc_dropdown( | |
id="stock-dropdown", | |
options=[ | |
(label="Coke", value="COKE"), | |
(label="Tesla", value="TSLA"), | |
(label="Apple", value="AAPL") | |
], | |
value="COKE" | |
), | |
dcc_graph(id="stock-graph") | |
end; | |
callback!(app, | |
Output("stock-graph", "figure"), | |
Input("stock-dropdown", "value") | |
) do ticker | |
today = @sprintf("%i", datetime2unix(Dates.now())) | |
url = string("https://query1.finance.yahoo.com/v7/finance/download/", | |
ticker, "?period1=1167609600&period2=", today, "&interval=1d&events=history&crumb=", crumb[1]) | |
results = HTTP.request("GET", url, Dict("B"=>session_cookie[1])) | |
df = CSV.read(IOBuffer(String(results.body))); | |
return (data=[(x=df[:,"Date"], y=df[:,"Close"])], | |
layout=(margin=[(l=40, r=0, t=20, b=30)], | |
title=ticker)) | |
end; | |
run_server(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python version: https://gist.github.com/rpkyle/b69a4c70bb35b53c1902587a7c3e52dc
R version: https://gist.github.com/rpkyle/e01e67b1b395291f65b7a584ebe6a93a
F# version: https://gist.github.com/kMutagene/b1af6e4d388dbd04a47a1014ad450593