diff --git a/examples/getTradeNofications.ts b/examples/dropNofications.ts similarity index 92% rename from examples/getTradeNofications.ts rename to examples/dropNofications.ts index f07032e..0952cc9 100644 --- a/examples/getTradeNofications.ts +++ b/examples/dropNofications.ts @@ -19,8 +19,8 @@ async function main() { const clobClient = new ClobClient(host, chainId, wallet, creds); console.log( - await clobClient.getTradeNotifications({ - index: 0, + await clobClient.dropNotifications({ + ids: ["3"], }), ); } diff --git a/examples/dropTradeNofications.ts b/examples/getNofications.ts similarity index 88% rename from examples/dropTradeNofications.ts rename to examples/getNofications.ts index 240a8cd..3caa816 100644 --- a/examples/dropTradeNofications.ts +++ b/examples/getNofications.ts @@ -18,11 +18,7 @@ async function main() { }; const clobClient = new ClobClient(host, chainId, wallet, creds); - console.log( - await clobClient.dropTradeNotifications({ - index: 0, - }), - ); + console.log(await clobClient.getNotifications()); } main(); diff --git a/package.json b/package.json index e3fb443..5deb9c1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "3.1.0", + "version": "3.2.0", "contributors": [ { "name": "Jonathan Amenechi", diff --git a/src/client.ts b/src/client.ts index a80e0a6..873dd1f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -14,8 +14,7 @@ import { OrderType, Side, Trade, - TradeNotification, - TradeNotificationParams, + Notification, TradeParams, UserMarketOrder, UserOrder, @@ -31,6 +30,7 @@ import { PriceHistoryFilterParams, PaginationPayload, MarketTradeEvent, + DropNotificationParams, } from "./types"; import { createL1Headers, createL2Headers } from "./headers"; import { @@ -38,6 +38,7 @@ import { DELETE, GET, get, + parseDropNotificationParams, parseOrdersScoringParams, POST, post, @@ -65,8 +66,8 @@ import { GET_MARKETS, GET_MARKET, GET_PRICES_HISTORY, - GET_TRADE_NOTIFICATIONS, - DROP_TRADE_NOTIFICATIONS, + GET_NOTIFICATIONS, + DROP_NOTIFICATIONS, CANCEL_ORDERS, CANCEL_MARKET_ORDERS, GET_BALANCE_ALLOWANCE, @@ -353,12 +354,10 @@ export class ClobClient { return this.get(`${this.host}${endpoint}`, { headers, params }); } - public async getTradeNotifications( - params?: TradeNotificationParams, - ): Promise { + public async getNotifications(): Promise { this.canL2Auth(); - const endpoint = GET_TRADE_NOTIFICATIONS; + const endpoint = GET_NOTIFICATIONS; const headerArgs = { method: GET, requestPath: endpoint, @@ -370,13 +369,16 @@ export class ClobClient { headerArgs, ); - return this.get(`${this.host}${endpoint}`, { headers, params }); + return this.get(`${this.host}${endpoint}`, { + headers, + params: { signature_type: this.orderBuilder.signatureType }, + }); } - public async dropTradeNotifications(params?: TradeNotificationParams): Promise { + public async dropNotifications(params?: DropNotificationParams): Promise { this.canL2Auth(); - const endpoint = DROP_TRADE_NOTIFICATIONS; + const endpoint = DROP_NOTIFICATIONS; const l2HeaderArgs = { method: DELETE, requestPath: endpoint, @@ -388,7 +390,10 @@ export class ClobClient { l2HeaderArgs, ); - return this.del(`${this.host}${endpoint}`, { headers, params }); + return this.del(`${this.host}${endpoint}`, { + headers, + params: parseDropNotificationParams(params), + }); } public async getBalanceAllowance( diff --git a/src/endpoints.ts b/src/endpoints.ts index 2e13b07..361f2a9 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -36,8 +36,8 @@ export const ARE_ORDERS_SCORING = "/orders-scoring"; export const GET_PRICES_HISTORY = "/prices-history"; // Notifications -export const GET_TRADE_NOTIFICATIONS = "/trade-notifications"; -export const DROP_TRADE_NOTIFICATIONS = "/drop-trade-notifications"; +export const GET_NOTIFICATIONS = "/notifications"; +export const DROP_NOTIFICATIONS = "/notifications"; // Balance export const GET_BALANCE_ALLOWANCE = "/balance-allowance"; diff --git a/src/http-helpers/index.ts b/src/http-helpers/index.ts index ffac2c9..48f4f4c 100644 --- a/src/http-helpers/index.ts +++ b/src/http-helpers/index.ts @@ -1,5 +1,5 @@ import axios, { AxiosRequestHeaders, Method } from "axios"; -import { OrdersScoringParams } from "src/types"; +import { DropNotificationParams, OrdersScoringParams } from "src/types"; import { isBrowser } from "browser-or-node"; export const GET = "GET"; @@ -89,3 +89,15 @@ export const parseOrdersScoringParams = (orderScoringParams?: OrdersScoringParam } return params; }; + +export const parseDropNotificationParams = ( + dropNotificationParams?: DropNotificationParams, +): QueryParams => { + const params: QueryParams = {}; + if (dropNotificationParams !== undefined) { + if (dropNotificationParams.ids !== undefined) { + params["ids"] = dropNotificationParams?.ids.join(","); + } + } + return params; +}; diff --git a/src/types.ts b/src/types.ts index f961412..17bc75b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -276,27 +276,15 @@ export enum PriceHistoryInterval { ONE_HOUR = "1h", } -export interface TradeNotificationParams { - index: number; +export interface DropNotificationParams { + ids: string[]; } -export interface TradeNotification { - id: number; +export interface Notification { + type: number; owner: string; - order_id: string; - market: string; - asset_id: string; - side: string; - type: string; - price: string; - original_size: string; - matched_size: string; - remaining_size: string; - outcome: string; - outcome_index: number; - action: string; - timestamp: number; - transaction_hash: OrderType; + + payload: any; } export interface OrderMarketCancelParams { diff --git a/tests/http-helpers/index.test.ts b/tests/http-helpers/index.test.ts index 08b6c2a..6ccf856 100644 --- a/tests/http-helpers/index.test.ts +++ b/tests/http-helpers/index.test.ts @@ -1,7 +1,10 @@ import "mocha"; import { expect } from "chai"; -import { parseOrdersScoringParams } from "../../src/http-helpers/index"; -import { OrdersScoringParams } from "../../src"; +import { + parseDropNotificationParams, + parseOrdersScoringParams, +} from "../../src/http-helpers/index"; +import { DropNotificationParams, OrdersScoringParams } from "../../src"; describe("utilities", () => { describe("parseOrdersScoringParams", () => { @@ -15,4 +18,15 @@ describe("utilities", () => { expect(params).deep.equal({ order_ids: "0x0,0x1,0x2" }); }); }); + describe("parseDropNotificationParams", () => { + it("checking params", () => { + const params = parseDropNotificationParams({ + ids: ["0", "1", "2"], + } as DropNotificationParams); + expect(params).not.null; + expect(params).not.undefined; + expect(params).not.empty; + expect(params).deep.equal({ ids: "0,1,2" }); + }); + }); });