gateio / gateapi-python

247 stars 92 forks source link

Is it possible that get last trade data from all pairs? #97

Closed mmterkc closed 2 years ago

mmterkc commented 2 years ago

Hi, I want to get last trade data from all pairs at same time. api_instance.list_trades method need currency pairs but list.tickers method don't need. How can I get last trades data from all pairs? I tried with for loop but it tooks a lot of time. Thanks.

revilwang commented 2 years ago

The API requires currency_pair to be present. The only way you can do is loop. But you can do it asynchronously with async_req set to true. But this way you are most likely to be blocked from request limits if you send them too fast.

mmterkc commented 2 years ago

How can i configure async_req true? than what is request limit? @revilwang Thanks

revilwang commented 2 years ago

Every method provides an async_req parameter. You can find it in the method's python doc.

The request limit can be found in the official API documents Frequency Limit Rules section.

Pitter24 commented 2 years ago

Hi mmterkc, don't do it via continuos request. Use the websockets method instead. Websockets is like listening to price coming in, you make you're "request" once and you're done.

Here's a piece of code you can use.

First connect to the websocket:

ws = create_connection("wss://api.gateio.ws/ws/v4/") ws.send(json.dumps({ "time": int(time.time()), "channel": "spot.trades", "event": "subscribe", # "unsubscribe" for unsubscription "payload": ["BTC_USDT"] })) resp = json.loads(ws.recv()) print(resp)

Then try this: while True: resp = json.loads(ws.recv())

Have a look a this and tell me if is it helpful

revilwang commented 2 years ago

Yes, websocket is preferred. We have provided gatews package which you can install with

pip install gatews

and the source code is in gate.io/gatews repo

mmterkc commented 2 years ago

Hi again I tried with gate ws. But I got "Got a an error: 'NoneType' object is not subscriptable" error. I use ws = create_connection("wss://api.gateio.ws/ws/v4/") ws.send(json.dumps({ "time": int(time.time()), "channel": "spot.trades", "event": "subscribe", # "unsubscribe" for unsubscription "payload": ['LIT3S_USDT', 'LYXE_USDT', 'BCHA_USDT', 'ZEC3S_USDT',"BTC_USDT","ETH_USDT",'HARD_USDT','GRIN3S_USDT', 'SLC_USDT', 'CATGIRL_USDT','ROSN_USDT', 'DOGE3L_USDT','ELON_USDT','GHST_USDT' , 'CTK_USDT','RACA3S_USDT', 'OPEN_USDT','MCRN_USDT', 'THEOS_USDT', 'SYS_USDT', 'SPA_USDT', 'AAVE3S_USDT', 'NII_USDT', 'VGX_USDT','RSR_USDT', 'UNISTAKE_USDT', 'STRONG_USDT', 'DPY_USDT', 'RBC_USDT', 'KFC_USDT', 'METIS_USDT', 'BIRD_USDT', 'MEAN_USDT', 'STETH_USDT', 'ALPA_USDT', 'SWINGBY_USDT', 'WAVES3L_USDT', 'DUSK_USDT', 'WAVES_USDT'] })) resp = json.loads(ws.recv()) print(resp) How can I solve NoneType error I want to subscribe all coin USDT pairs .There are an estimated 1500 pairs