Package: opensea-stream
OpenSea Stream API - python SDKA python SDK for receiving updates from the OpenSea Stream API - pushed over websockets. We currently support the following event types on a per-collection basis:Item ListedItem SoldItem TransferredItem Metadata updatesItem CancelledItem Received offerItem Received bidDocumentation:https://docs.opensea.io/reference/stream-api-overviewInstallationThis module requires Python 3 or later.Python 3pip install opensea_sdkGetting StartedAuthenticationIn order to make onboarding easy, we've integrated the OpenSea Stream API with our existing API key system. The API keys you have been using for the REST API should work here as well. If you don't already have one, request an API key from ushere.Simple examplefromopensea_sdkimport*api_key=''# Your opensea api keydefcallback(payload:dict):# handle eventreturnClient=OpenseaStreamClient(api_key,Network.MAINNET)Client.onItemListed('collection-slug',callback)Client.onItemSold('collection-slug',callback)Client.startListening()You can also optionally pass in:anetworkif you would like to access testnet networks.The default value isNetwork.MAINNET, which represents the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnetCan also selectNetwork.TESTNET, which represents the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).Available NetworksThe OpenSea Stream API is available on the following networks:Mainnetwss://stream.openseabeta.com/socketMainnet support events from the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet.Testnetwss://testnets-stream.openseabeta.com/socketTestnet support events from the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).To create testnet instance of the client, you can create it with the following arguments:fromopensea_sdkimport*api_key=''# Opensea api keydefcallback(payload:dict):# handle eventreturnClient=OpenseaStreamClient(api_key,Network.TESTNET)Manually connecting to the socket (optional)The client will automatically connect to the socket as soon as you subscribe to the first channel.
If you would like to connect to the socket manually (before that), you can do so:Client.connect()After successfully connecting to our websocket it is time to listen to specific events you're interested in!Streaming metadata updatesWe will only send out metadata updates when we detect that the metadata provided intokenURIhas changed from what OpenSea has previously cached.Client.onItemMetadataUpdated('collection-slug',callback)Streaming item listed eventsClient.onItemListed('collection-slug',callback)Streaming item sold eventsClient.onItemSold('collection-slug',callback)Streaming item transferred eventsClient.onItemTransferred('collection-slug',callback)Streaming bids and offersClient.onItemReceivedBid('collection-slug',callback)Client.onItemReceivedOffer('collection-slug',callback)Streaming order cancellation eventsClient.onItemCancelled('collection-slug',callback)Streaming multiple event types and multiple collectionsClient.onEvents(['collection-slug','collection_slug'][EventTypes.ITEM_RECEIVED_OFFER,EventTypes.ITEM_TRANSFERRED],callback)Subscribing to events from all collectionsIf you'd like to listen to an event from all collections use wildcard*for theslugparameter.TypesTypes are included to make working with our event payload objects easier.WebhookYou might want to use our predefined but fully Customizable discord webhook managementfromopensea_sdkimport*fromdiscord_webhookimportDiscordWebhookwebhook=DiscordWebhook(url='')# Webhook Urlapi_key=''# Opensea api keyClient=OpenseaStreamClient(api_key,Network.MAINNET)Client.onItemListed('collection-slug',Webhook(webhook).send)Client.startListening()You can change the color, the footer and the thumbnail of the webhook with the following arguments:fromopensea_sdkimport*fromdiscord_webhookimportDiscordWebhookwebhook=DiscordWebhook(url='')# Webhook Urlapi_key=''# Opensea api keycustom_footer='My custom footer'custom_thumbnail=''# Image urlcolor_=''# Hexadecimal color e.g ff0000 (red)Client=OpenseaStreamClient(api_key,Network.MAINNET)Client.onItemListed('collection-slug',Webhook(webhook,color=color_,thumbnail=custom_thumbnail,footer=custom_footer).send)Client.startListening()