From 19950131397c540b9dd355b92169fdc7fa1b6f91 Mon Sep 17 00:00:00 2001 From: Rodrigo <95635797+poly-rodr@users.noreply.github.com> Date: Fri, 27 May 2022 18:09:32 -0300 Subject: [PATCH] Adding support for GetLastTradePrice method --- examples/getLastTradePrice.ts | 22 ++++++++++++++++++++++ package.json | 2 +- src/client.ts | 7 +++++++ src/endpoints.ts | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 examples/getLastTradePrice.ts diff --git a/examples/getLastTradePrice.ts b/examples/getLastTradePrice.ts new file mode 100644 index 0000000..eece921 --- /dev/null +++ b/examples/getLastTradePrice.ts @@ -0,0 +1,22 @@ +import { ethers } from "ethers"; +import { config as dotenvConfig } from "dotenv"; +import { resolve } from "path"; +import { ApiKeyCreds, ClobClient } from "../src"; + +dotenvConfig({ path: resolve(__dirname, "../.env") }); + +async function main() { + const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL); + const pk = new ethers.Wallet(`${process.env.PK}`); + const wallet = pk.connect(provider); + console.log(`Address: ${await wallet.getAddress()}`); + + const host = process.env.CLOB_API_URL || "http://localhost:8080"; + const clobClient = new ClobClient(host, wallet); + + console.log(`Price: `); + const resp = await clobClient.getLastTradePrice("16678291189211314787145083999015737376658799626183230671758641503291735614088"); + console.log(resp); +} + +main(); diff --git a/package.json b/package.json index 209d2c2..8d22b91 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "1.0.24", + "version": "1.0.25", "contributors": [ { "name": "Jonathan Amenechi", diff --git a/src/client.ts b/src/client.ts index 90e1ea4..5ed68fd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -35,6 +35,7 @@ import { OPEN_ORDERS, ORDER_HISTORY, DERIVE_API_KEY, + GET_LAST_TRADE_PRICE, } from "./endpoints"; import { OrderBuilder } from "./order-builder/builder"; @@ -91,6 +92,12 @@ export class ClobClient { return get(`${this.host}${PRICE}?market=${tokenID}&side=${side}`); } + public async getLastTradePrice(tokenID: string): Promise { + const endpoint = `${this.host}${GET_LAST_TRADE_PRICE}?market=${tokenID}`; + return get(endpoint); + } + + // L1 Authed /** diff --git a/src/endpoints.ts b/src/endpoints.ts index ecf9a43..316bf8d 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -27,3 +27,5 @@ export const POST_ORDER = "/order"; export const CANCEL = "/order"; export const CANCEL_ALL = "/cancel-all"; + +export const GET_LAST_TRADE_PRICE = "/last-trade-price";