Skip to content

Commit

Permalink
Merge pull request #31 from Polymarket/feature/get-last-trade-price
Browse files Browse the repository at this point in the history
 Adding support for GetLastTradePrice method
  • Loading branch information
poly-rodr authored May 27, 2022
2 parents a963ef7 + 1995013 commit 8dff86b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions examples/getLastTradePrice.ts
Original file line number Diff line number Diff line change
@@ -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();
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": "1.0.24",
"version": "1.0.25",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
OPEN_ORDERS,
ORDER_HISTORY,
DERIVE_API_KEY,
GET_LAST_TRADE_PRICE,
} from "./endpoints";
import { OrderBuilder } from "./order-builder/builder";

Expand Down Expand Up @@ -91,6 +92,12 @@ export class ClobClient {
return get(`${this.host}${PRICE}?market=${tokenID}&side=${side}`);
}

public async getLastTradePrice(tokenID: string): Promise<any> {
const endpoint = `${this.host}${GET_LAST_TRADE_PRICE}?market=${tokenID}`;
return get(endpoint);
}


// L1 Authed

/**
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 8dff86b

Please sign in to comment.