opensea

package module
v0.0.0-...-d110ae4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

opensea-go

Golang's library for OpenSea APIs (https://docs.opensea.io/reference).

Get Started

Get it
go get -u github.com/casiphia/opensea-go
Use it
package main

import (
	"context"
	"github.com/casiphia/opensea-go"
	"log"
)

func main() {
	var cli = opensea.New(opensea.WithTestNets(true))
	var asset, err = cli.Asset(context.Background(), &opensea.AssetRequest{
		AssetContractAddress: "0x66583bd73a27c9245b723ff6a58f872234c3a50a",
		TokenID:              "3",
	})
	if err != nil {
		log.Fatalln(err)
		return
	}
	log.Println(asset)
}

Documentation

Overview

* @Descripttion: X-club project * @Version: 1.0.0 * @Author: wangxiaodiao * @Email: 413586280@qq.com * @Date: 2023-02-07 15:28:29 * @LastEditors: wangxiaodiao * @LastEditTime: 2023-02-07 15:28:38 * @FilePath: /opensea-go/stream_types.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("resource.not.found")
	ErrTooManyRequests = errors.New("too.many.requests")
	ErrInternalServer  = errors.New("internal.server.error")
)

Functions

func ParseRsp

func ParseRsp(rsp restgo.IResponse, i interface{}) error

func WrapperCountContext

func WrapperCountContext(ctx context.Context, count int) context.Context

Types

type AssetRequest

type AssetRequest struct {
	// The NFT contract address for the assets
	AssetContractAddress string `path:"asset_contract_address,required"`
	// Address of the contract for this NFT
	TokenID string `path:"token_id,required"`
	// Address of an owner of the token.
	// If you include this, the response will include an ownership object that includes
	// the number of tokens owned by the address provided instead of the top_ownerships object
	// included in the standard response, which provides the number of tokens owned by each of
	// the 10 addresses with the greatest supply of the token.
	AccountAddress string `query:"account_address"`
	// A flag determining if order information should be included in the response. The default value of this flag is false.
	IncludeOrders bool `query:"include_orders"`
}

type AssetValidateRequest

type AssetValidateRequest struct {
	// The NFT contract address for the assets
	AssetContractAddress string `path:"asset_contract_address,required"`
	// Address of the contract for this NFT
	TokenID string `path:"token_id,required"`
	// Address of an owner of the token.
	// If you include this, the response will include an ownership object that includes
	// the number of tokens owned by the address provided instead of the top_ownerships object
	// included in the standard response, which provides the number of tokens owned by each of
	// the 10 addresses with the greatest supply of the token.
	Validate string `path:"validate,required"`
}

type AssetValidateResponse

type AssetValidateResponse struct {
	Valid    bool        `opensea:"valid" json:"valid"`
	TokenUri string      `opensea:"token_uri" json:"tokenUri"`
	Errors   interface{} `opensea:"errors" json:"errors"`
}

type AssetsRequest

type AssetsRequest struct {
	// The address of the owner of the assets
	Owner string `query:"owner"`
	// An array of token IDs to search for (e.g. ?token_ids=1&token_ids=209).
	// Will return a list of assets with token_id matching any of the IDs in this array.
	TokenIDs []string `query:"token_ids"`
	// The NFT contract address for the assets
	AssetContractAddress string `query:"asset_contract_address"`
	// An array of contract addresses to search for (e.g. ?asset_contract_addresses=0x1...&asset_contract_addresses=0x2...).
	// Will return a list of assets with contracts matching any of the addresses in this array.
	// If "token_ids" is also specified, then it will only return assets that match each (address, token_id) pairing, respecting order.
	AssetContractAddresses []string `query:"asset_contract_addresses"`
	// How to order the assets returned. By default, the API returns the fastest ordering.
	// Options you can set are sale_date (the last sale's transaction's timestamp),
	// sale_count (number of sales), and sale_price (the last sale's total_price)
	OrderBy string `query:"order_by"`
	// Can be asc for ascending or desc for descending
	OrderDirection string `query:"order_direction,required"`
	// Offset
	Offset int32 `query:"offset"`
	// Limit
	Limit int32 `query:"limit,required"`

	//Cursor A cursor pointing to the page to retrieve
	Cursor string `query:"cursor"`

	// Limit responses to members of a collection.
	// Case-sensitive and must match the collection slug exactly.
	// Will return all assets from all contracts in a collection.
	// For more information on collections, see our collections documentation.
	Collection string `query:"collection"`

	// Limit responses to members of a collection.
	// Case sensitive and must match the collection slug exactly.
	// Will return all assets from all contracts in a collection.
	// For more information on collections,
	CollectionSlug string `query:"collection_slug"`

	// CollectionEditor
	CollectionEditor string `query:"collection_editor"`

	// A flag determining if order information should be included in the response.
	IncludeOrders bool `query:"include_orders"`
}

type AssetsResponse

type AssetsResponse struct {
	Assets   []*model.Asset `opensea:"assets"`
	Next     string         `opensea:"next"`
	Previous string         `opensea:"previous"`
}

type BundlesRequest

type BundlesRequest struct {
	// If set to true, only show bundles currently on sale.
	// If set to false, only show bundles that have been sold or cancelled.
	OnSale bool `json:"on_sale"`
	// The address of the owner of the assets
	Owner string `query:"owner"`
	// The NFT contract address for the assets
	AssetContractAddress string `query:"asset_contract_address"`
	// An array of contract addresses to search for (e.g. ?asset_contract_addresses=0x1...&asset_contract_addresses=0x2...).
	// Will return a list of assets with contracts matching any of the addresses in this array.
	// If "token_ids" is also specified, then it will only return assets that match each (address, token_id) pairing, respecting order.
	AssetContractAddresses []string `query:"asset_contract_addresses"`
	// An array of token IDs to search for (e.g. ?token_ids=1&token_ids=209).
	// Will return a list of assets with token_id matching any of the IDs in this array.
	TokenIDs []string `query:"token_ids"`
	// Limit
	Limit int32 `query:"limit,required"`
	// Offset
	Offset int32 `query:"offset,required"`
}

type BundlesResponse

type BundlesResponse struct {
	Bundles []*model.Bundle `opensea:"bundles"`
}

type Client

type Client struct {
	*restgo.Client
	// contains filtered or unexported fields
}

func New

func New(fnList ...OptionFn) *Client

func (*Client) Asset

func (c *Client) Asset(ctx context.Context, req *AssetRequest) (*model.Asset, error)

Asset Used to fetch more in-depth information about an individual asset

func (*Client) AssetValidate

func (c *Client) AssetValidate(ctx context.Context, req *AssetValidateRequest) (*AssetValidateResponse, error)

This endpoint is used to check the metadata URL on a given NFT.

func (*Client) Assets

func (c *Client) Assets(ctx context.Context, req *AssetsRequest) (*AssetsResponse, error)

Assets To retrieve assets from our API, call the /assets endpoint with the desired filter parameters.

func (*Client) Bundles

func (c *Client) Bundles(ctx context.Context, req *BundlesRequest) ([]*model.Bundle, error)

Bundles are groups of items for sale on OpenSea. You can buy them all at once in one transaction, and you can create them without any transactions or gas, as long as you've already approved the assets inside.

func (*Client) Collection

func (c *Client) Collection(ctx context.Context, req *CollectionRequest) (*model.Collection, error)

Collection Used for retrieving more in-depth information about individual collections, including real time statistics like floor price

func (*Client) CollectionStats

func (c *Client) CollectionStats(ctx context.Context, req *CollectionRequest) (*model.CollectionStats, error)

CollectionStats Use this endpoint to fetch stats for a specific collection, including realtime floor price statistics

func (*Client) Collections

func (c *Client) Collections(ctx context.Context, req *CollectionsRequest) ([]*model.Collection, error)

Collections Use this endpoint to fetch collections on OpenSea

func (*Client) Contract

func (c *Client) Contract(ctx context.Context, req *ContractRequest) (*model.Contract, error)

Contract Used to fetch more in-depth information about an contract asset

func (*Client) Events

func (c *Client) Events(ctx context.Context, req *EventsRequest) (*EventsResponse, error)

Events The /events endpoint provides a list of events that occur on the assets that OpenSea tracks. The "event_type" field indicates what type of event it is (transfer, successful auction, etc).

func (*Client) OrdersCreateListings

func (c *Client) OrdersCreateListings(ctx context.Context, req *OrderCreateResponse) (*OrderResponse, error)

This endpoint is used to fetch the set of active listings on a given NFT for the Seaport contract.

func (*Client) OrdersCreateOffers

func (c *Client) OrdersCreateOffers(ctx context.Context, req *OrderCreateResponse) (*OrderCreateResponse, error)

This endpoint is used to fetch the set of active offers on a given NFT for the Seaport contract.

func (*Client) OrdersListings

func (c *Client) OrdersListings(ctx context.Context, req *OrdersRequest) (*OrderResponse, error)

This endpoint is used to fetch the set of active listings on a given NFT for the Seaport contract.

func (*Client) OrdersOffers

func (c *Client) OrdersOffers(ctx context.Context, req *OrdersRequest) (*OrderResponse, error)

This endpoint is used to fetch the set of active offers on a given NFT for the Seaport contract.

func (*Client) Owners

func (c *Client) Owners(ctx context.Context, req *OwnersRequest) (*OwnersResponse, error)

This endpoint is used to obtain the entire list of owners for an NFT. Results will also include the quantity owned.

type CollectionRequest

type CollectionRequest struct {
	CollectionSlug string `path:"collection_slug,required"`
}

type CollectionResponse

type CollectionResponse struct {
	Collection *model.Collection `opensea:"collection"`
}

type CollectionStatsResponse

type CollectionStatsResponse struct {
	Stats *model.CollectionStats `opensea:"stats"`
}

type CollectionsRequest

type CollectionsRequest struct {
	// A wallet address. If specified, will return collections where the owner owns at least one asset belonging to smart contracts in the collection.
	// The number of assets the account owns is shown as owned_asset_count for each collection.
	AssetOwner string `query:"asset_owner"`
	// Offset
	Offset int32 `query:"offset,required"`
	// Limit
	Limit int32 `query:"limit,required"`
}

type CollectionsResponse

type CollectionsResponse struct {
	Collections []*model.Collection `opensea:"collections"`
}

type ContractRequest

type ContractRequest struct {
	// Address of the contract
	AssetContractAddress string `path:"asset_contract_address,required"`
}

type EventType

type EventType string
const (
	ItemMetadataUpdated EventType = "item_metadata_updated"
	ItemListed          EventType = "item_listed"
	ItemSold            EventType = "item_sold"
	ItemTransferred     EventType = "item_transferred"
	ItemReceivedOffer   EventType = "item_received_offer"
	ItemReceivedBid     EventType = "item_received_bid"
	ItemCancelled       EventType = "item_cancelled"
)

type EventsRequest

type EventsRequest struct {
	// Restrict to events on OpenSea auctions. Can be true or false
	OnlyOpensea bool `query:"only_opensea"`
	// The token's id to optionally filter by
	TokenID string `query:"token_id"`
	// The NFT contract address for the assets
	AssetContractAddress string `query:"asset_contract_address"`
	// Limit responses to events from a collection. Case sensitive and must match the collection slug exactly.
	// Will return all assets from all contracts in a collection.
	// For more information on collections, see our collections documentation.
	CollectionSlug   string `query:"collection_slug"`
	CollectionEditor string `query:"collection_editor"`
	// A user account's wallet address to filter for events on an account
	AccountAddress string `query:"account_address"`
	// The event type to filter.
	EventType model.EventType `query:"event_type"`
	// Filter by an auction type.
	AuctionType model.AuctionType `query:"auction_type"`
	// Only show events listed before this timestamp. Seconds since the Unix epoch.
	// eg: 2017-07-21T17:32:28Z
	OccurredBefore string `query:"occurred_before"`
	// Only show events listed after this timestamp. Seconds since the Unix epoch.
	// eg: 2017-07-21T17:32:28Z
	OccurredAfter string `query:"occurred_after"`
	// A cursor pointing to the page to retrieve
	Cursor string `query:"cursor"`
}

type EventsResponse

type EventsResponse struct {
	// List of Event Object
	AssetEvents []*model.Event `opensea:"asset_events"`
	// A cursor to be supplied as a query param to retrieve the next page
	Next string `opensea:"next"`
	// A cursor to be supplied as a query param to retrieve the previous page
	Previous string `opensea:"previous"`
}

type Network

type Network string
const (
	MAINNET Network = "mainnet"
	TESTNET Network = "testnet"
)

type OptionFn

type OptionFn func(*option)

func WithAPIKey

func WithAPIKey(apiKey string) OptionFn

func WithRetryWhenFreqLimit

func WithRetryWhenFreqLimit(interval time.Duration, count int) OptionFn

func WithTestNets

func WithTestNets(test bool) OptionFn

type OrderCreateResponse

type OrderCreateResponse struct {
	Orders   []*model.Order `opensea:"owners"`
	Next     string         `opensea:"next"`
	Previous string         `opensea:"previous"`
}

type OrderResponse

type OrderResponse struct {
	Orders   []*model.Order `opensea:"owners"`
	Next     string         `opensea:"next"`
	Previous string         `opensea:"previous"`
}

type OrdersCreateRequest

type OrdersCreateRequest struct {
	// Specify the chain you would like to retrieve listings on. The options are "arbitrum", "avalanche", "ethereum", "klaytn", "matic" and "optimism".
	Chain string `path:"chain,required"`
	// Represents the details of the listing to be posted to Seaport. Refer to Orders Parameter Model for more details.
	OrderParameters *model.Protocol `form:"order_parameters,required"`
	Signature       string          `form:"signature,required"`
}

type OrdersRequest

type OrdersRequest struct {
	// Specify the chain you would like to retrieve listings on. The options are "arbitrum", "avalanche", "ethereum", "klaytn", "matic" and "optimism".
	Chain string `path:"chain,required"`
	// Address of the contract for an NFT
	AssetContractAddress string `query:"asset_contract_address"`
	// Number of listings to retrieve
	Limit string `query:"limit,required"`
	// Filter by a list of token IDs for the order's asset.
	// Needs to be defined together with asset_contract_address.
	TokenIDs []string `query:"token_ids"`
	// Filter by the order maker's wallet address
	Maker string `query:"maker"`
	// Filter by the order taker's wallet address.
	// Orders open for any taker have the null address as their taker.
	Taker string `query:"taker"`
	// How to sort the orders. Can be created_date for when they were made,
	// or eth_price to see the lowest-priced orders first (converted to their ETH values).
	// eth_price is only supported when asset_contract_address and token_id are also defined.
	OrderBy string `query:"order_by"`
	// Can be asc or desc for ascending or descending sort.
	// For example, to see the cheapest orders, do order_direction asc and order_by eth_price.
	OrderDirection string `query:"order_direction,required"`
	// Only show orders listed after this timestamp. Seconds since the Unix epoch.
	// eg: 2017-07-21T17:32:28Z
	ListedAfter string `query:"listed_after"`
	// Only show orders listed before this timestamp. Seconds since the Unix epoch.
	// eg: 2017-07-21T17:32:28Z
	ListedBefore string `query:"listed_before"`
}

type OwnersRequest

type OwnersRequest struct {
	// Address of the contract for this NFT
	AssetContractAddress string `path:"asset_contract_address,required"`
	// Address of the contract for this NFT
	TokenID string `path:"token_id,required"`
	// How many results to show. The default value is 20 (if param is omitted), max is 50.
	Limit string `query:"limit,required"`
	// What field to order by. For now, we only support created_date.
	OrderBy string `query:"order_by"`
	// asc or desc. Descending is the default.
	OrderDirection string `query:"order_direction"`
	// The cursor token. Used for going forward / backward to the next/previous pages.
	Cursor string `query:"cursor"`
}

type OwnersResponse

type OwnersResponse struct {
	Assets   []*model.Owner `opensea:"owners"`
	Next     string         `opensea:"next"`
	Previous string         `opensea:"previous"`
}

type StreamClient

type StreamClient struct {
	// contains filtered or unexported fields
}

func NewStreamClient

func NewStreamClient(network Network, token string, onError func(error)) *StreamClient

func (StreamClient) Connect

func (s StreamClient) Connect() error

func (*StreamClient) Disconnect

func (s *StreamClient) Disconnect() error

func (StreamClient) OnItemCancelled

func (s StreamClient) OnItemCancelled(collectionSlug string, Callback func(itemCancelledEvent any)) func()

func (StreamClient) OnItemListed

func (s StreamClient) OnItemListed(collectionSlug string, Callback func(itemListedEvent any)) func()

func (StreamClient) OnItemMetadataUpdated

func (s StreamClient) OnItemMetadataUpdated(collectionSlug string, Callback func(itemMetadataUpdatedEvent any)) func()

func (StreamClient) OnItemReceivedBid

func (s StreamClient) OnItemReceivedBid(collectionSlug string, Callback func(itemReceivedBidEvent any)) func()

func (StreamClient) OnItemReceivedOffer

func (s StreamClient) OnItemReceivedOffer(collectionSlug string, Callback func(itemReceivedOfferEvent any)) func()

func (StreamClient) OnItemSold

func (s StreamClient) OnItemSold(collectionSlug string, Callback func(itemSoldEvent any)) func()

func (StreamClient) OnItemTransferred

func (s StreamClient) OnItemTransferred(collectionSlug string, Callback func(itemTransferredEvent any)) func()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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