gateio / gateapi-go

100 stars 32 forks source link

ListMyTrades return empty data #2

Closed TuringZhu closed 3 years ago

TuringZhu commented 4 years ago

I call list my trades api with parameter order and no page and limit,

the api return following data

{
    "message": ""
}

and http code is 404. status is "404 not found"

but, when I query with shell with the following code. I can get correct data:

the key secret and order_id all correct

can someone tell me why?

key="xxxxx"
secret="xxxx"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/spot/my_trades"
query_param="currency_pair=BTC_USDT&order_id=ORDER_ID"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf $body_param | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf $sign_string | openssl sha512 -hmac "$secret" | awk '{print $NF}')

full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
    -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
revilwang commented 4 years ago

Please provide some snippet of your not-working-as-expected code

TuringZhu commented 4 years ago

sometimes it return expected data, but sometimes it not.

package main

import (
    "fmt"
    "github.com/antihax/optional"
    "github.com/gateio/gateapi"
)

var (
    err    error
    client *gateapi.APIClient
)

func main() {
    client = gateapi.NewAPIClient(gateapi.NewConfiguration())
    client.SetKeySecret("MY_KEY", "MY_SECRET")
    client.ChangeBasePath("MY_PROXY")
    api := client.SpotApi
    trades,_,err:= api.ListMyTrades(nil, "BTC_USDT", &gateapi.ListMyTradesOpts{
        Page:optional.NewInt32(1),
        Limit:optional.NewInt32(5),
    })
    if err != nil {
        fmt.Println(err)
    }
    for _, v:= range  trades {
        fmt.Println(v)
    }
}

for gateio only allowing ip access sensitive information with specified ip in whitelist, I configured proxy with nginx:

server {
    listen       80;
    server_name MY_DOMAINNAME;
    access_log  logs/gateio-access.log main;
    error_log   logs/gateio-error.log; 
    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            api.gateio.ws;
        proxy_pass https://api.gateio.ws:443/;
    }
}
revilwang commented 4 years ago

Change the error output like this:

    if err != nil {
        if e, ok := err.(gateapi.GenericOpenAPIError); ok {
            fmt.Println(e.Body())
        } else {
            fmt.Println(err.Error())
        }
    } else {
        fmt.Println(result)
    }

And when it's not returning the expected data. Please provide the response body content

TuringZhu commented 4 years ago

OK

TuringZhu commented 4 years ago

@revilwang

I'm sorry to disturb you, but I have a question and I don't know where to find the answer.

That is, how many times can I call the https://api.gateio.ws/api/v4 per second?

I'm worried that it cannot be called due to a frequency limit error

revilwang commented 4 years ago

Spot APIs limit 300 requests/second per IP. Futures private APIs limit 200 requests/second per user.

P.S. request limits will be added into API documentation on next update.

TuringZhu commented 4 years ago

tks👍