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:
Yo-An Lin 2022-04-28 11:35:08 +08:00 committed by GitHub
commit 553324d9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 96 additions and 37 deletions

View 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
}

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -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)

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import "github.com/c9s/requestgen"

View File

@ -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"

View File

@ -1,4 +1,4 @@
package glassnode
package glassnodeapi
import (
"encoding/json"