Coiex API Curl 无法解析主机
Coiex API Curl Could not resolve host
我正在尝试通过应用 www.api.coinex.com 数据在 unix-BASH 环境中进行一些计算后执行 buy/sell 命令。因此,我编写了简单的 BASH 代码来为 DOGEUSDT 下市价单。
我使用以下官方指南:
API Invocation Instruction
Place Market Order
-我在 MINT 20 中使用 VPN。Linux。
- 获取数据的代码运行良好,但 POST 数据有问题。
#!/bin/bash
#A code to put a market order in the www.coinex.com exchange pairs
#My Access ID in www.coinex.com
access_id="xxxx"
#My secrect Key in www.coinex.com
secret_key="xxxx"
#Request Url
get_url="https://api.coinex.com/v1/order/market"
#Any Amount
amount="100.0"
#Any pair in the Market
marketpair="DOGEUSDT"
#buy or sell
market_type="sell"
#the market price
price="0.041"
#Get servertime, Tonce is a timestamp with a positive Interger that represents the number of milliseconds from Unix epoch to the current time. Error between tonce and server time can not exceed plus or minus 60s
tonce=`curl -X GET https://api.coinex.com/v1/market/ticker/all | jq .data.date`
#authorization code using 32-bit MD5 Algorithm Signature
authorization=`echo -n 'access_id='$access_id'&amount='$amount'&market='$marketpair'&tonce='$tonce'&type='$market_type'&secret_key='$secret_key''|md5sum`
#Convert authorization to UPPERCASE
authorization1=`echo ${authorization^^}`
#Place market order
curl -v -H "authorization:'$authorization1'" -H "Content-Type: application/json" -d '{"access_id":"'$access_id'", "amount": "'$amount'","market":"'$market'", "tonce": "'$tonce'", "type": "'$market_type'"}' -X -POST "'$get_url'"
我收到以下错误:
* Could not resolve host: 'https
* Closing connection 0
curl: (6) Could not resolve host: 'https
版本
在 运行 评论中的最新提案后,我得到了以下错误。
` `++ curl -v -H 'authorization: 5EB8EFD237AC301BB854D32407C39AF8 -' -H 'Content-Type: application/json' -d '{
"access_id": "03391998195A4A3EAD0D6C59336CF1D1",
"amount": "0.1",
"market": "ARUSDT",
"tonce": "1636216102004",
"type": "sell"
}' --url https://api.coinex.com/v1/order/market
* Trying 104.18.30.180:443...
* TCP_NODELAY set
* Connected to api.coinex.com (104.18.30.180) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Cloudflare, Inc.; CN=coinex.com
* start date: Nov 1 00:00:00 2021 GMT
* expire date: Oct 31 23:59:59 2022 GMT
* subjectAltName: host "api.coinex.com" matched cert's "*.coinex.com"
* issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x562e9c3c3c80)
> POST /v1/order/market HTTP/2
> Host: api.coinex.com
> user-agent: curl/7.68.0
> accept: */*
> authorization: 5EB8EFD237AC301BB854D32407C39AF8 -
> content-type: application/json
> content-length: 140
>
* We are completely uploaded and fine
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 200
< date: Sat, 06 Nov 2021 16:28:24 GMT
< content-type: application/json
< content-length: 54
< cf-cache-status: DYNAMIC
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 6a9fb1d72a0c6283-OTP
<
* Connection #0 to host api.coinex.com left intact
{"code": 25, "data": {}, "message": "Signature error"} `
`
我建议您使用 jq
工具格式化您的 JSON 数据。它比 bash 或其他格式更好更可靠。
您的 cURL 最后一行变为:
# The JSON data format for jq command
# Important: $token are not for bash variables but for jq arguments
# So, DATA_FORMAT must be defined between simple cotes (not double)
declare DATA_FORMAT='{"access_id": $access_id, "amount": $amount, "market": $market, "tonce": $tonce, "type": $market_type}'
# jq call to format JSON data
# The jq arguments in data format will be replaced by bash variable values (in this example, with the same name)
declare DATA_CONTENT=$(jq \
--null-input \
--arg access_id "${access_id}" \
--arg amount "${amount}" \
--arg market "${market}" \
--arg tonce "${tonce}" \
--arg market_type "${market_type}" \
"${DATA_FORMAT}" \
)
# cURL call
curl \
-v \
-H "authorization: $authorization1" \
-H "Content-Type: application/json" \
-d "${DATA_CONTENT}" \
--url "$get_url"
根据我从 www.coinex.com 支持团队收到的最新回复,代码必须用 node
语言编写,他们没有提到 BASH。好像不支持BASH。
此外,我还找到了一个 python
包,用于连接 www.coinex.com 处的点对。我成功地与这个存储库交易了加密货币对。
https://github.com/imanmousaei/coinexpy
我正在尝试通过应用 www.api.coinex.com 数据在 unix-BASH 环境中进行一些计算后执行 buy/sell 命令。因此,我编写了简单的 BASH 代码来为 DOGEUSDT 下市价单。
我使用以下官方指南:
API Invocation Instruction
Place Market Order
-我在 MINT 20 中使用 VPN。Linux。 - 获取数据的代码运行良好,但 POST 数据有问题。
#!/bin/bash
#A code to put a market order in the www.coinex.com exchange pairs
#My Access ID in www.coinex.com
access_id="xxxx"
#My secrect Key in www.coinex.com
secret_key="xxxx"
#Request Url
get_url="https://api.coinex.com/v1/order/market"
#Any Amount
amount="100.0"
#Any pair in the Market
marketpair="DOGEUSDT"
#buy or sell
market_type="sell"
#the market price
price="0.041"
#Get servertime, Tonce is a timestamp with a positive Interger that represents the number of milliseconds from Unix epoch to the current time. Error between tonce and server time can not exceed plus or minus 60s
tonce=`curl -X GET https://api.coinex.com/v1/market/ticker/all | jq .data.date`
#authorization code using 32-bit MD5 Algorithm Signature
authorization=`echo -n 'access_id='$access_id'&amount='$amount'&market='$marketpair'&tonce='$tonce'&type='$market_type'&secret_key='$secret_key''|md5sum`
#Convert authorization to UPPERCASE
authorization1=`echo ${authorization^^}`
#Place market order
curl -v -H "authorization:'$authorization1'" -H "Content-Type: application/json" -d '{"access_id":"'$access_id'", "amount": "'$amount'","market":"'$market'", "tonce": "'$tonce'", "type": "'$market_type'"}' -X -POST "'$get_url'"
我收到以下错误:
* Could not resolve host: 'https
* Closing connection 0
curl: (6) Could not resolve host: 'https
版本 在 运行 评论中的最新提案后,我得到了以下错误。
` `++ curl -v -H 'authorization: 5EB8EFD237AC301BB854D32407C39AF8 -' -H 'Content-Type: application/json' -d '{
"access_id": "03391998195A4A3EAD0D6C59336CF1D1",
"amount": "0.1",
"market": "ARUSDT",
"tonce": "1636216102004",
"type": "sell"
}' --url https://api.coinex.com/v1/order/market
* Trying 104.18.30.180:443...
* TCP_NODELAY set
* Connected to api.coinex.com (104.18.30.180) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Cloudflare, Inc.; CN=coinex.com
* start date: Nov 1 00:00:00 2021 GMT
* expire date: Oct 31 23:59:59 2022 GMT
* subjectAltName: host "api.coinex.com" matched cert's "*.coinex.com"
* issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x562e9c3c3c80)
> POST /v1/order/market HTTP/2
> Host: api.coinex.com
> user-agent: curl/7.68.0
> accept: */*
> authorization: 5EB8EFD237AC301BB854D32407C39AF8 -
> content-type: application/json
> content-length: 140
>
* We are completely uploaded and fine
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 200
< date: Sat, 06 Nov 2021 16:28:24 GMT
< content-type: application/json
< content-length: 54
< cf-cache-status: DYNAMIC
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 6a9fb1d72a0c6283-OTP
<
* Connection #0 to host api.coinex.com left intact
{"code": 25, "data": {}, "message": "Signature error"} `
`
我建议您使用 jq
工具格式化您的 JSON 数据。它比 bash 或其他格式更好更可靠。
您的 cURL 最后一行变为:
# The JSON data format for jq command
# Important: $token are not for bash variables but for jq arguments
# So, DATA_FORMAT must be defined between simple cotes (not double)
declare DATA_FORMAT='{"access_id": $access_id, "amount": $amount, "market": $market, "tonce": $tonce, "type": $market_type}'
# jq call to format JSON data
# The jq arguments in data format will be replaced by bash variable values (in this example, with the same name)
declare DATA_CONTENT=$(jq \
--null-input \
--arg access_id "${access_id}" \
--arg amount "${amount}" \
--arg market "${market}" \
--arg tonce "${tonce}" \
--arg market_type "${market_type}" \
"${DATA_FORMAT}" \
)
# cURL call
curl \
-v \
-H "authorization: $authorization1" \
-H "Content-Type: application/json" \
-d "${DATA_CONTENT}" \
--url "$get_url"
根据我从 www.coinex.com 支持团队收到的最新回复,代码必须用 node
语言编写,他们没有提到 BASH。好像不支持BASH。
此外,我还找到了一个 python
包,用于连接 www.coinex.com 处的点对。我成功地与这个存储库交易了加密货币对。
https://github.com/imanmousaei/coinexpy