Skip to content

Commit

Permalink
Merge pull request #91 from Polymarket/feat/live-activity-service
Browse files Browse the repository at this point in the history
Adding live-activity service example
  • Loading branch information
poly-rodr authored Jun 12, 2023
2 parents 8c99f22 + 3cdbacc commit 79c549c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
55 changes: 33 additions & 22 deletions examples/socketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,48 @@ const YES_TOKEN_ID = "1343197538147866997676250008839231694243646439454152539053
// const NO_TOKEN_ID = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const CONDITION_ID = "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af";

interface subscriptionMessage {
auth: { apiKey: string; secret: string; passphrase: string };
type: string;
markets: string[];
assets_ids: string[];
}

/**
*
* @param type user | market
*/
async function main(type: "user" | "market") {
async function main(type: "user" | "market" | "live-activity") {
const host = process.env.WS_URL || "ws://localhost:8081";
console.log(`${host}/ws/${type}`);
let ws = new WebSocket(`${host}/ws/${type}`); // change to market for market, user for user

const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
passphrase: `${process.env.CLOB_PASS_PHRASE}`,
};
let subscriptionMessage: subscriptionMessage = {} as subscriptionMessage;

let subscriptionMessage = {
auth: {
apiKey: creds.key,
secret: creds.secret,
passphrase: creds.passphrase,
},
type, // change to market for market, user for user
markets: [] as string[],
assets_ids: [] as string[],
};
if (type != "live-activity") {
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
passphrase: `${process.env.CLOB_PASS_PHRASE}`,
};

subscriptionMessage = {
auth: {
apiKey: creds.key,
secret: creds.secret,
passphrase: creds.passphrase,
},
type, // change to market for market, user for user
markets: [] as string[],
assets_ids: [] as string[],
};

if (type == "user") {
subscriptionMessage["markets"] = [CONDITION_ID];
} else {
subscriptionMessage["assets_ids"] = [YES_TOKEN_ID];
// subscriptionMessage["assets_ids"] = [NO_TOKEN_ID];
if (type == "user") {
subscriptionMessage["markets"] = [CONDITION_ID];
} else {
subscriptionMessage["assets_ids"] = [YES_TOKEN_ID];
// subscriptionMessage["assets_ids"] = [NO_TOKEN_ID];
}
}

ws.on("open", function () {
Expand All @@ -59,4 +70,4 @@ async function main(type: "user" | "market") {
});
}

main("market");
main("live-activity");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@polymarket/clob-client",
"description": "Typescript client for Polymarket's CLOB",
"version": "2.4.0",
"version": "2.5.0",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down

0 comments on commit 79c549c

Please sign in to comment.