擅长:python、mysql、java
<p>因为我的上一个示例代码过于简化,所以我提供了一个新的更复杂的版本,它可以工作并完成我想要它做的事情。(当然,除非有一种方法可以用更少的代码实现)</p>
<pre><code>import time
import json
from websocket import create_connection
ws=create_connection("wss://ws-feed.gdax.com")
ws.send(json.dumps({"type": "subscribe", "channels": [{"name": "heartbeat", "product_ids": ["BTC-EUR"],}]}))
newdict={}
def KonektorWebsocket():
dane=ws.recv()
dane=json.loads(dane)
print(json.dumps(dane, indent=4, sort_keys=True))
b=["last_trade_id","product_id","sequence","time","type"]
c=['ost_tranzakcja', 'parawalut','sekwencja','czas', 'typtranzakcji']
i=0
while i<5:
a = eval("dane.get('" + b[i] + "', None)")
print(" A: ", a)
print(" B[i]: ", b[i])
newdict[c[i]]=a
i=i+1
while True:
KonektorWebsocket()
print(newdict)
time.sleep(0.5)
</code></pre>