-
Notifications
You must be signed in to change notification settings - Fork 18
Add CLI example for creating and signing CLOB orders #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import "dotenv/config"; | ||
|
|
||
| import { createLimitOrder, signOrder } from "../src"; // если нужно, изменим путь | ||
|
|
||
| function requireEnv(name: string): string { | ||
| const value = process.env[name]; | ||
| if (!value) { | ||
| console.error(`[clob-order-utils] Missing required env var: ${name}`); | ||
| process.exit(1); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| async function main() { | ||
| const privateKey = requireEnv("PRIVATE_KEY"); | ||
| const exchangeAddress = requireEnv("EXCHANGE_ADDRESS"); | ||
| const chainIdRaw = requireEnv("CHAIN_ID"); | ||
|
|
||
| const chainId = Number(chainIdRaw); | ||
| if (!Number.isFinite(chainId)) { | ||
| console.error( | ||
| `[clob-order-utils] Invalid CHAIN_ID, expected number, got: ${chainIdRaw}`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const order = createLimitOrder({ | ||
| marketId: "MARKET_ID_HERE", | ||
| outcome: 0, | ||
| price: "0.5", | ||
| size: "1", | ||
| side: "buy", | ||
| maker: exchangeAddress, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong address used as order makerThe |
||
| chainId, | ||
| }); | ||
|
|
||
| const signed = await signOrder(order, privateKey); | ||
| console.log(JSON.stringify(signed, null, 2)); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error("[clob-order-utils] Unexpected error:", err); | ||
| process.exit(1); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing dotenv dependency prevents example from running
The example imports
dotenv/configto load environment variables, butdotenvis not listed inpackage.jsonas a dependency or devDependency. Runningnpm run example:create-orderwill fail with a "Cannot find module 'dotenv'" error because the package isn't installed.