Some checks failed
Build / Build (push) Failing after 6m48s
Build / Build UI (push) Failing after 1m29s
Validate Schema / build (push) Failing after 3s
Build / Publish :latest (push) Has been skipped
Build / Publish :release (push) Has been skipped
Build / Release (push) Has been skipped
38 lines
852 B
Go
38 lines
852 B
Go
package awattar
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
const RegionURI = "https://api.awattar.%s/v1/marketdata"
|
|
|
|
type Prices struct {
|
|
Data []PriceInfo
|
|
}
|
|
|
|
type PriceInfo struct {
|
|
StartTimestamp time.Time `json:"start_timestamp"`
|
|
EndTimestamp time.Time `json:"end_timestamp"`
|
|
Marketprice float64 `json:"marketprice"`
|
|
Unit string `json:"unit"`
|
|
}
|
|
|
|
func (p *PriceInfo) UnmarshalJSON(data []byte) error {
|
|
var s struct {
|
|
StartTimestamp int64 `json:"start_timestamp"`
|
|
EndTimestamp int64 `json:"end_timestamp"`
|
|
Marketprice float64 `json:"marketprice"`
|
|
Unit string `json:"unit"`
|
|
}
|
|
|
|
err := json.Unmarshal(data, &s)
|
|
if err == nil {
|
|
p.StartTimestamp = time.Unix(s.StartTimestamp/1e3, 0)
|
|
p.EndTimestamp = time.Unix(s.EndTimestamp/1e3, 0)
|
|
p.Marketprice = s.Marketprice
|
|
p.Unit = s.Unit
|
|
}
|
|
|
|
return err
|
|
}
|