gateio / gateapi-python

243 stars 91 forks source link

return empty when call finished orders or call my_trades in spot #115

Closed anouaran closed 1 year ago

anouaran commented 2 years ago

I'm using python script to call orders by /spot/orders work fine when I putt in status OPEN but when I butt FINISHED return empty same error when call my_trades, my code:

import time
import hashlib
import hmac
import requests

def gen_sign(method, url, query_string=None, payload_string=None):
    key = '***'        # api_key
    secret = '***'     # api_secret

    t = time.time()
    m = hashlib.sha512()
    m.update((payload_string or "").encode('utf-8'))
    hashed_payload = m.hexdigest()
    s = '%s\n%s\n%s\n%s\n%s' % (method, url, query_string or "", hashed_payload, t)
    sign = hmac.new(secret.encode('utf-8'), s.encode('utf-8'), hashlib.sha512).hexdigest()
    return {'KEY': key, 'Timestamp': str(t), 'SIGN': sign}

host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}

url = '/spot/orders'
query_param = 'currency_pair=BTC_USDT&status=open'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())

NOTE: I have orders filled and cancelled in this pair this method work fine. butt after try to get finished orders by status=finished not work give me empty return []. document: same error if I use GET /spot/my_trades :

revilwang commented 2 years ago

Are your finished orders recent? The API returns only orders or trades in the last 7 days by default.

anouaran commented 2 years ago

No my orders for last 3 months. but gate can't add this explain about return last 7 days. why status=open get orders without limit for 7 days. so how can get all orders in status=finished without limit in 7 days?

revilwang commented 2 years ago

You can set from and to parameters to control the time range for your query. Note the time range between from and to cannot exceed 30 days.

For open orders, they are still recent because they are alive in the trading market.

anouaran commented 2 years ago

in binance give me all traders just by pair. so what is the best way to get all traders without limit. can I use websocket good or same probleme

revilwang commented 2 years ago

The only way to retrieve historical trades and orders is to iterate your time range by 30 days. However you can set limit up to 1000 to retrieve as many records as possible in one request.