Skip to content

Commit

Permalink
Merge pull request #123 from Polymarket/feat/orderbook-ts
Browse files Browse the repository at this point in the history
version
  • Loading branch information
poly-rodr authored Sep 24, 2024
2 parents 8a9186c + d02b579 commit 75703fb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/cancelOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {

// Send it to the server
const resp = await clobClient.cancelOrder({
orderID: "0x920cb5fc73e8cce1d8ee00c90beca3d7cc4195adc82a8c94ea96134eaefefe39", // Order ID
orderID: "0x989af24e7bdf0f815e464d5560a0657735a9199fa3a6cd7fb968c85cc65d18b4", // Order ID
});
console.log(resp);
console.log(`Done!`);
Expand Down
9 changes: 8 additions & 1 deletion examples/cancelOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ async function main() {

// Send it to the server
const resp = await clobClient.cancelOrders([
"0xd4f32972ee7fbf7f8e666bd63e02ad0cc8a23596f72ba5f0f1b3e437b8cc6459",
"0x7ce769d075f4f1263603fde09862f5998f5e6ae4a39a16f3780f0bd708d3fc1c",
]);
console.log(resp);
console.log(`Done!`);
/*
bids: [ { price: '0.5', size: '66240' } ],
asks: [
{ price: '0.56', size: '1000' },
{ price: '0.55', size: '9701387.74' }
*/
}

main();
2 changes: 1 addition & 1 deletion examples/getOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

const order = await clobClient.getOrder(
"0xb816482a5187a3d3db49cbaf6fe3ddf24f53e6c712b5a4bf5e01d0ec7b11dabc",
"0x831680cb77da95792af5a052c87c8abf9d2ae5cb21f275670bc0ff58f2823c5c",
);
console.log(order);
}
Expand Down
11 changes: 7 additions & 4 deletions examples/marketOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ async function main() {
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const marketOrder = await clobClient.createMarketBuyOrder({
tokenID: YES,
amount: 100,
feeRateBps: 0,
nonce: 0,
price: 0.5,
amount: 0.1,
});
console.log("Created Market Order", marketOrder);

// Send it to the server
const resp = await clobClient.postOrder(marketOrder, OrderType.FOK);
console.log(resp);
/*
asks: [
{ price: '0.56', size: '1000' },
{ price: '0.55', size: '9701369.36' }
],*/
}

main();
34 changes: 19 additions & 15 deletions examples/order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable no-constant-condition */
import { ethers } from "ethers";
import { config as dotenvConfig } from "dotenv";
import { resolve } from "path";
import { ApiKeyCreds, Chain, ClobClient, Side } from "../src";
import { SignedOrder } from "@polymarket/order-utils";

dotenvConfig({ path: resolve(__dirname, "../.env") });

Expand All @@ -20,21 +22,23 @@ async function main() {

// Create a buy order for 100 YES for 0.50c
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const order = await clobClient.createOrder(
{
tokenID: YES,
price: 0.5,
side: Side.BUY,
size: 100,
feeRateBps: 0,
},
{ tickSize: "0.01" },
);
console.log("Created Order", order);

// Send it to the server
const resp = await clobClient.postOrder(order);
console.log(resp);
const promises: Promise<SignedOrder>[] = [];
for (let i = 0; i < 1; i++) {
promises.push(
clobClient
.createOrder(
{
tokenID: YES,
price: 0.5,
side: Side.SELL,
size: 100,
},
{ tickSize: "0.01" },
)
.then(o => clobClient.postOrder(o)),
);
}
await Promise.all(promises);
}

main();
8 changes: 4 additions & 4 deletions examples/socketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApiKeyCreds } from "../src";
const YES_TOKEN_ID =
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
// eslint-disable-next-line max-len
const NO_TOKEN_ID = "52114319501245915516055106046884209969926127482827954674443846427813813222426";
//const NO_TOKEN_ID = "52114319501245915516055106046884209969926127482827954674443846427813813222426";
// eslint-disable-next-line max-len
const CONDITION_ID = "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1";

Expand Down Expand Up @@ -59,7 +59,7 @@ async function main(type: "user" | "market" | "live-activity") {
if (type == "user") {
subscriptionMessage["markets"] = [CONDITION_ID];
} else {
subscriptionMessage["assets_ids"] = [NO_TOKEN_ID, YES_TOKEN_ID];
subscriptionMessage["assets_ids"] = [YES_TOKEN_ID];
}
}

Expand All @@ -85,7 +85,7 @@ async function main(type: "user" | "market" | "live-activity") {
setInterval(() => {
console.log("PINGING");
ws.send("PING");
}, 50000);
}, 10000);

if (ev) {
console.log("open", ev);
Expand All @@ -97,4 +97,4 @@ async function main(type: "user" | "market" | "live-activity") {
};
}

main("user");
main("market");
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": "4.9.1",
"version": "4.10.0",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down

0 comments on commit 75703fb

Please sign in to comment.