goopensea

package module
v0.0.0-...-51c194e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 7 Imported by: 0

README

go-opensea

Go (golang) Wrapper for the OpenSea API https://docs.opensea.io/reference/api-overview

Installation

If using Go modules (Go version >= 11.1) simply import as needed.

go mod init github.com/yourusername/yourprojectname
Older Go versions
go get github.com/rbbrown1/go-opensea

Getting started

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	goopensea "github.com/rbbrown1/go-opensea"
)

// get NFTs for a wallet address
func main() {
	ctx, cancel := context.WithTimeout(
		context.Background(),
		time.Duration(time.Second*10))
	defer cancel()

	// create opensea client object
	client := goopensea.NewClient(ctx)

    // create parameter object
	params := goopensea.GetAssetsParams{
		Owner: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
		Limit: 1}

    // execute the api call
	assets, err := client.GetAssets(params)
	if err != nil {
		log.Fatalf("Error getting multiple assets: %v", err)
	}

	fmt.Printf("%+v", assets)
}

Testing

go test

Documentation

Documentation coming soon :)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address       string      `json:"address"`
	ProfileImgUrl string      `json:"profile_img_url"`
	User          interface{} `json:"user"`
	Config        string      `json:"config"`
}

type Asset

type Asset struct {
	Id                      json.Number   `json:"id"`
	TokenId                 string        `json:"token_id"`
	NumSales                json.Number   `json:"num_sales"`
	ImageURL                string        `json:"image_url"`
	ImagePreviewUrl         string        `json:"image_preview_url"`
	ImageThumbnailUrl       string        `json:"image_thumbnail_url"`
	AnimationUrl            string        `json:"animation_url"`
	BackgroundColor         string        `json:"background_color"`
	Name                    string        `json:"name"`
	Description             string        `json:"description"`
	ExternalLink            string        `json:"external_link"`
	AssetContract           AssetContract `json:"asset_contract"`
	PermaLink               string        `json:"permalink"`
	Collection              Collection    `json:"collection"`
	Decimals                json.Number   `json:"decimals"`
	TokenMetaData           string        `json:"token_meta_data"`
	Owner                   Account       `json:"owner"`
	Creator                 Account       `json:"user"`
	Traits                  []Trait       `json:"traits"`
	LastSale                Sale          `json:"last_sale"`
	ListingDate             string        `json:"listing_date"`
	IsPresale               bool          `json:"is_presale"`
	TransferFeePaymentToken PaymentToken  `json:"transfer_fee_payment_token"`
	TransferFee             string        `json:"transfer_fee"`
	TopBid                  string        `json:"top_bid"`
	SupportsWyvern          bool          `json:"supports_wyvern"`
	TopOwnerships           []Ownership   `json:"top_ownerships"`
	Ownership               Ownership     `json:"ownership"`
}

type AssetContract

type AssetContract struct {
	Collection                  Collection `json:"collection"`
	Address                     string     `json:"address"`
	AddressContractType         string     `json:"asset_contract_type"`
	CreatedDate                 string     `json:"created_date"`
	Name                        string     `json:"name"`
	NftVersion                  string     `json:"nft_versiom"`
	OpenseaVersion              string     `json:"opensea_version"`
	Owner                       int        `json:"owner"`
	SchemaName                  string     `json:"schema_name"`
	Symbol                      string     `json:"symbol"`
	TotalSupply                 string     `json:"total_supply"`
	ImageURL                    string     `json:"image_url"`
	Description                 string     `json:"description"`
	ExternalLink                string     `json:"external_link"`
	DefaultToFiat               bool       `json:"default_to_fiat"`
	DevBuyerFeeBasisPoints      int        `json:"dev_buyer_fee_basis_points"`
	DevSellerFeeBasisPoints     int        `json:"dev_seller_fee_basis_points"`
	OnlyProxiedTransfers        bool       `json:"only_proxied_transfers"`
	OpenseaBuyerFeeBasisPoints  int        `json:"opensea_buyer_fee_basis_points"`
	OpenseaSellerFeeBasisPoints int        `json:"opensea_seller_fee_basis_points"`
	BuyerFeeBasisPoints         int        `json:"buyer_fee_basis_points"`
	SellerFeeBasisPoints        int        `json:"seller_fee_basis_points"`
	PayoutAddress               string     `json:"payout_address"`
}

type AssetEvent

type AssetEvent struct {
	ApprovedAccount    Account      `json:"approved_account"`
	Asset              Asset        `json:"asset"`
	AssetBundle        string       `json:"asset_bundle"`
	AuctionType        string       `json:"auction_type"`
	BidAmount          string       `json:"bid_amount"`
	CollectionSlug     string       `json:"collection_slug"`
	ContractAddress    string       `json:"contract_address"`
	CreatedDate        string       `json:"created_date"`
	CustomEventName    string       `json:"custom_event_name"`
	DevFeePaymentEvent string       `json:"dev_fee_payment_event"`
	Duration           string       `json:"duration"`
	EndingPrice        string       `json:"ending_price"`
	EventType          string       `json:"event_type"`
	FromAccount        Account      `json:"from_account"`
	Id                 json.Number  `json:"id"`
	IsPrivate          bool         `json:"is_private"`
	OwnerAccount       Account      `json:"owner_account"`
	PaymentToken       PaymentToken `json:"payment_token"`
	Quantity           string       `json:"quantity"`
	Seller             Account      `json:"seller"`
	StartingPrice      string       `json:"starting_price"`
	ToAccount          Account      `json:"to_account"`
	TotalPrice         string       `json:"total_price"`
	Transaction        Transaction  `json:"transaction"`
	WinnerAccount      Account      `json:"winner_account"`
}

type Assets

type Assets struct {
	Assets []Asset `json:"assets"`
}

type Bundle

type Bundle struct {
	Maker         Account       `json:"maker"`
	Slug          string        `json:"slug"`
	Assets        []Asset       `json:"assets"`
	Schemas       []string      `json:"schemas"`
	Name          string        `json:"name"`
	Description   string        `json:"description"`
	ExternalLink  string        `json:"external_link"`
	AssetContract AssetContract `json:"asset_contract"`
	PermaLink     string        `json:"perma_link"`
	SellOrders    []Order       `json:"sell_orders"`
}

type Bundles

type Bundles struct {
	Bundles []Bundle `json:"bundles"`
}

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	Ctx        context.Context
	RetryCount int
}

func NewClient

func NewClient(ctx context.Context) *Client

func (*Client) GetAsset

func (c *Client) GetAsset(params GetAssetParams) (Asset, error)

retrieve a single asset

func (*Client) GetAssets

func (c *Client) GetAssets(params GetAssetsParams) (Assets, error)

retrieve multiple assets, such as all NFTs owned by a wallet

func (*Client) GetBundles

func (c *Client) GetBundles(params GetBundlesParams) (Bundles, error)

func (*Client) GetCollection

func (c *Client) GetCollection(params GetCollectionParams) (Collections, error)

func (*Client) GetContract

func (c *Client) GetContract(asset_contract_address string) (AssetContract, error)

func (*Client) GetEvents

func (c *Client) GetEvents(params GetEventsParams) (Events, error)

func (*Client) GetOrders

func (c *Client) GetOrders(params GetOrdersParams) (Orders, error)

func (*Client) Request

func (c *Client) Request(method string, url string,
	queryParams interface{}, result interface{}) (res *http.Response, err error)

type Collection

type Collection struct {
	PrimaryAssetContracts       []AssetContract `json:"primary_asset_contracts"`
	Stats                       Stats           `json:"stats"`
	BannerImageUrl              string          `json:"banner_image_url"`
	ChatUrl                     string          `json:"chat_url"`
	CreatedDate                 string          `json:"created_date"`
	DefaultToFiat               bool            `json:"default_to_fiat"`
	Description                 string          `json:"description"`
	DevBuyerFeeBasisPoints      string          `json:"dev_buyer_fee_basis_points"`
	DevSellerFeeBasisPoints     string          `json:"dev_seller_fee_basis_points"`
	DiscordUrl                  string          `json:"discord_url"`
	DisplayData                 DisplayData     `json:"display_data"`
	ExternalUrl                 string          `json:"external_url"`
	Featured                    bool            `json:"featured"`
	FeaturedImageUrl            string          `json:"featured_image_url"`
	Hidden                      bool            `json:"hidden"`
	SafelistRequestStatus       string          `json:"safelist_request_status"`
	ImageURL                    string          `json:"image_url"`
	IsSubjectToWhitelist        bool            `json:"is_subject_to_whitelist"`
	LargeImageUrl               string          `json:"large_image_url"`
	MediumUsername              string          `json:"medium_username"`
	Name                        string          `json:"name"`
	OnlyProxiedTransfers        bool            `json:"only_proxied_transfers"`
	OpenseaBuyerFeeBasisPoints  string          `json:"opensea_buyer_fee_basis_points"`
	OpenseaSellerFeeBasisPoints string          `json:"opensea_seller_fee_basis_points"`
	PayoutAddress               string          `json:"payout_address"`
	RequireEmail                bool            `json:"require_email"`
	ShortDescription            string          `json:"short_description"`
	Slug                        string          `json:"slug"`
	TelegramUrl                 string          `json:"telegram_url"`
	TwitterUsername             string          `json:"twitter_username"`
	InstagramUsername           string          `json:"instagram_username"`
	WikiUrl                     string          `json:"wiki_url"`
	OwnedAssetsCount            json.Number     `json:"owned_asset_count"`
	PaymentTokens               []PaymentToken  `json:"payment_tokens"`
	Traits                      interface{}     `json:"traits"`
}

type Collections

type Collections struct {
	Collections []Collection `json:"collections"`
}

type DisplayData

type DisplayData struct {
	CardDisplayStyle string `json:"card_display_style"`
}

type Events

type Events struct {
	AssetEvents []AssetEvent `json:"asset_events"`
}

type GetAssetParams

type GetAssetParams struct {
	TokenId              string `url:"token_id,omitempty" binding:"required"`
	AssetContractAddress string `url:"asset_contract_address,omitempty" binding:"required"`
}

type GetAssetsParams

type GetAssetsParams struct {
	Owner                  string   `url:"owner,omitempty"`
	TokenIds               []string `url:"token_ids,omitempty"`
	AssetContractAddress   string   `url:"asset_contract_address,omitempty"`
	AssetContractAddresses []string `url:"asset_contract_addresses,omitempty"`
	OrderBy                string   `url:"order_by,omitempty"`
	OrderDirection         string   `url:"order_direction,omitempty"`
	Offset                 int      `url:"offset,omitempty"`
	Limit                  int      `url:"limit,omitempty"`
	Collection             string   `url:"collection,omitempty"`
}

type GetBundlesParams

type GetBundlesParams struct {
	OnSale                 bool   `url:"on_sale,omitempty"`
	Owner                  string `url:"owner,omitempty"`
	AssetContractAddress   string `url:"asset_contract_address,omitempty"`
	AssetContractAddresses string `url:"asset_contract_addresses,omitempty"`
	TokenIds               string `url:"token_ids,omitempty"`
	Offset                 int    `url:"offset,omitempty"`
	Limit                  int    `url:"limit,omitempty"`
}

type GetCollectionParams

type GetCollectionParams struct {
	AssetOwner string `url:"asset_owner,omitempty"`
	Offset     int    `url:"offset,omitempty"`
	Limit      int    `url:"limit,omitempty"`
}

type GetEventsParams

type GetEventsParams struct {
	AssetContractAddress string `url:"asset_contract_address,omitempty"`
	CollectionSlug       string `url:"collection_slug,omitempty"`
	TokenId              int    `url:"token_id,omitempty"`
	AccountAddress       string `url:"account_address,omitempty"`
	EventType            string `url:"event_type,omitempty"`
	OnlyOpensea          bool   `url:"only_opensea,omitempty"`
	AuctionType          string `url:"auction_type,omitempty"`
	Offset               int    `url:"offset,omitempty"`
	Limit                int    `url:"limit,omitempty"`
	OccuredBefore        string `url:"occurred_before,omitempty"`
	OccuredAfter         string `url:"occurred_after,omitempty"`
}

type GetOrdersParams

type GetOrdersParams struct {
	AssetContractAddress string   `url:"asset_contract_address,omitempty"`
	PaymentTokenAddress  string   `url:"payment_token_address,omitempty"`
	Maker                string   `url:"maker,omitempty"`
	Taker                string   `url:"taker,omitempty"`
	Owner                string   `url:"owner,omitempty"`
	IsEnglish            bool     `url:"is_english,omitempty"`
	Bundled              bool     `url:"bundled,omitempty"`
	IncludeBundled       bool     `url:"include_bundled,omitempty"`
	IncludeInvalid       bool     `url:"include_invalid,omitempty"`
	ListedAfter          string   `url:"listed_after,omitempty"`
	ListedBefore         string   `url:"listed_before,omitempty"`
	TokenId              string   `url:"token_id,omitempty"`
	TokenIds             []string `url:"token_ids,omitempty"`
	Side                 int      `url:"side,omitempty"`
	SaleKind             int      `url:"sale_kind,omitempty"`
	Limit                int      `url:"limit,omitempty"`
	Offset               int      `url:"offset,omitempty"`
	OrderBy              string   `url:"order_by,omitempty"`
	OrderDirection       string   `url:"order_direction,omitempty"`
}

type Order

type Order struct {
	Asset                Asset        `json:"asset"`
	AssetBundle          Bundle       `json:"asset_bundle"`
	CreatedDate          string       `json:"created_date"`
	ClosingDate          string       `json:"closing_date"`
	ClosingExtendable    bool         `json:"closing_extendable"`
	ExpirationTime       int          `json:"expiration_time"`
	ListingTime          int          `json:"listing_time"`
	OrderHash            string       `json:"order_hash"`
	Metadata             interface{}  `json:"metadata"`
	Exchange             string       `json:"exchange"`
	Maker                Account      `json:"maker"`
	Taker                Account      `json:"taker"`
	CurrentPrice         string       `json:"current_price"`
	CurrentBounty        string       `json:"current_bounty"`
	BountyMultiple       string       `json:"bounty_multiple"`
	MakerRelayerFee      string       `json:"maker_relayer_fee"`
	TakerRelayerFee      string       `json:"taker_relayer_fee"`
	MakerProtocolFee     string       `json:"maker_protocol_fee"`
	TakerProtocolFee     string       `json:"taker_protocol_fee"`
	MakerReferrerFee     string       `json:"maker_referrer_fee"`
	FeeRecipient         Account      `json:"fee_recipient"`
	FeeMethod            int          `json:"fee_method"`
	Side                 int          `json:"side"`
	SaleKind             int          `json:"sale_kind"`
	Target               string       `json:"target"`
	HowToCall            int          `json:"how_to_call"`
	CallData             string       `json:"calldata"`
	ReplacementPattern   string       `json:"replacement_pattern"`
	StaticTarget         string       `json:"static_target"`
	StaticExtradata      string       `json:"static_extradata"`
	PaymentToken         string       `json:"payment_token"`
	PaymentTokenContract PaymentToken `json:"payment_token_contract"`
	BasePrice            string       `json:"base_price"`
	Extra                string       `json:"extra"`
	Quantity             string       `json:"quantity"`
	Salt                 string       `json:"salt"`
	V                    int          `json:"v"`
	R                    string       `json:"r"`
	S                    string       `json:"s"`
	ApprovedOnChain      bool         `json:"approved_on_chain"`
	Cancelled            bool         `json:"cancelled"`
	Finalized            bool         `json:"finalized"`
	MarkedInvalid        bool         `json:"marked_invalid"`
	PrefixedHash         string       `json:"prefixed_hash"`
}

type Orders

type Orders struct {
	Count  int     `json:"count"`
	Orders []Order `json:"orders"`
}

type Ownership

type Ownership struct {
	Owner    Account     `json:"owner"`
	Quantity json.Number `json:"quantity"`
}

type PaymentToken

type PaymentToken struct {
	Id       json.Number `json:"id"`
	Symbol   string      `json:"symbol"`
	Address  string      `json:"address"`
	ImageUrl string      `json:"image_url"`
	Name     string      `json:"name"`
	Decimals json.Number `json:"decimals"`
	EthPrice json.Number `json:"eth_price"`
	UsdPrice json.Number `json:"usd_price"`
}

type Sale

type Sale struct {
	AssetBundle    string       `json:"asset_bundle"`
	EventType      string       `json:"event_type"`
	EventTimestamp string       `json:"event_timestamp"`
	AuctionType    string       `json:"auction_type"`
	TotalPrice     string       `json:"total_price"`
	PaymentToken   PaymentToken `json:"payment_token"`
	Transaction    Transaction  `json:"transaction"`
	CreatedDate    string       `json:"created_date"`
	Quantity       string       `json:"quantity"`
}

type Stats

type Stats struct {
	OneDayVolume          float64     `json:"one_day_volume"`
	OneDayChange          float64     `json:"one_day_change"`
	OneDaySales           json.Number `json:"one_day_sales"`
	OneDayAveragePrice    float64     `json:"one_day_average_price"`
	SevenDayVolume        float64     `json:"seven_day_volume"`
	SevenDayChange        float64     `json:"seven_day_change"`
	SevenDaySales         json.Number `json:"seven_day_sales"`
	SevenDayAverage       float64     `json:"seven_day_average_price"`
	ThirtyDayVolume       float64     `json:"thirty_day_volume"`
	ThirtyDayChange       float64     `json:"thirty_day_change"`
	ThirtyDaySales        json.Number `json:"thirty_day_sales"`
	ThirtyDayAveragePrice float64     `json:"thirty_day_average_price"`
	TotalVolume           float64     `json:"total_volume"`
	TotalSales            json.Number `json:"total_sales"`
	TotalSupplyCount      json.Number `json:"total_supply"`
	Count                 json.Number `json:"count"`
	NumOwners             json.Number `json:"num_owners"`
	AveragePrice          float64     `json:"average_price"`
	NumReports            json.Number `json:"num_reports"`
	MarketCap             float64     `json:"market_cap"`
	FloorPrice            float64     `json:"floor_price"`
}

type Trait

type Trait struct {
	TraitType   string      `json:"trait_type"`
	Value       interface{} `json:"value"`
	DisplayType string      `json:"display_type"`
	MaxValue    json.Number `json:"max_value"`
	TraitCount  json.Number `json:"trait_count"`
	Order       interface{} `json:"order"`
}

type Transaction

type Transaction struct {
	BlockHash        string      `json:"block_hash"`
	BlockNumber      string      `json:"block_number"`
	FromAccount      Account     `json:"from_account"`
	Id               json.Number `json:"id"`
	Timestamp        string      `json:"timestamp"`
	ToAccount        Account     `json:"to_account"`
	TransactionHash  string      `json:"transaction_hash"`
	TransactionIndex string      `json:"transaction_index"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL