Quickstart

The Monitor WebSocket enables you to stream both on-chain and off-chain data. On-chain data (trade, creation, migration) are pre-parsed, ready for immediate use, and accessible through a variety of available endpoints.

If you have suggestions for new endpoints, feel free to reach out to our development team via our Telegram chat. Thank you for your contributions to the project!

Connection

No API key is required to use our WebSocket connection. It is free to use, and we do not have any hidden costs.

Once you are connected, you can explore our On/Off-Chain Data section to send messages to our server. You can also establish a connection by sending a message directly.

To maintain a stable connection, it's important to send a ping request every 8 minutes. The server allows a maximum duration of 10 minutes without a ping request from the client. This can be easily managed by using a keep-alive function when opening the WebSocket connection.

wss://api.monitor.ws/connect

package main

import (
	"log"
	"log/slog"
	"time"

	"github.com/fatih/color"
	"github.com/gorilla/websocket"
)

type Payload struct {
	Event   string   `json:"event"`
	Content []string `json:"content"`
}

const (
	url = "wss://api.monitor.ws/connect"
)

func main() {

	/* Connecting to the monitorws server */
	conn, _, err := websocket.DefaultDialer.Dial(url, nil)
	if err != nil {
		log.Fatalf("connecting to monitorws: %v", err)
	}
	defer conn.Close()

	/* Sending event payload */
	if err := conn.WriteJSON(Payload{
		/* Refer to docs.monitor.ws/websocket */
		Event: "<YOUR_EVENT>",
		Content: []string{
			"", /* This field can be empty if you don't want to set any filters; however, it does not work with all events. */
		},
	}); err != nil {
		log.Fatalf("writing event to monitorws: %v", err)
	}

	/*
		Send a ping message every 8 minutes to keep the connection alive
	*/
	go func() {
		for {
			time.Sleep(8 * time.Minute)
			if err := conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(10*time.Second)); err != nil {
				slog.Error("sending ping to monitorws", "err", err)
				continue
			}
			color.Magenta("[ %s ] > Ping sent to monitorws", time.Now().Format("15:04:05"))
		}
	}()

	/*
		Infinite loop to listen for events from the server.
	*/
	for {

		/* Reading the message received from the server */
		_, message, err := conn.ReadMessage()
		if err != nil {
			slog.Error("reading event from monitorws", "err", err)
			continue
		}

		color.Cyan("[ %s ] > %s", time.Now().Format("15:04:05"), string(message))
	}
}

Dev Support

If you encounter any difficulties integrating the WebSocket connection into your script, our development team is here to assist. Feel free to join our Telegram community, where you can ask questions, and receive support directly from the team and other developers.

Last updated