For basic usage, run ./pricedbfetcher -help
.
Like most APIs, these have query limits, so your queries may be rate-limited if you try to download too much at once. Check each one's official documentation for specifics.
You need an account to use this API, but you can use it to query full price history for many stocks, ETFs, etc - even ones you don't own.
- Follow Questrade's instructions to "create an app" and generate an API key.
- Create a file on your computer with a comma-separated list of your account numbers (all on a signle line, no whitespace between them).
- Create another file with your API key in it (and nothing else).
- Use the
-questrade-account-numbers-file
and-questrade-token-file
to letpricedbfetcher
know where to find your files. Note that the token file will be overwritten.
We use the markets/candles and accounts/positions API calls.
This is a completely public, unauthenticated API (at least the parts we need), good for convenient access to current crypto prices (but not full history). No setup, registration, or local credentials files are needed.
You'll need to sign up for Alpha Vantage, but it actually supports stocks, foreign-exchange, and crypto. I prefer using Questrade for stocks and Coinbase for crypto (don't remember why, but I think it may have been due to small query limit and long waits for rate-limiting). But it's certainly handy for FX, if nothing else.
- Register for an API key
- Put your API key in a file (alone)
- Use the
-alphavantage-api-key-file
flag to tellpricedbfetcher
about your file.
API calls we may use (depending on which categories you want to use it for):
This is a JSON file described by the pricedbfetcher/lib/lib.go Config struct. The start_date
field should be a date in YYYY-MM-DD format. Each section is described in more detail below.
This file should be pointed to by the -price-db-file
flag.
Example config:
{
"start_date": "2019-05-10",
"alphavantage": {
"forex_symbols": [
"GBP",
"USD"
],
"cryptocurrency_symbols": [
"BTC",
"ETH"
],
"stock_synbols": [
"GOOG"
]
},
"questrade": {
"market_symbols": [
"XBAL.TO",
"BNDX"
],
"position_symbols": [
"FAKE.SYMBOL"
]
},
"coinbase": {
"currencies": [
"LTC"
]
},
"commodity": {
"GBP": {
"display": "£"
},
"XBAL.TO": {
"display": "\"XBAL.TO\"",
"currency": "CAD"
}
}
}
Defined in alphavantage/alphavantage.go Config struct.
forex_symbols
: array of foreign currencies to trackcryptocurrency_symbols
: array of crypto symbols to trackstock_synbols
: array of stocks to track
Defined in questrade/questrade.go Config struct.
market_symbols
: stock symbols that Questrade can natively handleposition_symbols
: stock symbols that aren't in Questrade's normal database, but you have in your account (possibly due to a transfer from another account)
Defined in coinbase/coinbase.go Config struct.
currencies
: list of cryptocurrencies to track
Defined in pricedbfetcher/lib/lib.go CommodityConfig struct.
- object where each attribute name should be a symbol specified in one of the previous sections, and each attribute value should be an instance of an object with the following (optional) properties:
display
: string to record inprice.db
. If unspecified, we'll use the symbol as written elsewhere in the file.currency
: currency to use for transactions of this commodity. If unspecified, we'll use '$'.
A ledger price-db file (see documentation). The file is expected to exist already, but may be empty. Anything in the file apart from comments or P
statements may not be supported.