Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BASH Code Error #115

Open
Mehdi1m opened this issue Nov 20, 2021 · 0 comments
Open

BASH Code Error #115

Mehdi1m opened this issue Nov 20, 2021 · 0 comments

Comments

@Mehdi1m
Copy link

Mehdi1m commented Nov 20, 2021

I have written a BASH code to trade with COinex.com API after some calculation in BASH environment. When I run this code I get a Signature error, I will be grateful for your feedbacks and guidelines.


        #!/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="0.1"  
#Any pair in the Market
market="ARUSDT"  
#buy or sell
type="sell" 

#Get server time, Tonce is a timestamp with a positive Integer 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 'access_id='$access_id'&amount='$amount'&market='$market'&tonce='$tonce'&type='$type'&secret_key='$secret_key''|md5sum| cut -d' ' -f1`
echo 'access_id='$access_id'&amount='$amount'&market='$market'&tonce='$tonce'&type='$type'&secret_key='$secret_key''
#Convert authorization to UPPERCASE

authorization1=`echo ${authorization^^}`

# 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": $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) 
DATA_CONTENT=$(jq \
        --null-input \
        --arg access_id   "${access_id}"   \
        --arg amount      "${amount}"      \
        --arg market      "${market}"      \
        --arg tonce       "${tonce}"       \
        --arg type        "${type}" \
        "${DATA_FORMAT}" \
    )
set -x 
# cURL call
curl -i  \
    -v \
    -H "authorization: Bearer  $authorization1 " \
    -H "Content-Type: application/json" \
     -d "${DATA_CONTENT}" \
      --url "$get_url"

I get the following error:


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  150k    0  150k    0     0   113k      0 --:--:--  0:00:01 --:--:--  113k
access_id=XXXX&amount=0.1&market=ARUSDT&tonce=1637401904541&type=sell&secret_key=XXXX
++ curl -i -v -H 'authorization: Bearer  396CC97A7C8A86F349E52BB41AE47387 ' -H 'Content-Type: application/json' -d '{
  "access_id": "03390D6C59336CF1D1",
  "amount": "0.1",
  "market": "ARUSDT",
  "tonce": "1637401904541",
  "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 0x561aa81e1c80)
> POST /v1/order/market HTTP/2
> Host: api.coinex.com
> user-agent: curl/7.68.0
> accept: */*
> authorization: Bearer  396CC97A7C8A86F349E52BB41AE47387 
> 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 
HTTP/2 200 
< date: Sat, 20 Nov 2021 09:51:46 GMT
date: Sat, 20 Nov 2021 09:51:46 GMT
< content-type: application/json
content-type: application/json
< content-length: 58
content-length: 58
< cf-cache-status: DYNAMIC
cf-cache-status: DYNAMIC
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
server: cloudflare
< cf-ray: 6b10c819aa2e752d-LHR
cf-ray: 6b10c819aa2e752d-LHR

< 
* Connection #0 to host api.coinex.com left intact
{"code": 25, "data": {}, "message": "Signature Incorrect"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant