Types


Index


Data Models

Defines the types into which data will be deserialized.

Stonks.Models.AssetInfoType

Stores 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,
)
source
Stonks.Models.AssetPriceType

Stores 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
source
Stonks.Models.ExchangeRateType

Stores an exchange rate datapoint. Lowest frequency is daily.

Constructors

ExchangeRate(;
  base::String,
  target::String,
  date::Date,
  rate::Float64,
)
source
Stonks.Models.IncomeStatementType

Stores 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,
)
source
Stonks.Models.BalanceSheetType

Stores 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,
)
source
Stonks.Models.CashflowStatementType

Stores 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,
)
source
Stonks.Models.EarningsType

Stores 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,
)
source

API Clients

Stores information required to make requests HTTP APIs.

Stonks.APIClients.APIResourceType
APIResource{T<:AbstractStonksRecord}

Stores data required to make requests to an API resource.

Fields

  • url::String: the url of the API resource, excluding query parameters
  • query_params::Dict{String, String}: parameters used in the request
  • parser::AbstractContentParser: a subtype of AbstractContentParser implementing parse_content
  • headers::Dict{String,String}: HTTP headers
  • symbol_key::String: indicates the identifier for the symbol
  • max_batch_size::Integer: the maximum number of symbols allowed in a single request
  • max_retries::Integer: how many times to retry a failed request
  • rank_order::Integer: if multiple APIResource capable of handling T, 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,
)
source
Stonks.APIClients.APIClientType

Groups 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="")
source

Content Parsers

Parsers transform the content received from n HTTP request into a Vector{<:AbstractStonxRecord}


Stores

Responsible for persisting and retrieving data: Vector{<:AbstractStonxRecord}.

Stonks.Stores.FileStoreType
FileStore{T<:AbstractStonksRecord}

Stores all information needed for data storage and retrieval.

Fields

  • path::String: absolute or relative path
  • ids::AbstractVector{AbstractString}: list of identifiers. maximum 2 identifiers
  • format::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 T
  • time_colum::Union{AbstractString, Missing}: column representing time dimension. Can be skipped for AssetPrice and ExchangeRate.
  • 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)
source