diff --git a/pkg/glassnode/glassnode.go b/pkg/glassnode/glassnode.go new file mode 100644 index 000000000..ee0248464 --- /dev/null +++ b/pkg/glassnode/glassnode.go @@ -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 +} diff --git a/pkg/glassnode/addresses.go b/pkg/glassnode/glassnodeapi/addresses.go similarity index 96% rename from pkg/glassnode/addresses.go rename to pkg/glassnode/glassnodeapi/addresses.go index 3a937c2ca..261880fe0 100644 --- a/pkg/glassnode/addresses.go +++ b/pkg/glassnode/glassnodeapi/addresses.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/addresses_request_requestgen.go b/pkg/glassnode/glassnodeapi/addresses_request_requestgen.go similarity index 99% rename from pkg/glassnode/addresses_request_requestgen.go rename to pkg/glassnode/glassnodeapi/addresses_request_requestgen.go index 3d7ee1cea..5af5f7724 100644 --- a/pkg/glassnode/addresses_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/addresses_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/blockchain.go b/pkg/glassnode/glassnodeapi/blockchain.go similarity index 96% rename from pkg/glassnode/blockchain.go rename to pkg/glassnode/glassnodeapi/blockchain.go index aa5630193..a9370f725 100644 --- a/pkg/glassnode/blockchain.go +++ b/pkg/glassnode/glassnodeapi/blockchain.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/blockchain_request_requestgen.go b/pkg/glassnode/glassnodeapi/blockchain_request_requestgen.go similarity index 99% rename from pkg/glassnode/blockchain_request_requestgen.go rename to pkg/glassnode/glassnodeapi/blockchain_request_requestgen.go index 59f73e5c1..d9978d3d8 100644 --- a/pkg/glassnode/blockchain_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/blockchain_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/client.go b/pkg/glassnode/glassnodeapi/client.go similarity index 98% rename from pkg/glassnode/client.go rename to pkg/glassnode/glassnodeapi/client.go index 54195ff87..3370854d6 100644 --- a/pkg/glassnode/client.go +++ b/pkg/glassnode/glassnodeapi/client.go @@ -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) diff --git a/pkg/glassnode/defi.go b/pkg/glassnode/glassnodeapi/defi.go similarity index 96% rename from pkg/glassnode/defi.go rename to pkg/glassnode/glassnodeapi/defi.go index e9269800c..44534256c 100644 --- a/pkg/glassnode/defi.go +++ b/pkg/glassnode/glassnodeapi/defi.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/defi_request_requestgen.go b/pkg/glassnode/glassnodeapi/defi_request_requestgen.go similarity index 99% rename from pkg/glassnode/defi_request_requestgen.go rename to pkg/glassnode/glassnodeapi/defi_request_requestgen.go index 8f51708ec..df39ba1fb 100644 --- a/pkg/glassnode/defi_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/defi_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/derivatives.go b/pkg/glassnode/glassnodeapi/derivatives.go similarity index 96% rename from pkg/glassnode/derivatives.go rename to pkg/glassnode/glassnodeapi/derivatives.go index d6f51e4df..00f0f0e69 100644 --- a/pkg/glassnode/derivatives.go +++ b/pkg/glassnode/glassnodeapi/derivatives.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/derivatives_request_requestgen.go b/pkg/glassnode/glassnodeapi/derivatives_request_requestgen.go similarity index 99% rename from pkg/glassnode/derivatives_request_requestgen.go rename to pkg/glassnode/glassnodeapi/derivatives_request_requestgen.go index 3efd49ab0..75c861a5c 100644 --- a/pkg/glassnode/derivatives_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/derivatives_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/distribution.go b/pkg/glassnode/glassnodeapi/distribution.go similarity index 96% rename from pkg/glassnode/distribution.go rename to pkg/glassnode/glassnodeapi/distribution.go index 02d847e06..35b47736d 100644 --- a/pkg/glassnode/distribution.go +++ b/pkg/glassnode/glassnodeapi/distribution.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/distribution_request_requestgen.go b/pkg/glassnode/glassnodeapi/distribution_request_requestgen.go similarity index 99% rename from pkg/glassnode/distribution_request_requestgen.go rename to pkg/glassnode/glassnodeapi/distribution_request_requestgen.go index 5a066d7a7..aa45e22ce 100644 --- a/pkg/glassnode/distribution_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/distribution_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/entities.go b/pkg/glassnode/glassnodeapi/entities.go similarity index 96% rename from pkg/glassnode/entities.go rename to pkg/glassnode/glassnodeapi/entities.go index 25d0a0101..5e32dad26 100644 --- a/pkg/glassnode/entities.go +++ b/pkg/glassnode/glassnodeapi/entities.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/entities_request_requestgen.go b/pkg/glassnode/glassnodeapi/entities_request_requestgen.go similarity index 99% rename from pkg/glassnode/entities_request_requestgen.go rename to pkg/glassnode/glassnodeapi/entities_request_requestgen.go index c91a1eef8..3fd3e3929 100644 --- a/pkg/glassnode/entities_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/entities_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/eth2.go b/pkg/glassnode/glassnodeapi/eth2.go similarity index 96% rename from pkg/glassnode/eth2.go rename to pkg/glassnode/glassnodeapi/eth2.go index d7b5deb3e..241ab4d17 100644 --- a/pkg/glassnode/eth2.go +++ b/pkg/glassnode/glassnodeapi/eth2.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/eth_2_request_requestgen.go b/pkg/glassnode/glassnodeapi/eth_2_request_requestgen.go similarity index 99% rename from pkg/glassnode/eth_2_request_requestgen.go rename to pkg/glassnode/glassnodeapi/eth_2_request_requestgen.go index 17bea7d8f..3d9502a33 100644 --- a/pkg/glassnode/eth_2_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/eth_2_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/fees.go b/pkg/glassnode/glassnodeapi/fees.go similarity index 96% rename from pkg/glassnode/fees.go rename to pkg/glassnode/glassnodeapi/fees.go index 6d215fb63..449b56776 100644 --- a/pkg/glassnode/fees.go +++ b/pkg/glassnode/glassnodeapi/fees.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/fees_request_requestgen.go b/pkg/glassnode/glassnodeapi/fees_request_requestgen.go similarity index 99% rename from pkg/glassnode/fees_request_requestgen.go rename to pkg/glassnode/glassnodeapi/fees_request_requestgen.go index e269fb8ff..e5071cc5e 100644 --- a/pkg/glassnode/fees_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/fees_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/indicators.go b/pkg/glassnode/glassnodeapi/indicators.go similarity index 96% rename from pkg/glassnode/indicators.go rename to pkg/glassnode/glassnodeapi/indicators.go index 1899b4b10..d8382545e 100644 --- a/pkg/glassnode/indicators.go +++ b/pkg/glassnode/glassnodeapi/indicators.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/indicators_request_requestgen.go b/pkg/glassnode/glassnodeapi/indicators_request_requestgen.go similarity index 99% rename from pkg/glassnode/indicators_request_requestgen.go rename to pkg/glassnode/glassnodeapi/indicators_request_requestgen.go index 858673cf2..0df98c803 100644 --- a/pkg/glassnode/indicators_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/indicators_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/institutions.go b/pkg/glassnode/glassnodeapi/institutions.go similarity index 96% rename from pkg/glassnode/institutions.go rename to pkg/glassnode/glassnodeapi/institutions.go index fece291fb..671c05459 100644 --- a/pkg/glassnode/institutions.go +++ b/pkg/glassnode/glassnodeapi/institutions.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/institutions_request_requestgen.go b/pkg/glassnode/glassnodeapi/institutions_request_requestgen.go similarity index 99% rename from pkg/glassnode/institutions_request_requestgen.go rename to pkg/glassnode/glassnodeapi/institutions_request_requestgen.go index acc40a4b9..b5ef3ff2b 100644 --- a/pkg/glassnode/institutions_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/institutions_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/lightning.go b/pkg/glassnode/glassnodeapi/lightning.go similarity index 96% rename from pkg/glassnode/lightning.go rename to pkg/glassnode/glassnodeapi/lightning.go index 8ab82cb36..d8040db5e 100644 --- a/pkg/glassnode/lightning.go +++ b/pkg/glassnode/glassnodeapi/lightning.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/lightning_request_requestgen.go b/pkg/glassnode/glassnodeapi/lightning_request_requestgen.go similarity index 99% rename from pkg/glassnode/lightning_request_requestgen.go rename to pkg/glassnode/glassnodeapi/lightning_request_requestgen.go index e3103de89..961866226 100644 --- a/pkg/glassnode/lightning_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/lightning_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/market.go b/pkg/glassnode/glassnodeapi/market.go similarity index 96% rename from pkg/glassnode/market.go rename to pkg/glassnode/glassnodeapi/market.go index ce9939916..aeefd0d38 100644 --- a/pkg/glassnode/market.go +++ b/pkg/glassnode/glassnodeapi/market.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/market_request_requestgen.go b/pkg/glassnode/glassnodeapi/market_request_requestgen.go similarity index 99% rename from pkg/glassnode/market_request_requestgen.go rename to pkg/glassnode/glassnodeapi/market_request_requestgen.go index 33896ccc1..da35ff3d8 100644 --- a/pkg/glassnode/market_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/market_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/mempool.go b/pkg/glassnode/glassnodeapi/mempool.go similarity index 96% rename from pkg/glassnode/mempool.go rename to pkg/glassnode/glassnodeapi/mempool.go index 27cd4e744..059c1c67b 100644 --- a/pkg/glassnode/mempool.go +++ b/pkg/glassnode/glassnodeapi/mempool.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/mempool_request_requestgen.go b/pkg/glassnode/glassnodeapi/mempool_request_requestgen.go similarity index 99% rename from pkg/glassnode/mempool_request_requestgen.go rename to pkg/glassnode/glassnodeapi/mempool_request_requestgen.go index 8c0f0ff8a..1b49b93f8 100644 --- a/pkg/glassnode/mempool_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/mempool_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/mining.go b/pkg/glassnode/glassnodeapi/mining.go similarity index 96% rename from pkg/glassnode/mining.go rename to pkg/glassnode/glassnodeapi/mining.go index 3a72925dd..44cda95a1 100644 --- a/pkg/glassnode/mining.go +++ b/pkg/glassnode/glassnodeapi/mining.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/mining_request_requestgen.go b/pkg/glassnode/glassnodeapi/mining_request_requestgen.go similarity index 99% rename from pkg/glassnode/mining_request_requestgen.go rename to pkg/glassnode/glassnodeapi/mining_request_requestgen.go index 8243d4d9f..b448ba87d 100644 --- a/pkg/glassnode/mining_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/mining_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/protocols.go b/pkg/glassnode/glassnodeapi/protocols.go similarity index 96% rename from pkg/glassnode/protocols.go rename to pkg/glassnode/glassnodeapi/protocols.go index e111a88a6..3a0e62a0a 100644 --- a/pkg/glassnode/protocols.go +++ b/pkg/glassnode/glassnodeapi/protocols.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/protocols_request_requestgen.go b/pkg/glassnode/glassnodeapi/protocols_request_requestgen.go similarity index 99% rename from pkg/glassnode/protocols_request_requestgen.go rename to pkg/glassnode/glassnodeapi/protocols_request_requestgen.go index 29bf603dc..2b8fb6b0d 100644 --- a/pkg/glassnode/protocols_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/protocols_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/supply.go b/pkg/glassnode/glassnodeapi/supply.go similarity index 96% rename from pkg/glassnode/supply.go rename to pkg/glassnode/glassnodeapi/supply.go index a6ff4c957..542f03b23 100644 --- a/pkg/glassnode/supply.go +++ b/pkg/glassnode/glassnodeapi/supply.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/supply_request_requestgen.go b/pkg/glassnode/glassnodeapi/supply_request_requestgen.go similarity index 99% rename from pkg/glassnode/supply_request_requestgen.go rename to pkg/glassnode/glassnodeapi/supply_request_requestgen.go index 3d766d060..2577d7da1 100644 --- a/pkg/glassnode/supply_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/supply_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/transactions.go b/pkg/glassnode/glassnodeapi/transactions.go similarity index 96% rename from pkg/glassnode/transactions.go rename to pkg/glassnode/glassnodeapi/transactions.go index de5283ab4..57e22412f 100644 --- a/pkg/glassnode/transactions.go +++ b/pkg/glassnode/glassnodeapi/transactions.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import "github.com/c9s/requestgen" diff --git a/pkg/glassnode/transactions_request_requestgen.go b/pkg/glassnode/glassnodeapi/transactions_request_requestgen.go similarity index 99% rename from pkg/glassnode/transactions_request_requestgen.go rename to pkg/glassnode/glassnodeapi/transactions_request_requestgen.go index dda52ceca..7ebcd983b 100644 --- a/pkg/glassnode/transactions_request_requestgen.go +++ b/pkg/glassnode/glassnodeapi/transactions_request_requestgen.go @@ -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" diff --git a/pkg/glassnode/types.go b/pkg/glassnode/glassnodeapi/types.go similarity index 98% rename from pkg/glassnode/types.go rename to pkg/glassnode/glassnodeapi/types.go index 28560eece..0d055e990 100644 --- a/pkg/glassnode/types.go +++ b/pkg/glassnode/glassnodeapi/types.go @@ -1,4 +1,4 @@ -package glassnode +package glassnodeapi import ( "encoding/json"