Websocket Feeds

The Instamint websocket allows STOMP clients to subscribe to feeds that provide notification of events. The websocket is accessible via http://ws.instamint.network subscribe to /feed/kafka.
Please note that websocket channel names are subject to change
Currently the events that are supported include:
Event
Fires when..
Mint
An asset is attempted to minted, when minting is successful or fails
Auction
An auction is created, closed or when a bid arrives or ask is adjusted
Trade
An asset is sold at an auction
Transfer
An asset is transferred
Websocket messages confirming minting and creation of an auction
The below Python code establishes a STOMP-based websocket client that listens to events and prints them to the terminal
1
import websocket
2
import stomper
3
import time
4
from threading import Thread
5
6
class Client:
7
def connect(self):
8
self.ws = websocket.WebSocketApp("ws://ws.instamint.network/ws",
9
on_message = self.on_msg,
10
on_error = self.on_error,
11
on_close = self.on_closed,
12
on_open = self.on_open)
13
self.ws.run_forever()
14
15
def on_open(self, ws):
16
self.ws.send("CONNECT\naccept-version:1.0,1.1,2.0\n\n\x00\n")
17
self.ws.send(stomper.subscribe("/feeds/kafka", "sub3", ack="auto"))
18
19
20
def on_msg(self, ws, msg):
21
frame = stomper.Frame()
22
unpacked_msg = stomper.Frame.unpack(frame, msg)
23
print("Received the message: " + str(unpacked_msg['body']))
24
25
def on_closed(self, ws):
26
print("The websocket connection is closed.")
27
28
def on_error(self, ws, err):
29
print(err)
30
31
def send(self, feed, msg):
32
f = stomper.Frame()
33
f.unpack(stomper.send(feed, msg))
34
frame = f.pack()
35
self.ws.send(frame)
36
37
client = Client()
38
thread = Thread(target=client.connect, daemon=True)
39
thread.start()