WebSockets
WebSockets allow you to receive real-time notifications from the server.
Notifications supported:
| Name | Subscription code | Category | Type | Description |
|---|---|---|---|---|
| Event spawn | event_spawn | Events | Server | Send ActiveEventSchema when an event spawn. |
| Event removed | event_removed | Events | Server | Send ActiveEventSchema when an event expires and is removed. |
| Grand Exchange new sell order | grandexchange_sell_order | Grand Exchange | Server | Send GEOrderSchema when a sell order is created on the Grand Exchange |
| Grand Exchange new buy order | grandexchange_buy_order | Grand Exchange | Server | Send GEOrderSchema when a buy order is created on the Grand Exchange |
| Grand Exchange buy | grandexchange_buy | Grand Exchange | Server | Send GeOrderHistorySchema when a buy is completed (buyer purchases from a sell order) |
| Grand Exchange sell | grandexchange_sell | Grand Exchange | Server | Send GeOrderHistorySchema when a sale is completed (seller fills a buy order) |
| Pending Item Received | pending_item_received | Pending Items | Server | Send PendingItemSchema when an item is sent to the player’s pending items (from achievements, Grand Exchange purchases, etc.) |
| Online characters | online_characters | Characters | Server | Send array[ActiveCharacterSchema] at the connection and every 10 minutes with the list of online characters. |
| Version | version | Server | Server | Send the API server version at the connection and at every update. |
| Announcement | announcement | Announcements | Server | Sends {"message": "string"} when a new announcement is published. |
| Achievement unlock | achievement_unlocked | Achievements | Account | Send AchievementSchema when an achievement is unlocked on your account. |
| Account log | account_log | Logs | Account | Send LogSchema every time an action is performed on one of the characters in your account. |
| Test | test | Test | Test | Send Test message every 60 seconds. |
How does it work?
Section titled “How does it work?”The WebSocket server is: wss://realtime.artifactsmmo.com
Next, you need to include your token and the types of notifications you want to receive in the first message you send to the server.
message = { "token": token, "subscriptions": ["event_spawn", "event_removed", "grandexchange_neworder", "grandexchange_sell", "achievement_unlocked", "test"] }If you want to receive all notifications, you don’t need to include subscriptions.
Examples
Section titled “Examples”import asyncioimport websocketsimport json
url = "wss://realtime.artifactsmmo.com"token = "YOUR_TOKEN" # Replace with your token
message = { "token": token, "subscriptions": ["event_spawn", "event_removed", "grandexchange_neworder", "grandexchange_sell", "achievement_unlocked", "test"] }
async def receive_messages():
async with websockets.connect(url) as websocket: await websocket.send(json.dumps(message))
print("Connected to the WebSocket server") try: while True: # Waits for a message from the server message_received = await websocket.recv() message_received = json.loads(message_received)
print(f"Message received: {message_received}") except websockets.ConnectionClosed: print("Connection closed by the server")
# Start the WebSocket clientasyncio.run(receive_messages())const WebSocket = require('ws');
const url = "wss://realtime.artifactsmmo.com";const token = "YOUR_TOKEN"; // Replace with your token
const message = { token: token, subscriptions: ["event_new", "grandexchange_sell", "my_grandexchange_sell", "grandexchange_neworder"]};
async function receiveMessages() { const websocket = new WebSocket(url);
websocket.on('open', () => { websocket.send(JSON.stringify(message)); console.log("Connected to the WebSocket server"); });
websocket.on('message', (data) => { const messageReceived = JSON.parse(data); console.log("Message received:", messageReceived); });
websocket.on('close', () => { console.log("Connection closed by the server"); });
websocket.on('error', (error) => { console.error("WebSocket error:", error); });}
// Start the WebSocket clientreceiveMessages();<dependency> <groupId>org.java-websocket</groupId> <artifactId>Java-WebSocket</artifactId> <version>1.5.7</version></dependency>
public class WebSocketHandler extends WebSocketClient {
public WebSocketHandler(URI serverUri) { super(serverUri); }
@Override public void onOpen(ServerHandshake handshakedata) { String message = """ {"token": "%s", "subscriptions": ["event_spawn", "event_removed,"grandexchange_sell", "grandexchange_neworder", "achievement_unlocked"]}; """.formatted(TOKEN); send(message); System.out.println("Connected to WebSocket server"); }
@Override public void onMessage(String message) { System.out.println("Received message: " + message); }
@Override public void onClose(int code, String reason, boolean remote) { System.out.println("Disconnected from WebSocket server: " + reason); }
@Override public void onError(Exception ex) { System.err.println("WebSocket error: " + ex.getMessage()); }
public static void main(String[] args){ try { WebSocketHandler client = new WebSocketHandler(new URI("wss://realtime.artifactsmmo.com")); client.connectBlocking(); } catch (URISyntaxException | InterruptedException e) { e.printStackTrace(); } }}Server responses
Section titled “Server responses”Server messages always include notification type and data. Data is always the same schema returned by the API if possible.
Here’s an example of a server message:
{ 'type': 'grandexchange_neworder', 'data': {"id":"67337920ef441b2c7466d5e8","seller":"muigetsu","code":"copper_ore","quantity":1,"price":1,"created_at":"2024-11-12T15:49:52.343Z"}}