Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a function to set API key in ENV #13

Merged
merged 7 commits into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ os:
- linux
- osx
julia:
- 0.6
- 1.0
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
git:
depth: 99999999
depth: 1
after_success:
- julia -e 'Pkg.add("Documenter")'
- julia -e 'cd(Pkg.dir("AlphaVantage")); include(joinpath("docs", "make.jl"))'
- julia -e 'cd(Pkg.dir("AlphaVantage")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("AlphaVantage")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; Pkg.add("Documenter"); Pkg.add("Coverage");'
- julia -e 'import AlphaVantage; joinpath(dirname(pathof(AlphaVantage)), ".."); include(joinpath("docs", "make.jl"))'
- julia -e 'import AlphaVantage; joinpath(dirname(pathof(AlphaVantage)), ".."); using Coverage; Coveralls.submit(Coveralls.process_folder()); Codecov.submit(Codecov.process_folder())'
env:
matrix:
secure: iP1R+kU1IVioHrewc5qiLscGJ2+bTFFC/kM7IB6I4G13YBxBfXlaBf92lbRWKy4sb7stn9i4FjDWa4GBptNnsBddngWLjU7Eqb56MOdgYZN8x/xJlyCNDsl6fx8wMjgCyVNivCdV+UZ9bagrzwmlGFLQNjcNiRya5A850oMuFWvAf4BbWPb/gVS/JmKbkNQR42jjAs2hj8I2BnHQkEAJrwxXv2RUE8xXWAsajsnwnEUswtnlyIroWuExhqrnnb7twZj8kVVnGr3XcZdki6YByqbucd10oOw0s6sZlqkTgpBF9wtqgkhSk1Qj7rZ7MXG9Uwro8Ktd55CC1JzWEuOXyPmVWVsGiiIB2Dxc2kCqKknVmS42JoKwz3gtD6H0PhTYaH5vUoMnjCVHJFITjKdyDi6+Li/MPn6pR8gLfzrnzNOu4h7JfWpAwvMb01ecA35pZuBIHwzsaHbSiHVKprkxhH8Jkk3PLRWYbiGrrxP+7gl7IE18PR1TM2th5f+mVIaUm8bhgYTDNl3PBV3hd/ww7jUmLWCvpXP9K/XoyyNHvpcBm3EXP8BnzNPkR+39dZrjOSJADlNZXrPvbzocQXkBamuYngeDLPhSiVx4LPuFythv2zecsSBDeUbY4lTeytKL0oi3YwO2UBi/fp0Nrss2lyB3tm9XfOy493xKbW/N2nk=
158 changes: 158 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
[[ArgCheck]]
deps = ["Random", "Test"]
git-tree-sha1 = "9e3bff61bc46d3420d903b53ad07f85325fddc28"
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
version = "1.0.0"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinaryProvider]]
deps = ["Libdl", "Pkg", "SHA", "Test"]
git-tree-sha1 = "48c147e63431adbcee69bc40b04c3f0fec0a4982"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.0"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "ff2595695fc4f14427358ce2593f867085c45dcb"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "1.2.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[HTTP]]
deps = ["Base64", "Dates", "Distributed", "IniFile", "MbedTLS", "Sockets", "Test"]
git-tree-sha1 = "b881f69331e85642be315c63d05ed65d6fc8a05b"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.7.1"

[[HttpCommon]]
deps = ["Dates", "Nullables", "Pkg", "Test", "URIParser"]
git-tree-sha1 = "46313284237aa6ca67a6bce6d6fbd323d19cff59"
uuid = "77172c1b-203f-54ac-aa54-3f1198fe9f90"
version = "0.5.0"

[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"

[[InteractiveUtils]]
deps = ["LinearAlgebra", "Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON]]
deps = ["Dates", "Distributed", "Mmap", "Pkg", "Sockets", "Test", "Unicode"]
git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.19.0"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS]]
deps = ["BinaryProvider", "Libdl", "Pkg", "Random", "Sockets", "Test"]
git-tree-sha1 = "3775d205b09b624aa06d39012a8920ba99cb3b8b"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "0.6.3"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Nullables]]
deps = ["Compat", "Pkg"]
git-tree-sha1 = "ae1a63457e14554df2159b0b028f48536125092d"
uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"
version = "0.0.8"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RecipesBase]]
deps = ["Pkg", "Random", "Test"]
git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "0.6.0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[TimeSeries]]
deps = ["Dates", "DelimitedFiles", "Random", "RecipesBase", "Statistics", "Test"]
git-tree-sha1 = "3997f5a96c9738a19592950dfc37632a91fd57b0"
uuid = "9e3dc215-6440-5c97-bce1-76c03772f85e"
version = "0.13.0"

[[URIParser]]
deps = ["Test", "Unicode"]
git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69"
uuid = "30578b45-9adc-5946-b283-645ec420af67"
version = "0.4.0"

[[UUIDs]]
deps = ["Random"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
19 changes: 19 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "AlphaVantage"
uuid = "6348297c-a006-11e8-3a05-9bbf8830fd7b"
license = "MIT"
authors = ["Ellis Valentiner <ellisvalentiner@gmail.com>"]
version = "0.4.0"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
HttpCommon = "77172c1b-203f-54ac-aa54-3f1198fe9f90"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ If you encounter a clear bug, please file a minimal reproducible example on GitH
```julia
using AlphaVantage
using DataFrames
using Plots
using StatPlots
gr(size=(800,470))
# Get daily S&P 500 data
gspc = time_series_daily("^GSPC");
gspc = time_series_daily("^GSPC", datatype="csv");
# Convert to a DataFrame
data = DataFrame(gspc[2:end, :]);
# Add column names
names!(data, convert.(Symbol, gspc[1,:]));
# Convert timestamp column to Date type
data[:timestamp] = Dates.Date.(data[:timestamp]);
# Plot the timeseries
@df data plot(:timestamp, [:low :high :close], label=["Low" "High" "Close"], colour=[:red :green :blue], w=2)
@df data plot(:timestamp, [:low :high :close], label=["Low" "High" "Close"],
colour=["#A2A6A5", "#F68E5B", "#B47E6E"], w=2)
savefig("sp500.png")
```

Expand Down
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.6
julia 1.0
ArgCheck
HTTP
HttpCommon
Requests
JSON
12 changes: 2 additions & 10 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
using Documenter, AlphaVantage

makedocs(
modules = [AlphaVantage],
clean = false,
format = [:html],
sitename = "AlphaVantage",
pages = Any[
"Manual" => "index.md"
]
)
makedocs()

deploydocs(
deps = Deps.pip("mkdocs", "python-markdown-math"),
deps = Deps.pip("mkdocs"),
repo = "github.com/ellisvalentiner/AlphaVantage.jl.git",
julia = "0.6"
)
2 changes: 1 addition & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repo_url: https://github.com/ellisvalentiner/AlphaVantage.jl
site_description: A Julia wrapper for the Alpha Vantage API.
site_author: Ellis Valentiner

theme: material
theme: readthedocs

extra_css:
- assets/Documenter.css
Expand Down
11 changes: 4 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
```@meta
CurrentModule = AlphaVantage
```

# AlphaVantage.jl Documentation

Expand All @@ -14,7 +11,7 @@ The Alpha Vantage API requires a [free API key](https://www.alphavantage.co/supp

## Installation

```julia
```
# AlphaVantage.jl is not currently registered as an official package
# Please install the development version from GitHub:
Pkg.clone("git://GitHub.com/ellisvalentiner/AlphaVantage.jl")
Expand All @@ -26,7 +23,7 @@ If you encounter a clear bug, please file a minimal reproducible example on GitH

### Stock Time Series

```@docs
```
time_series_intraday()
time_series_daily()
time_series_daily_adjusted()
Expand All @@ -38,15 +35,15 @@ time_series_monthly_adjusted()

### Digital Currencies

```@docs
```
digital_currencies_daily()
digital_currencies_weekly()
digital_currencies_monthly()
```

## Usage

```julia
```
using AlphaVantage
using DataFrames
using Plots
Expand Down
6 changes: 4 additions & 2 deletions src/AlphaVantage.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
VERSION >= v"0.6.0"
VERSION >= v"1.0.0"

module AlphaVantage

const alphavantage_api = "https://www.alphavantage.co/"

using ArgCheck
using DelimitedFiles
using HTTP
using HttpCommon
using Requests
using JSON

include("utils.jl")
include("stock_time_series.jl")
Expand Down
21 changes: 16 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
Internal function that wraps Requests.get
"""
function _get_request(uri::String)
resp = Requests.get(uri)
status = statuscode(resp)
if status != 200
resp = HTTP.get(uri)
if resp.status != 200
desc = STATUS_CODES[status]
error("Expected status code 200 but received $status: $desc")
end
Expand All @@ -17,8 +16,20 @@ Internal function that parses the response
"""
function _parse_response(data, datatype::String)
if datatype == "csv"
return readcsv(data.data)
return readdlm(data.body, ',', header=true)
elseif datatype == "json"
return Requests.json(data)
return JSON.Parser.parse(String(data.body))
end
end

"""
set API key if the environment variable doesn't set or the "overwrite" flag set true
"""
function set_apikey(apikey::String; overwrite=true)
envkey = "ALPHA_VANTAGE_API_KEY"
if !haskey(ENV, envkey) | overwrite
ENV["ALPHA_VANTAGE_API_KEY"] = apikey
end
end

export set_apikey
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using AlphaVantage
using Base.Test
using Test

@testset "Stock Time Series" begin
for f in (:time_series_intraday, :time_series_daily, :time_series_daily_adjusted, :time_series_weekly, :time_series_weekly_adjusted, :time_series_monthly, :time_series_monthly_adjusted)
for f in (:time_series_intraday, :time_series_daily)
@eval begin
testname = string($f)
@testset "$testname" begin
Expand All @@ -15,7 +15,7 @@ using Base.Test
end

@testset "Digital Currencies" begin
for f in (:digital_currency_intraday, :digital_currency_daily, :digital_currency_weekly, :digital_currency_monthly)
for f in (:digital_currency_intraday, :digital_currency_daily)
@eval begin
testname = string($f)
@testset "$testname" begin
Expand Down