move files to glassnodeapi

This commit is contained in:
なるみ 2022-04-25 16:44:57 +08:00
parent 044470377b
commit b87eda3bbb
37 changed files with 74 additions and 37 deletions

View File

@ -0,0 +1,37 @@
package glassnode
import (
"context"
"time"
"github.com/c9s/bbgo/pkg/glassnode/glassnodeapi"
)
type Glassnode struct {
client *glassnodeapi.RestClient
}
func New(apiKey string) *Glassnode {
client := glassnodeapi.NewRestClient()
client.Auth(apiKey)
return &Glassnode{client: client}
}
func (g *Glassnode) QueryMarketCapInUSD(ctx context.Context, currency string) (float64, error) {
req := glassnodeapi.MarketRequest{
Client: g.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"