【问题标题】:ByBit : API ColdFusion通过比特:API ColdFusion
【发布时间】:2023-02-15 11:14:38
【问题描述】:

在使用 ByBit By/Sell API 时遇到问题。 ColdFusion 的任何帮助表示赞赏。

https://bybit-exchange.github.io/docs/spot/v3/?console#t-authenticationparameters

POST 认证 邮政 规则:时间戳 + api_key + recv_window + raw_request_body

参数_str = “1659073093578T0d98KyVamQ62YBzN85000{ “符号”:“BTCUSDT”, "订单数量":"0.05", “边”:“卖”, "orderType": "限额", "timeInForce": "GTC", "订单价格": "24500", “orderLinkId”:“spotA0008” }”

curl --location --request POST 'https://api-testnet.bybit.com/spot/v3/private/order' \

--header 'X-BAPI-API-KEY: {api key}'
--header 'X-BAPI-TIMESTAMP: 1659067662307'
--header 'X-BAPI-RECV-WINDOW: 5000'
--header 'X-BAPI-SIGN: cc63fb44be4a87f4b7bbd42db012ddacc1c935c3d3ae3e01c3b4be393522c213'
--header 'Content-Type: application/json'
--数据原始'{ “符号”:“BTCUSDT”, "订单数量":"0.01", “边”:“买”, "orderType": "LIMIT", "timeInForce": "GTC", "订单价格": "21300", "orderLinkId": "spotx006", “订单类别”:1, “触发价格”:“21700” }'

这是帖子示例。 对于帐户 - 我的签名工作正常。

   <cfscript>

    apiKey = "#_key#";
    apiSecret = "#_s#";

   newbody = serializeJSON({
      "symbol": "#symb#",
      "orderQty":"#qty#",
       "side": "#side#",
       "orderType": "#type#"
   });

   ts_key_str = #unixdatetimeNow.getTime()# & '#apikey#' & '5000';

   str_to_sign = #unixdatetimeNow.getTime()# & '#apikey#' & '5000' & '#newbody#';

   HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");

   </cfscript>

    <cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
    <cfhttpparam type="body" value="#newbody#">
    <cfhttpparam type="HEADER" name="Content_Type" value="application/json">
    <cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2"> 
    <cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#"> 
    <cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000"> 
    <cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#"> 
    <cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#unixdatetimeNow.getTime()#"> 
    </cfhttp> 

即使在新主体前面添加 ts_key_str 也不起作用。

我的签名不好。当我使用它获取帐户数据时,它工作正常 cfhttpparam type="body" value=""

任何帮助表示赞赏。

【问题讨论】:

  • 可能是时间戳:#unixdatetimeNow.getTime()# 得到 13 位数字,但在 cfset 中使用时它变成 15 位数字。我如何限制为 13 位数字?
  • 1666807130469然后在cfset中变为166680713046918
  • 忽略:18 是从 开始的。我的错。不知道为什么这不会授权。账户流程有效。几乎尝试了一切。
  • 排序:是一个时间戳错误 - 字符串时间和 http 发布时间略有不同:所以我只是创建了一个时间戳并向每个时间发送相同的确切时间。 String Time 和 Post Time 和 5000 是服务器时间差异,只有 350 加戳:在时间之内很好

标签: api cryptoapi coldfusion-2016 bybit


【解决方案1】:

这是一个时间戳问题。

设置一个时间戳,并使用该时间戳。所以它可能不会在延迟的呼叫上拉出不同的时间戳。

更新代码。

    <!--- MARKET --->
    <cfset b_body = '{"symbol": "#pair#","orderQty":"#size#","side": "#side#","orderType": "MARKET"}'>

    <cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>
    <cfset timestamp = #unixdatetimeNow.getTime()#>

    <cfscript>
        apiKey = "#_key#";
        apiSecret = "#_s#";
        str_to_sign = #timestamp# & '#apikey#' & '5000' & '#b_body#';   
        HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");
    </cfscript>

    <cfset lhmac = lCase(#hmac#)>
   
    <cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
    <cfhttpparam type="body" value="#b_body#">
    <cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2">
    <cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#"> 
    <cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#"> 
    <cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#timestamp#"> 
    <cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000"> 
    <cfhttpparam type="HEADER" name="Content_Type" value="application/json">
    </cfhttp> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2018-09-21
    相关资源
    最近更新 更多