Issue
I am trying to do buy/sell orders after some computation in the unix-BASH environment by application of www.api.coinex.com data. Therefore, I wrote s simple BASH code to put a market order for DOGEUSDT.
I use the following official guidelines:
API Invocation Instruction
Place Market Order
-I use VPN IN MINT 20. Linux. -The codes to get data work well, but have problems with POST data.
#!/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'"
I got following error:
* Could not resolve host: 'https
* Closing connection 0
curl: (6) Could not resolve host: 'https
Edition I got the following error after running the latest proposals in the comments.
` `++ 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"} `
`
Solution
According to the latest reply I received from the www.coinex.com support team, the code must be written in node
language, they didn’t mention BASH. It seems BASH is not supported.
Also, I found a python
package to connect with spot pairs at www.coinex.com. I traded crypto pairs with this repository successfully.
https://github.com/imanmousaei/coinexpy
Answered By - mehdi shokati