Types
Index
Stonks.APIClients.APIClient
Stonks.APIClients.APIResource
Stonks.APIClients.AbstractDataClient
Stonks.Models.AbstractStonksRecord
Stonks.Models.AssetInfo
Stonks.Models.AssetPrice
Stonks.Models.BalanceSheet
Stonks.Models.CashflowStatement
Stonks.Models.Earnings
Stonks.Models.ExchangeRate
Stonks.Models.IncomeStatement
Stonks.Parsers.AbstractContentParser
Stonks.Parsers.CSVParser
Stonks.Parsers.JSONParser
Stonks.Stores.AbstractStore
Stonks.Stores.FileStore
Data Models
Defines the types into which data will be deserialized.
Stonks.Models.AbstractStonksRecord
— TypeAbstract type inteded to be subtyped by an data model.
All subtypes are constructed from keyword args and optional values default to missing
.
Stonks.Models.AssetInfo
— TypeStores general information about a quoted symbol / ticker.
Constructors
AssetInfo(;
symbol::String,
currency::String,
name::Union{String,Missing}=missing,
type::Union{String,Missing}=missing,
exchange::Union{String,Missing}=missing,
country::Union{String,Missing}=missing,
industry::Union{String,Missing}=missing,
sector::Union{String,Missing}=missing,
timezone::Union{String,Missing}=missing,
employees::Union{Int,Missing}=missing,
)
Stonks.Models.AssetPrice
— TypeStores a time series datapoint with price information. Lowest frequency is daily.
Constructors
AssetPrice(
symbol::String,
date::Date,
close::Float64,
open::Union{Float64,Missing} = missing,
high::Union{Float64,Missing} = missing,
low::Union{Float64,Missing} = missing,
close_adjusted::Union{Float64,Missing} = missing,
volume::Union{Integer,Missing} = missing,
)
end
Stonks.Models.ExchangeRate
— TypeStores an exchange rate datapoint. Lowest frequency is daily.
Constructors
ExchangeRate(;
base::String,
target::String,
date::Date,
rate::Float64,
)
Stonks.Models.IncomeStatement
— TypeStores a datapoint containing income statement information. Follows normalized fields mapped to GAAP and IFRS taxonomies of the SEC.
Constructors
IncomeStatement(;
symbol::String,
frequency::String,
date::Date,
currency::Union{String,Missing} = missing,
total_revenue::Int64,
cost_of_revenue::Int64,
gross_profit::Int64,
operating_income::Int64,
selling_general_and_administrative::Union{Int64,Missing} = missing,
research_and_development::Union{Int64,Missing} = missing,
depreciation::Union{Int64,Missing} = missing, # Depreciation, Total
depreciation_and_amortization::Union{Int64,Missing} = missing,
income_before_tax::Union{Int64,Missing} = missing,
income_tax_expense::Union{Int64,Missing} = missing,
interest_expense::Union{Int64,Missing} = missing,
interest_and_debt_expense::Union{Int64,Missing} = missing,
ebit::Union{Int64,Missing} = missing,
ebitda::Union{Int64,Missing} = missing,
net_income::Int64,
net_income_common_shares::Union{Int64,Missing} = missing,
)
Stonks.Models.BalanceSheet
— TypeStores a datapoint containing balance sheet information. Follows normalized fields mapped to GAAP and IFRS taxonomies of the SEC.
Constructors
BalanceSheet(;
symbol::String,
frequency::String,
date::Date,
currency::Union{String,Missing} = missing,
total_assets::Int64,
total_liabilities::Int64,
total_shareholder_equity::Int64,
cash_and_equivalents::Union{Int64,Missing} = missing,
current_net_receivables::Union{Int64,Missing} = missing,
inventory::Union{Int64,Missing} = missing,
short_term_investments::Union{Int64,Missing} = missing,
other_current_assets::Union{Int64,Missing} = missing,
total_current_assets::Union{Int64,Missing} = missing,
property_plant_equipment::Union{Int64,Missing} = missing,
goodwill::Union{Int64,Missing} = missing,
long_term_investments::Union{Int64,Missing} = missing,
intangible_assets::Union{Int64,Missing} = missing,
total_noncurrent_assets::Union{Int64,Missing} = missing,
current_accounts_payable::Union{Int64,Missing} = missing,
deferred_revenue::Union{Int64,Missing} = missing,
short_term_debt::Union{Int64,Missing} = missing,
other_current_liabilities::Union{Int64,Missing} = missing,
total_current_liabilities::Union{Int64,Missing} = missing,
current_debt::Union{Int64,Missing} = missing,
current_long_term_debt::Union{Int64,Missing} = missing,
long_term_debt::Union{Int64,Missing} = missing,
long_term_debt_noncurrent::Union{Int64,Missing} = missing,
capital_lease_obligations::Union{Int64,Missing} = missing,
other_noncurrent_liabilities::Union{Int64,Missing} = missing,
total_noncurrent_liabilities::Union{Int64,Missing} = missing,
treasury_stock::Union{Int64,Missing} = missing,
retained_earnings::Union{Int64,Missing} = missing,
common_stock::Union{Int64,Missing} = missing,
common_stock_shares_outstanding::Union{Int64,Missing} = missing,
)
Stonks.Models.CashflowStatement
— TypeStores a datapoint containing cashflow statement information.
Constructors
CashflowStatement(;
symbol::String,
frequency::String,
date::String,
currency::String,
operating_cashflow::Union{Int64,Missing} = missing,
cashflow_investment::Union{Int64,Missing} = missing,
cashflow_financing::Union{Int64,Missing} = missing,
change_operating_liabilities::Union{Int64,Missing} = missing,
change_receivables::Union{Int64,Missing} = missing,
change_inventory::Union{Int64,Missing} = missing,
change_cash_and_equivalents::Union{Int64,Missing} = missing,
depreciation_and_amortization::Union{Int64,Missing} = missing,
capital_expenditures::Union{Int64,Missing} = missing,
dividend_payout::Union{Int64,Missing} = missing,
stock_repurchase::Union{Int64,Missing} = missing,
net_income::Union{Int64,Missing} = missing,
)
Stonks.Models.Earnings
— TypeStores a datapoint containing earnings (per share) information.
Constructors
Earnings(;
symbol::String,
frequency::String,
date::Date,
currency::Union{String,Missing} = missing,
actual::Float16,
estimate::Union{Float16,Missing} = missing,
)
API Clients
Stores information required to make requests HTTP APIs.
Stonks.APIClients.AbstractDataClient
— TypeAbstract type to be subtyped by any type responsible for data retrieval, like HTTP API or web socket.
Stonks.APIClients.APIResource
— TypeAPIResource{T<:AbstractStonksRecord}
Stores data required to make requests to an API resource.
Fields
url::String
: the url of the API resource, excluding query parametersquery_params::Dict{String, String}
: parameters used in the requestparser::AbstractContentParser
: a subtype ofAbstractContentParser
implementingparse_content
headers::Dict{String,String}
: HTTP headerssymbol_key::String
: indicates the identifier for the symbolmax_batch_size::Integer
: the maximum number of symbols allowed in a single requestmax_retries::Integer
: how many times to retry a failed requestrank_order::Integer
: if multipleAPIResource
capable of handlingT
, the one with highest values is preffered.
Constructors
APIResource{T}(;
url::String,
parser::AbstractContentParser,
headers::Dict{String, String} = Dict(),
query_params::Dict{String, String} = Dict(),
symbol_key::String = max_batch_size > 1 ? "symbols" : "symbol",
max_batch_size::String = 1,
max_retries::Integer = 0,
rank_order::Integer = 1,
)
Stonks.APIClients.APIClient
— TypeGroups collection of APIResource
. Can hold resources from the same or different API.
Fields
resources::Dict{String,APIResource}
[url::String]
: for descriptive purposes. should be ommited if you mix in resources from different APIs.
Constructors
APIClient(resources::Dict{String, APIResource}, url::String="")
Content Parsers
Parsers transform the content received from n HTTP request into a Vector{<:AbstractStonxRecord}
Stonks.Parsers.AbstractContentParser
— TypeAbstract type to be subclassed by any type of parser.
Stonks.Parsers.JSONParser
— TypeA wrapper type for a function implementing parse_content
interface for JSON content.
Stonks.Parsers.CSVParser
— TypeA wrapper type for a function implementing parse_content
interface for CSV content.
Stores
Responsible for persisting and retrieving data: Vector{<:AbstractStonxRecord}
.
Stonks.Stores.AbstractStore
— TypeAbstract type to be subtyped by all types of Stores, like FileStore
. DatabaseStore
.
Stonks.Stores.FileStore
— TypeFileStore{T<:AbstractStonksRecord}
Stores all information needed for data storage and retrieval.
Fields
path::String
: absolute or relative pathids::AbstractVector{AbstractString}
: list of identifiers. maximum 2 identifiersformat::String
: file format. all files will have the ending like "data.{format}". default = "csv"partitions::AbstractVector{AbstractString}
: columns used for data partitioning. columns have to be members of Ttime_colum::Union{AbstractString, Missing}
: column representing time dimension. Can be skipped forAssetPrice
andExchangeRate
.reader::Function
: reader(path::String) -> Vector{AbstractStonksRecord}writer::Function
: writer(data::Vector{<:AbstractStonksRecord}, path::String)
Constructors
FileStore{<:AbstractStonksRecord}(;
path,
ids,
format="csv",
partitions=[],
time_column=missing,
reader=reader_csv,
writer=writer_csv,
)
# where,
reader_csv(path::String) = apply_schema(CSV.File(path), T<:AbstractStonksRecord)
writer_csv(data::Vector{<:AbstractStonksRecord}, path::String) = CSV.write(path, data)
Examples
using Stonks
dest = joinpath(@__DIR__, "data/stonks")
FileStore{AssetInfo}(; path=dest, ids=["symbol"])
FileStore{AssetPrice}(; path=dest, ids=["symbol"], time_column="date")
FileStore{AssetPrice}(; path=dest, ids=[:symbol], partitions=[:symbol], time_column ="date")
using Arrow
read = read_arrow(path::String) = Arrow.Table(path)
write = write_arrow(data, path::String) = open(path, "w") do io Arrow.write(io, data) end
FileStore{ExchangeRate}(; path=dest, ids=[:base, :target], time_column="date", reader=read, writer=write)