Documentation
¶
Index ¶
- Constants
- Variables
- func GetPrices(ctx context.Context, timestamps []time.Time, granularity Granularity) (map[time.Time]*USDPrice, error)
- func MsatToUSD(price decimal.Decimal, amt lnwire.MilliSatoshi) decimal.Decimal
- func UseLogger(logger btclog.Logger)
- type Granularity
- type PriceRequest
- type USDPrice
Constants ¶
const Subsystem = "FIAT"
Subsystem defines the logging code for this subsystem.
Variables ¶
var ( // GranularityMinute aggregates the bitcoin price over 1 minute. GranularityMinute = newGranularity(time.Minute, time.Hour*24, "m1") // Granularity5Minute aggregates the bitcoin price over 5 minute. Granularity5Minute = newGranularity( time.Minute*5, time.Hour*24*5, "m5", ) // Granularity15Minute aggregates the bitcoin price over 15 minutes. Granularity15Minute = newGranularity( time.Minute*15, time.Hour*24*7, "m15", ) // Granularity30Minute aggregates the bitcoin price over 30 minutes. Granularity30Minute = newGranularity( time.Minute*30, time.Hour*24*14, "m30", ) // GranularityHour aggregates the bitcoin price over 1 hour. GranularityHour = newGranularity( time.Hour, time.Hour*24*30, "h1", ) // Granularity6Hour aggregates the bitcoin price over 6 hours. Granularity6Hour = newGranularity( time.Hour*6, time.Hour*24*183, "h6", ) // Granularity12Hour aggregates the bitcoin price over 12 hours. Granularity12Hour = newGranularity( time.Hour*12, time.Hour*24*365, "h12", ) // GranularityDay aggregates the bitcoin price over one day. GranularityDay = newGranularity( time.Hour*24, time.Hour*24*7305, "d1", ) )
var ErrQueryTooLong = errors.New("period too long for coincap api, " +
"please reduce")
ErrQueryTooLong is returned when we cannot get a granularity level for a period of time because it is too long.
Functions ¶
func GetPrices ¶
func GetPrices(ctx context.Context, timestamps []time.Time, granularity Granularity) (map[time.Time]*USDPrice, error)
GetPrices gets a set of prices for a set of timestamps.
Types ¶
type Granularity ¶
type Granularity struct {
// contains filtered or unexported fields
}
Granularity indicates the level of aggregation price information will be provided at.
func BestGranularity ¶
func BestGranularity(duration time.Duration) (Granularity, error)
BestGranularity takes a period of time and returns the lowest granularity that we can query the coincap api in a single query. This helper is used to provide default granularity periods when they are not provided by requests.
type PriceRequest ¶
type PriceRequest struct {
// Identifier uniquely identifies the request.
Identifier string
// Value is the amount of BTC in msat.
Value lnwire.MilliSatoshi
// Timestamp is the time at which the price should be obtained.
Timestamp time.Time
}
PriceRequest describes a request for price information.
type USDPrice ¶
type USDPrice struct {
// Timestamp is the time at which the BTC price is quoted.
Timestamp time.Time
// Price is the price in USD for 1 BTC at the given timestamp.
Price decimal.Decimal
}
USDPrice represents the Bitcoin price in USD at a certain time.
func CoinCapPriceData ¶
func CoinCapPriceData(ctx context.Context, start, end time.Time, granularity Granularity) ([]*USDPrice, error)
CoinCapPriceData obtains price data over a given range for coincap.
func GetPrice ¶
GetPrice gets the price for a given time from a set of price data. This function expects the price data to be sorted with ascending timestamps and for first timestamp in the price data to be before any timestamp we are querying. The last datapoint's timestamp may be before the timestamp we are querying. If a request lies between two price points, we just return the earlier price.