Skip to content

Commit

Permalink
examples update
Browse files Browse the repository at this point in the history
  • Loading branch information
poly-rodr committed Apr 12, 2024
1 parent d045dc6 commit 166aba8
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
passphrase: `${process.env.CLOB_PASS_PHRASE}`,
}
};

// Initialize the clob client
// NOTE: the signer must be approved on the CTFExchange contract
const clobClient = new ClobClient(host, signer, creds);

// Create a buy order for 100 NO for 0.50c
const order = await clobClient.createOrder({
tokenId: "16678291189211314787145083999015737376658799626183230671758641503291735614088",
tokenId: "52114319501245915516055106046884209969926127482827954674443846427813813222426",
price: 0.5,
side: Side.Buy,
size: 100,
Expand Down
2 changes: 1 addition & 1 deletion examples/GTDOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {

// Create a buy order for 100 YES for 0.50c with an expiration of 1 minute
// We add an extra 10s because Clob has a security threshold of 10 seconds before canceling it.
const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const oneMinute = parseInt(((new Date().getTime() + 60 * 1000 + 10 * 1000) / 1000).toString());

const order = await clobClient.createOrder({
Expand Down
6 changes: 3 additions & 3 deletions examples/cancelMarketOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES_TOKEN_ID =
"1343197538147866997676250008839231694243646439454152539053893078719042421992";
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO_TOKEN_ID =
"16678291189211314787145083999015737376658799626183230671758641503291735614088";
const CONDITION_ID = "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af";
"52114319501245915516055106046884209969926127482827954674443846427813813222426";
const CONDITION_ID = "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1";

// Send it to the server
console.log(await clobClient.cancelMarketOrders({ market: CONDITION_ID }));
Expand Down
2 changes: 1 addition & 1 deletion examples/geoToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function main() {
);

// Create a buy order for 100 YES for 0.50c
const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const order = await clobClient.createOrder(
{
tokenID: YES,
Expand Down
4 changes: 2 additions & 2 deletions examples/getBalanceAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ async function main() {

const yes = await clobClient.getBalanceAllowance({
asset_type: AssetType.CONDITIONAL,
token_id: "1343197538147866997676250008839231694243646439454152539053893078719042421992",
token_id: "71321045679252212594626385532706912750332728571942532289631379312455583992563",
});
console.log(yes);

const no = await clobClient.getBalanceAllowance({
asset_type: AssetType.CONDITIONAL,
token_id: "16678291189211314787145083999015737376658799626183230671758641503291735614088",
token_id: "52114319501245915516055106046884209969926127482827954674443846427813813222426",
});
console.log(no);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/getLastTradePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ async function main() {

console.log(
await clobClient.getLastTradePrice(
"16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO
"52114319501245915516055106046884209969926127482827954674443846427813813222426", // NO
),
);
console.log(
await clobClient.getLastTradePrice(
"1343197538147866997676250008839231694243646439454152539053893078719042421992", // YES
"71321045679252212594626385532706912750332728571942532289631379312455583992563", // YES
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/getLastTradesPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ async function main() {
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const clobClient = new ClobClient(host, chainId, wallet);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const NO = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO = "52114319501245915516055106046884209969926127482827954674443846427813813222426";

const lastTradesPrices = await clobClient.getLastTradesPrices([
{ token_id: YES },
Expand Down
4 changes: 2 additions & 2 deletions examples/getMidPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES_TOKEN_ID =
"1343197538147866997676250008839231694243646439454152539053893078719042421992";
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO_TOKEN_ID =
"16678291189211314787145083999015737376658799626183230671758641503291735614088";
"52114319501245915516055106046884209969926127482827954674443846427813813222426";

clobClient.getMidpoint(YES_TOKEN_ID).then((price: any) => console.log("YES", price));
clobClient.getMidpoint(NO_TOKEN_ID).then((price: any) => console.log("NO", price));
Expand Down
4 changes: 2 additions & 2 deletions examples/getMidPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async function main() {
};
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const NO = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO = "52114319501245915516055106046884209969926127482827954674443846427813813222426";

const midpoints = await clobClient.getMidpoints([
{ token_id: YES },
Expand Down
6 changes: 3 additions & 3 deletions examples/getOpenOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ async function main() {
await clobClient.getOpenOrders({
asset_id:
// eslint-disable-next-line max-len
"16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO
"52114319501245915516055106046884209969926127482827954674443846427813813222426", // NO
owner: creds.key,
}),
);
console.log(
await clobClient.getOpenOrders({
asset_id:
// eslint-disable-next-line max-len
"1343197538147866997676250008839231694243646439454152539053893078719042421992", // YES
"71321045679252212594626385532706912750332728571942532289631379312455583992563", // YES
owner: creds.key,
}),
);

console.log(
await clobClient.getOpenOrders({
market: "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af",
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
owner: creds.key,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion examples/getOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function main() {
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const chainId = parseInt(`${process.env.CHAIN_ID || Chain.AMOY}`) as Chain;
const clobClient = new ClobClient(host, chainId);
const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";

const orderbook = await clobClient.getOrderBook(YES);
console.log("orderbook", orderbook);
Expand Down
4 changes: 2 additions & 2 deletions examples/getOrderbooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ async function main() {
const chainId = parseInt(`${process.env.CHAIN_ID || Chain.AMOY}`) as Chain;
const clobClient = new ClobClient(host, chainId);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const NO = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO = "52114319501245915516055106046884209969926127482827954674443846427813813222426";

const orderbooks = await clobClient.getOrderBooks([
{ token_id: YES },
Expand Down
4 changes: 2 additions & 2 deletions examples/getPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES_TOKEN_ID =
"1343197538147866997676250008839231694243646439454152539053893078719042421992";
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO_TOKEN_ID =
"16678291189211314787145083999015737376658799626183230671758641503291735614088";
"52114319501245915516055106046884209969926127482827954674443846427813813222426";

clobClient.getPrice(YES_TOKEN_ID, "buy").then((price: any) => console.log("YES", "BUY", price));
clobClient
Expand Down
4 changes: 2 additions & 2 deletions examples/getPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async function main() {
};
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const NO = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO = "52114319501245915516055106046884209969926127482827954674443846427813813222426";

const prices = await clobClient.getPrices([
{ token_id: YES, side: Side.BUY },
Expand Down
4 changes: 2 additions & 2 deletions examples/getPricesHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES_TOKEN_ID =
"1343197538147866997676250008839231694243646439454152539053893078719042421992";
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
const NO_TOKEN_ID =
"16678291189211314787145083999015737376658799626183230671758641503291735614088";
"52114319501245915516055106046884209969926127482827954674443846427813813222426";

const yes_prices_history = await clobClient.getPricesHistory({
startTs: new Date().getTime() / 1000 - 1000,
Expand Down
6 changes: 3 additions & 3 deletions examples/getTrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
await clobClient.getTrades({
asset_id:
// eslint-disable-next-line max-len
"16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO
"52114319501245915516055106046884209969926127482827954674443846427813813222426", // NO
maker: await wallet.getAddress(),
limit: 10,
}),
Expand All @@ -31,14 +31,14 @@ async function main() {
await clobClient.getTrades({
asset_id:
// eslint-disable-next-line max-len
"1343197538147866997676250008839231694243646439454152539053893078719042421992", // YES
"71321045679252212594626385532706912750332728571942532289631379312455583992563", // YES
maker: await wallet.getAddress(),
limit: 10,
}),
);
console.log(
await clobClient.getTrades({
market: "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af",
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
maker: await wallet.getAddress(),
limit: 10,
}),
Expand Down
2 changes: 1 addition & 1 deletion examples/marketOrder.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);

// Create a YES market buy order for the equivalent of 100 USDC for the market price
const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const marketOrder = await clobClient.createMarketBuyOrder({
tokenID: YES,
amount: 100,
Expand Down
2 changes: 1 addition & 1 deletion examples/matchOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
};
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const yes_bid = await clobClient.createOrder({
tokenID: YES,
price: 0.5,
Expand Down
8 changes: 4 additions & 4 deletions examples/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { ApiKeyCreds, Chain, ClobClient, Side } from "../src";
dotenvConfig({ path: resolve(__dirname, "../.env") });

async function main() {
const wallet = new ethers.Wallet(`${process.env.PK}`);
const wallet = new ethers.Wallet(
`ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`,
);
const chainId = parseInt(`${process.env.CHAIN_ID || Chain.AMOY}`) as Chain;
console.log(`Address: ${await wallet.getAddress()}, chainId: ${chainId}`);

Expand All @@ -19,16 +21,14 @@ async function main() {
const clobClient = new ClobClient(host, chainId, wallet, creds);

// Create a buy order for 100 YES for 0.50c
const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const order = await clobClient.createOrder(
{
tokenID: YES,
price: 0.5,
side: Side.BUY,
size: 100,
feeRateBps: 0,
nonce: 0,
expiration: 0,
},
{ tickSize: "0.01" },
);
Expand Down
4 changes: 2 additions & 2 deletions examples/populateOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
};
const clobClient = new ClobClient(host, chainId, wallet, creds);

const YES = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES = "71321045679252212594626385532706912750332728571942532289631379312455583992563";
const yes_bid = await clobClient.createOrder({
tokenID: YES,
price: 0.4,
Expand All @@ -41,7 +41,7 @@ async function main() {
console.log("creating order", yes_ask);
await clobClient.postOrder(yes_ask);

const NO = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const NO = "52114319501245915516055106046884209969926127482827954674443846427813813222426";
const no_bid = await clobClient.createOrder({
tokenID: NO,
price: 0.4,
Expand Down
2 changes: 1 addition & 1 deletion examples/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {
console.log(
"rewards for market",
await clobClient.getRawRewardsForMarket(
"0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af",
"0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
),
);
console.log(
Expand Down
7 changes: 4 additions & 3 deletions examples/socketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ dotenvConfig({ path: resolve(__dirname, "../.env") });
import { WebSocket } from "ws";
import { ApiKeyCreds } from "../src";

const YES_TOKEN_ID = "1343197538147866997676250008839231694243646439454152539053893078719042421992";
const YES_TOKEN_ID =
"71321045679252212594626385532706912750332728571942532289631379312455583992563";
// eslint-disable-next-line max-len
const NO_TOKEN_ID = "16678291189211314787145083999015737376658799626183230671758641503291735614088";
const CONDITION_ID = "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af";
const NO_TOKEN_ID = "52114319501245915516055106046884209969926127482827954674443846427813813222426";
const CONDITION_ID = "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1";

interface subscriptionMessage {
auth: { apiKey: string; secret: string; passphrase: string };
Expand Down
2 changes: 1 addition & 1 deletion examples/testPolyProxyMarketBuy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function populateBook(client: ClobClient) {
await client.createOrder({
tokenID:
// eslint-disable-next-line max-len
"16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO
"52114319501245915516055106046884209969926127482827954674443846427813813222426", // NO
side: newOrder.side,
price: newOrder.price,
size: newOrder.size,
Expand Down
2 changes: 1 addition & 1 deletion examples/testPolyProxyMarketSell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function populateBook(client: ClobClient) {
await client.createOrder({
tokenID:
// eslint-disable-next-line max-len
"16678291189211314787145083999015737376658799626183230671758641503291735614088", // NO
"52114319501245915516055106046884209969926127482827954674443846427813813222426", // NO
side: newOrder.side,
price: newOrder.price,
size: newOrder.size,
Expand Down
Loading

0 comments on commit 166aba8

Please sign in to comment.