fix: 修复交易统计和L2认证问题
- 修复交易统计数据计算逻辑(总订单数、已完成订单数、持仓数量) - 修复L2认证签名生成,支持URL-safe base64格式的secret - 添加标准HTTP请求头以匹配clob-client行为 - 移除数据库加密(私人应用,明文存储) - 添加自动获取API Key功能 - 优化持仓数量统计(包括正负仓位) - 添加EIP-712签名和L1认证支持 - 更新前端账户管理界面
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
node_modules/
|
||||
dist/
|
||||
*.log
|
||||
.env
|
||||
.DS_Store
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# Polymarket JS SDK Demo
|
||||
|
||||
这是一个用于测试 Polymarket JS SDK 的演示目录。
|
||||
|
||||
## 安装依赖
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
或者使用 yarn:
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
在使用脚本之前,需要修改 `src/createOrder.ts` 文件中的以下配置:
|
||||
|
||||
1. **funder**: 你的 Polymarket 账户地址(在个人资料图片下方显示的地址)
|
||||
2. **signer**: 你的私钥
|
||||
- 如果使用邮箱登录,从 https://reveal.magic.link/polymarket 导出
|
||||
- 如果使用 Web3 应用,从你的钱包导出
|
||||
3. **tokenID**: 要交易的代币 ID
|
||||
- 使用 https://docs.polymarket.com/developers/gamma-markets-api/get-markets 获取示例代币
|
||||
- 示例代币: `114304586861386186441621124384163963092522056897081085884483958561365015034812` (Xi Jinping out in 2025, YES side)
|
||||
4. **tickSize** 和 **negRisk**: 根据市场调整这些参数,从 get-markets API 获取
|
||||
|
||||
## 运行测试脚本
|
||||
|
||||
```bash
|
||||
npm run test
|
||||
```
|
||||
|
||||
或者直接使用 ts-node:
|
||||
|
||||
```bash
|
||||
npx ts-node src/createOrder.ts
|
||||
```
|
||||
|
||||
## 编译
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
编译后的文件将输出到 `dist` 目录。
|
||||
|
||||
## 运行编译后的文件
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- **不要创建新的 API key**,始终使用 `createOrDerive` 方法
|
||||
- **signatureType** 说明:
|
||||
- `1`: Magic/Email 登录
|
||||
- `2`: 浏览器钱包 (Metamask, Coinbase Wallet 等)
|
||||
- `0`: EOA (如果你不知道这是什么,说明你不在使用它)
|
||||
- 确保你的账户有足够的 USDC 余额
|
||||
- 在生产环境中使用前,请确保妥善保管私钥
|
||||
|
||||
Generated
+1509
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "polymarket-demo",
|
||||
"version": "1.0.0",
|
||||
"description": "Polymarket JS SDK 测试脚本",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "ts-node src/createOrder.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/createOrder.js"
|
||||
},
|
||||
"keywords": [
|
||||
"polymarket",
|
||||
"demo",
|
||||
"test"
|
||||
],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@polymarket/clob-client": "^4.22.8",
|
||||
"ethers": "^5.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.7.18",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//npm install @polymarket/clob-client
|
||||
//npm install ethers
|
||||
//Client initialization example and dumping API Keys
|
||||
|
||||
import { ApiKeyCreds, ClobClient, OrderType, Side, } from "@polymarket/clob-client";
|
||||
import { Wallet } from "@ethersproject/wallet";
|
||||
|
||||
const host = 'https://clob.polymarket.com';
|
||||
const funder = ''; //This is the address listed below your profile picture when using the Polymarket site.
|
||||
const signer = new Wallet("[PRIVATE_KEY_REMOVED]"); //This is your Private Key. If using email login export from https://reveal.magic.link/polymarket otherwise export from your Web3 Application
|
||||
|
||||
|
||||
//In general don't create a new API key, always derive or createOrDerive
|
||||
const creds = new ClobClient(host, 137, signer).createOrDeriveApiKey();
|
||||
|
||||
//1: Magic/Email Login
|
||||
//2: Browser Wallet(Metamask, Coinbase Wallet, etc)
|
||||
//0: EOA (If you don't know what this is you're not using it)
|
||||
|
||||
const signatureType = 1;
|
||||
(async () => {
|
||||
const clobClient = new ClobClient(host, 137, signer, await creds, signatureType, funder);
|
||||
const resp2 = await clobClient.createAndPostOrder(
|
||||
{
|
||||
tokenID: "114304586861386186441621124384163963092522056897081085884483958561365015034812", //Use https://docs.polymarket.com/developers/gamma-markets-api/get-markets to grab a sample token
|
||||
price: 0.01,
|
||||
side: Side.BUY,
|
||||
size: 5,
|
||||
feeRateBps: 0,
|
||||
},
|
||||
{ tickSize: "0.01",negRisk: false }, //You'll need to adjust these based on the market. Get the tickSize and negRisk T/F from the get-markets above
|
||||
//Refer to the API documentation to locate a tokenID: https://docs.polymarket.com/developers/gamma-markets-api/fetch-markets-guide
|
||||
//Example token: 114304586861386186441621124384163963092522056897081085884483958561365015034812 ( Xi Jinping out in 2025, YES side )
|
||||
//{ tickSize: "0.001",negRisk: true },
|
||||
|
||||
OrderType.GTC,
|
||||
);
|
||||
console.log(resp2)
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020"],
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user