ccxt的bitmart签名无效错误

发布于 2025-01-09 20:45:53 字数 2369 浏览 1 评论 0原文

createOrder: async (req,res) =>; { 常量{ 象征, 数量, 价格, 边 } = 请求体;

      const t = Math.floor(new Date().getTime());
      console.log(t);

  const timestamp = t;
  const memo = '*****';
  const queryString = {"symbol":"BMX","side":"BUY"};
  const SecretKey = '***************************************';
  const signat = new CryptoJS.HmacSHA256(timestamp + "#" + memo + "#" + queryString, SecretKey);
  const s = signat.toString();
  console.log(s); 

    const exchange = new ccxt.bitmart({
        apiKey: process.env.apiKey,
        secret: process.env.secret,
        uid: process.env.uid,
        password: process.env.password,
        enableRateLimit: true,
        memo:'amal',
        headers: {
            'X-BM-SIGN': s,
        },
        
    // 'options': {
    //     'createMarketBuyOrderRequiresPrice': true, 

    // },
        // url: "https://api-test.bitmax-sandbox.io/",
        // sign: signat,
    });
    //console.log(exchange);
  
    try {
        console.log("inside create order");
         const s = symbol;
         const a = amount ;// BMX
         const p = price ;// BTC
         const buyOrsell = side;
        // cost = amount * price = 2 * 9000 = 18000 (USD)
         const order = await exchange.createOrder (s, 'market', buyOrsell, a, p);
         
   
         console.log (order);
         res.json(order);       
      
    } catch  (e) {
        
        if (e instanceof ccxt.NetworkError) {
            console.log (exchange.id, 'createOrder failed due to a network error:', e.message)
            // retry or whatever
            // ...
        } else if (e instanceof ccxt.ExchangeError) {
            console.log (exchange.id, 'createOrder failed due to exchange error:', e.message)
            // res.json(exchange.id, 'createOrder failed due to exchange error:', e.message);       

            // retry or whatever
            // ...
        } else {
            console.log (exchange.id, 'createOrder failed with:', e.message)
            // retry or whatever
            // ...
        }
    }
    
    
    // catch (err) {
    //     res.json({ message: err});
    //     console.log(err);
    // }
}

由于交换错误,

bitmart createOrder 失败:bitmart {"message":"标头 X-BM-SIGN 错误","code":30005,"trace":"74530845-d504-46b1-b1f9-1374ae11cbc6","data ":{}}

这个标头在哪里给出? 怎么解决这个问题?

createOrder: async (req,res) => {
const {
symbol,
amount,
price,
side
} = req.body;

      const t = Math.floor(new Date().getTime());
      console.log(t);

  const timestamp = t;
  const memo = '*****';
  const queryString = {"symbol":"BMX","side":"BUY"};
  const SecretKey = '***************************************';
  const signat = new CryptoJS.HmacSHA256(timestamp + "#" + memo + "#" + queryString, SecretKey);
  const s = signat.toString();
  console.log(s); 

    const exchange = new ccxt.bitmart({
        apiKey: process.env.apiKey,
        secret: process.env.secret,
        uid: process.env.uid,
        password: process.env.password,
        enableRateLimit: true,
        memo:'amal',
        headers: {
            'X-BM-SIGN': s,
        },
        
    // 'options': {
    //     'createMarketBuyOrderRequiresPrice': true, 

    // },
        // url: "https://api-test.bitmax-sandbox.io/",
        // sign: signat,
    });
    //console.log(exchange);
  
    try {
        console.log("inside create order");
         const s = symbol;
         const a = amount ;// BMX
         const p = price ;// BTC
         const buyOrsell = side;
        // cost = amount * price = 2 * 9000 = 18000 (USD)
         const order = await exchange.createOrder (s, 'market', buyOrsell, a, p);
         
   
         console.log (order);
         res.json(order);       
      
    } catch  (e) {
        
        if (e instanceof ccxt.NetworkError) {
            console.log (exchange.id, 'createOrder failed due to a network error:', e.message)
            // retry or whatever
            // ...
        } else if (e instanceof ccxt.ExchangeError) {
            console.log (exchange.id, 'createOrder failed due to exchange error:', e.message)
            // res.json(exchange.id, 'createOrder failed due to exchange error:', e.message);       

            // retry or whatever
            // ...
        } else {
            console.log (exchange.id, 'createOrder failed with:', e.message)
            // retry or whatever
            // ...
        }
    }
    
    
    // catch (err) {
    //     res.json({ message: err});
    //     console.log(err);
    // }
}

}

bitmart createOrder failed due to exchange error: bitmart {"message":"Header X-BM-SIGN is wrong","code":30005,"trace":"74530845-d504-46b1-b1f9-1374ae11cbc6","data":{}}

where this header is given?
how to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不打扰别人 2025-01-16 20:45:53

uid不要是你的账户uid,填写api-memo就可以了

the uid should be not your account uid, fill in the api-memo that will be fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文