Skip to content

Commit

Permalink
Merge pull request #30 from Polymarket/feature/tracker-url-env-variable
Browse files Browse the repository at this point in the history
Adding Clob API URL Env var
  • Loading branch information
poly-rodr authored May 27, 2022
2 parents 6bd3d34 + 40de6f0 commit a963ef7
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ RPC_URL=http://polygon-mumbai.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PK=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CLOB_API_KEY=
CLOB_SECRET=
CLOB_PASS_PHRASE=
CLOB_PASS_PHRASE=
CLOB_API_URL=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Typescript client for the Polymarket CLOB
### Usage

```ts
const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const signer = new ethers.Wallet(`${process.env.PK}`);
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/cancelAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/cancelOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/createApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const clobClient = new ClobClient(host, wallet);

console.log(`Response: `);
Expand Down
2 changes: 1 addition & 1 deletion examples/deriveApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const clobClient = new ClobClient(host, wallet);

console.log(`Response: `);
Expand Down
2 changes: 1 addition & 1 deletion examples/getApiKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/getOpenOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/getOrderHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/getOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ClobClient } from "../src";
dotenvConfig({ path: resolve(__dirname, "../.env") });

async function main() {
const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const clobClient = new ClobClient(host);
const resp = await clobClient.getOrderBook("16678291189211314787145083999015737376658799626183230671758641503291735614088")
console.log(resp);
Expand Down
46 changes: 46 additions & 0 deletions examples/getPrice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
passphrase: `${process.env.CLOB_PASS_PHRASE}`,
};
const clobClient = new ClobClient(host, wallet, creds);

const YES_TOKEN_ID="16678291189211314787145083999015737376658799626183230671758641503291735614088"
const NO_TOKEN_ID="1343197538147866997676250008839231694243646439454152539053893078719042421992"

clobClient.getPrice(
YES_TOKEN_ID,
"buy"
).then((price:any)=> console.log('YES', 'BUY', price));

clobClient.getPrice(
YES_TOKEN_ID,
"sell"
).then((price:any)=> console.log('YES', 'SELL', price));

clobClient.getPrice(
NO_TOKEN_ID,
"buy"
).then((price:any)=> console.log('NO', 'BUY', price));

clobClient.getPrice(
NO_TOKEN_ID,
"sell"
).then((price:any)=> console.log('NO', 'SELL', price));
}

main();
2 changes: 1 addition & 1 deletion examples/getServerTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ClobClient } from "../src";
dotenvConfig({ path: resolve(__dirname, "../.env") });

async function main() {
const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const clobClient = new ClobClient(host);

console.log(`Server time: ${await clobClient.getServerTime()}`);
Expand Down
2 changes: 1 addition & 1 deletion examples/getTradeHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/limitOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/marketBuy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/marketOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/marketOrderWorstPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/populateOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/testMultiSigMarketBuy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/testPolyProxyMarketBuy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down
2 changes: 1 addition & 1 deletion examples/testPolyProxyMarketSell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
const wallet = pk.connect(provider);
console.log(`Address: ${await wallet.getAddress()}`);

const host = "http://localhost:8080";
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const creds: ApiKeyCreds = {
key: `${process.env.CLOB_API_KEY}`,
secret: `${process.env.CLOB_SECRET}`,
Expand Down

0 comments on commit a963ef7

Please sign in to comment.