-
-
Notifications
You must be signed in to change notification settings - Fork 283
/
datasource.go
59 lines (48 loc) · 1.31 KB
/
datasource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package glassnode
import (
"context"
"time"
"github.com/c9s/bbgo/pkg/datasource/glassnode/glassnodeapi"
)
type DataSource struct {
client *glassnodeapi.RestClient
}
func New(apiKey string) *DataSource {
client := glassnodeapi.NewRestClient()
client.Auth(apiKey)
return &DataSource{client: client}
}
// query last futures open interest
// https://docs.glassnode.com/api/derivatives#futures-open-interest
func (d *DataSource) QueryFuturesOpenInterest(ctx context.Context, currency string) (float64, error) {
req := glassnodeapi.DerivativesRequest{
Client: d.client,
Asset: currency,
// 25 hours ago
Since: time.Now().Add(-25 * time.Hour).Unix(),
Interval: glassnodeapi.Interval24h,
Metric: "futures_open_interest_sum",
}
resp, err := req.Do(ctx)
if err != nil {
return 0, err
}
return resp.Last().Value, nil
}
// query last market cap in usd
// https://docs.glassnode.com/api/market#market-cap
func (d *DataSource) QueryMarketCapInUSD(ctx context.Context, currency string) (float64, error) {
req := glassnodeapi.MarketRequest{
Client: d.client,
Asset: currency,
// 25 hours ago
Since: time.Now().Add(-25 * time.Hour).Unix(),
Interval: glassnodeapi.Interval24h,
Metric: "marketcap_usd",
}
resp, err := req.Do(ctx)
if err != nil {
return 0, err
}
return resp.Last().Value, nil
}