4e89f53c24
- 创建 MarketController,将市场相关接口从 AccountController 移出 - 添加 /api/copy-trading/markets/latest-price 接口供前端获取最新价 - 在 PolymarketClobService 中封装获取订单表和最优价的逻辑 - 支持多元市场(二元、三元及以上)的最优价获取 - 市价单价格添加调整系数(买单+0.01,卖单-0.02) - 移除所有测试文件中的真实私钥和API凭证 - 更新前端API服务,添加markets相关接口
41 lines
1.9 KiB
TypeScript
41 lines
1.9 KiB
TypeScript
//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(process.env.PRIVATE_KEY || ""); //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).deleteApiKey();
|
|
|
|
//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: "87660119269436753918591605029528224889066452434179554814663664703244066132110", //Use https://docs.polymarket.com/developers/gamma-markets-api/get-markets to grab a sample token
|
|
price: 0.37,
|
|
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)
|
|
})();
|
|
|