mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #560 from narumiruna/glassnode
feature: query last market cap and futures open interest in usd from glassnode
This commit is contained in:
commit
553324d9ed
59
pkg/datasource/glassnode/datasource.go
Normal file
59
pkg/datasource/glassnode/datasource.go
Normal file
|
@ -0,0 +1,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
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type AddressesRequest -url /v1/metrics/addresses/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type BlockchainRequest -url /v1/metrics/blockchain/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -22,7 +22,7 @@ type RestClient struct {
|
|||
apiKey string
|
||||
}
|
||||
|
||||
func NewClient() *RestClient {
|
||||
func NewRestClient() *RestClient {
|
||||
u, err := url.Parse(glassnodeBaseURL)
|
||||
if err != nil {
|
||||
panic(err)
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type DefiRequest -url /v1/metrics/defi/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type DerivativesRequest -url /v1/metrics/derivatives/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type DistributionRequest -url /v1/metrics/distribution/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type EntitiesRequest -url /v1/metrics/entities/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type ETH2Request -url /v1/metrics/eth2/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type FeesRequest -url /v1/metrics/fees/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type IndicatorsRequest -url /v1/metrics/indicators/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type InstitutionsRequest -url /v1/metrics/institutions/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type LightningRequest -url /v1/metrics/lightning/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type MarketRequest -url /v1/metrics/market/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type MempoolRequest -url /v1/metrics/mempool/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type MiningRequest -url /v1/metrics/mining/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type ProtocolsRequest -url /v1/metrics/protocols/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type SupplyRequest -url /v1/metrics/supply/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import "github.com/c9s/requestgen"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by "requestgen -method GET -type TransactionsRequest -url /v1/metrics/transactions/:metric -responseType Response"; DO NOT EDIT.
|
||||
|
||||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package glassnode
|
||||
package glassnodeapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
Loading…
Reference in New Issue
Block a user