Socket
Book a DemoInstallSign in
Socket

@polymarket/real-time-data-client

Package Overview
Dependencies
Maintainers
12
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polymarket/real-time-data-client

A TypeScript client to receive real time data messages

latest
npmnpm
Version
1.4.0
Version published
Maintainers
12
Created
Source

Real time data client

This client provides a wrapper to connect to the real-time-data-streaming WebSocket service.

How to use it

Here is a quick example about how to connect to the service and start receiving messages (you can find more in the folder examples/):

import { RealTimeDataClient } from "../src/client";
import { Message } from "../src/model";

const onMessage = (message: Message): void => {
    console.log(message.topic, message.type, message.payload);
};

const onConnect = (client: RealTimeDataClient): void => {
    // Subscribe to a topic
    client.subscribe({
        subscriptions: [
            {
                topic: "comments",
                type: "*", // "*"" can be used to connect to all the types of the topic
                filters: `{"parentEntityID":100,"parentEntityType":"Event"}`, // empty means no filter
            },
        ],
    });
};

new RealTimeDataClient({ onMessage, onConnect }).connect();

How to subscribe and unsubscribe from messages

Once the connection is stablished and you have a client: RealTimeDataClient object, you can subscribe and unsubscribe to many messages streamings using the same connection.

Subscribe

Subscribe to 'trades' messages from the topic 'activity' and to the all comments messages.

client.subscribe({
    subscriptions: [
        {
            topic: "activity",
            type: "trades",
        },
    ],
});

client.subscribe({
    subscriptions: [
        {
            topic: "comments",
            type: "*", // "*"" can be used to connect to all the types of the topic
        },
    ],
});

Unsubscribe

Unsubscribe from the new trades messages of the topic 'activity'. If 'activity' has more messages types and I used '*' to connect to all of them, this will only unsubscribe from the type 'trades'.

client.subscribe({
    subscriptions: [
        {
            topic: "activity",
            type: "trades",
        },
    ],
});

Disconnect

The client object provides a method to disconnect from the WebSocket server:

client.disconnect();

Messages hierarchy

TopicTypeAuthFilters (if it is empty the messages won't be filtered)SchemaSubscription Handler
activitytrades-{"event_slug":"string"}' OR '{"market_slug":"string"}Trade
activityorders_matched-{"event_slug":"string"}' OR '{"market_slug":"string"}Trade
commentscomment_created-{"parentEntityID":number,"parentEntityType":"Event / Series"}Comment
commentscomment_removed-{"parentEntityID":number,"parentEntityType":"Event / Series"}Comment
commentsreaction_created-{"parentEntityID":number,"parentEntityType":"Event / Series"}Reaction
commentsreaction_removed-{"parentEntityID":number,"parentEntityType":"Event / Series"}Reaction
rfqrequest_created--Request
rfqrequest_edited--Request
rfqrequest_canceled--Request
rfqrequest_expired--Request
rfqquote_created--Quote
rfqquote_edited--Quote
rfqquote_canceled--Quote
rfqquote_expired--Quote
crypto_pricesupdate-{"symbol":string}CryptoPriceCryptoPriceHistorical
clob_userorderClobAuth-Order
clob_usertradeClobAuth-Trade
clob_marketprice_change-["100","200",...]PriceChanges
clob_marketagg_orderbook-["100","200",...]AggOrderbookAggOrderbook
clob_marketlast_trade_price-["100","200",...]LastTradePrice
clob_markettick_size_change-["100","200",...]TickSizeChange
clob_marketmarket_created--ClobMarket
clob_marketmarket_resolved--ClobMarket

Auth

ClobAuth

/**
 * API key credentials for CLOB authentication.
 */
export interface ClobApiKeyCreds {
    /** API key used for authentication */
    key: string;

    /** API secret associated with the key */
    secret: string;

    /** Passphrase required for authentication */
    passphrase: string;
}
client.subscribe({
    subscriptions: [
        {
            topic: "clob_user",
            type: "*",
            clob_auth: {
                key: "xxxxxx-xxxx-xxxxx-xxxx-xxxxxx",
                secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                passphrase: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            },
        },
    ],
});

Message types

Activity

Trade

NameTypeDescription
assetstringERC1155 token ID of conditional token being traded
biostringBio of the user of the trade
conditionIdstringId of market which is also the CTF condition ID
eventSlugstringSlug of the event
iconstringURL to the market icon image
namestringName of the user of the trade
outcomestringHuman readable outcome of the market
outcomeIndexintegerIndex of the outcome
pricefloatPrice of the trade
profileImagestringURL to the user profile image
proxyWalletstringAddress of the user proxy wallet
pseudonymstringPseudonym of the user
sidestringSide of the trade (BUY/SELL)
sizeintegerSize of the trade
slugstringSlug of the market
timestampintegerTimestamp of the trade
titlestringTitle of the event
transactionHashstringHash of the transaction

Comments

Comment

NameTypeDescription
idstringUnique identifier of comment
bodystringContent of the comment
parentEntityTypestringType of the parent entity (Event or Series)
parentEntityIDnumberID of the parent entity
parentCommentIDstringID of the parent comment
userAddressstringAddress of the user
replyAddressstringAddress of the reply user
createdAtstringCreation timestamp
updatedAtstringLast update timestamp

Reaction

NameTypeDescription
idstringUnique identifier of reaction
commentIDnumberID of the comment
reactionTypestringType of the reaction
iconstringIcon representing the reaction
userAddressstringAddress of the user
createdAtstringCreation timestamp

RFQ

Request

NameTypeDescription
requestIdstringUnique identifier for the request
proxyAddressstringUser proxy address
marketstringId of market which is also the CTF condition ID
tokenstringERC1155 token ID of conditional token being traded
complementstringComplement ERC1155 token ID of conditional token being traded
statestringCurrent state of the request
sidestringIndicates buy or sell side
sizeInnumberInput size of the request
sizeOutnumberOutput size of the request
pricenumberPrice from in/out sizes
expirynumberExpiry timestamp (UNIX format)

Quote

NameTypeDescription
quoteIdstringUnique identifier for the quote
requestIdstringAssociated request identifier
proxyAddressstringUser proxy address
tokenstringERC1155 token ID of conditional token being traded
statestringCurrent state of the quote
sidestringIndicates buy or sell side
sizeInnumberInput size of the quote
sizeOutnumberOutput size of the quote
sizeOutnumberOutput size of the request
conditionstringId of market which is also the CTF condition ID
complementstringComplement ERC1155 token ID of conditional token being traded
expirynumberExpiry timestamp (UNIX format)

CryptoPrice

NameTypeDescription
symbolstringSymbol of the asset
timestampnumberTimestamp in milliseconds for the update
valuenumberValue at the time of update

Filters

  • {"symbol":"btcusdt"}
  • {"symbol":"ethusdt"}
  • {"symbol":"xrpusdt"}
  • {"symbol":"solusdt"}

Initial data dump on connection

When the connection is stablished, if a filter is used, the server will dump an initial snapshoot of recent data

NameTypeDescription
symbolstringSymbol of the asset
dataarrayArray of price data objects, each containing timestamp and value

CLOB User

Order

NameTypeDescription
asset_idstringOrder's ERC1155 token ID of conditional token
created_atstring (timestamp)Order's creation UNIX timestamp
expirationstring (timestamp)Order's expiration UNIX timestamp
idstringUnique order hash identifier
maker_addressstringMaker’s address (funder)
marketstringCondition ID or market identifier
order_typestringType of order: GTC, GTD, FOK, FAK
original_sizestringOriginal size of the order at placement
outcomestringOrder outcome: YES / NO
ownerstringUUID of the order owner
pricestringOrder price (e.g., in decimals like 0.5)
sidestringSide of the trade: BUY or SELL
size_matchedstringAmount of order that has been matched
statusstringStatus of the order (e.g., MATCHED)
typestringType of update: PLACEMENT, CANCELLATION, FILL, etc.

Trade

NameTypeDescription
asset_idstringERC1155 token ID of the conditional token involved in the trade
fee_rate_bpsstringFee rate in basis points (bps)
idstringUnique identifier for the match record
last_updatestring (timestamp)Last update timestamp (UNIX)
maker_addressstringMaker’s address
maker_ordersarrayList of maker orders (see nested schema below)
marketstringCondition ID or market identifier
match_timestring (timestamp)Match execution timestamp (UNIX)
outcomestringOutcome of the market: YES / NO
ownerstringUUID of the taker (owner of the matched order)
pricestringMatched price (in decimal format, e.g., 0.5)
sidestringTaker side of the trade: BUY or SELL
sizestringTotal matched size
statusstringStatus of the match: e.g., MINED
taker_order_idstringID of the taker's order
transaction_hashstringTransaction hash where the match was settled
maker_orders
NameTypeDescription
asset_idstringERC1155 token ID of the conditional token of the maker's order
fee_rate_bpsstringMaker's fee rate in basis points
maker_addressstringMaker’s address
matched_amountstringAmount matched from the maker's order
order_idstringID of the maker's order
outcomestringOutcome targeted by the maker's order (YES / NO)
ownerstringUUID of the maker
pricestringOrder price
sidestringSide of the maker: BUY or SELL

CLOB market

PriceChanges

NameTypeDescription
marketstringCondition ID
price_changesarrayPrice changes by book
timestampstring (timestamp)Timestamp in milliseconds since epoch (UNIX time * 1000)
PriceChange
NameTypeDescription
asset_idstringAsset identifier
hashstringUnique hash ID of the book snapshot
pricestringPrice quoted (e.g., 0.5)
sidestringSide of the quote: BUY or SELL
sizestringSize or volume available at the quoted price (e.g., 0, 100)
best_askstringBest ask price
best_bidstringBest bid price

AggOrderbook

NameTypeDescription
asksarrayList of ask aggregated orders (sell side), each with price and size
asset_idstringAsset Id identifier
bidsarrayList of aggregated bid orders (buy side), each with price and size
hashstringUnique hash ID for this orderbook snapshot
marketstringMarket or condition ID
min_order_sizestringMinimum allowed order size
neg_riskbooleanNegRisk or not
tick_sizestringMinimum tick size
timestampstring (timestamp)Timestamp in milliseconds since epoch (UNIX time * 1000)
asks/bids scheema
NameTypeDescription
pricestringPrice level
sizestringSize at that price
Initial data dump on connection

When the connection is stablished, if a filter is used, the server will dump an initial snapshoot of recent data

LastTradePrice

NameTypeDescription
asset_idstringAsset Id identifier
fee_rate_bpsstringFee rate in basis points (bps)
marketstringMarket or condition ID
pricestringTrade price (e.g., 0.5)
sidestringSide of the order: BUY or SELL
sizestringSize of the trade

TickSizeChange

NameTypeDescription
marketstringMarket or condition ID
asset_idstringArray of two ERC1155 asset ID
old_tick_sizestringPrevious tick size before the change
new_tick_sizestringUpdated tick size after the change

ClobMarket

NameTypeDescription
marketstringMarket or condition ID
asset_ids[2]stringArray of two ERC1155 asset ID identifiers associated with market
min_order_sizestringMinimum size allowed for an order
tick_sizestringMinimum allowable price increment
neg_riskbooleanIndicates if the market is negative risk

Keywords

Polymarket

FAQs

Package last updated on 25 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts