我目前正在使用gdax API python示例:https://github.com/danpaquin/gdax-python用于学习使用gdax sandbox api。
我正在尝试使用以下代码通过wss://ws-feed-public.sandbox.gdax.com从沙箱中获取实时交易价格:
import gdax, time
class myWebsocketClient(gdax.WebsocketClient):
def on_open(self):
self.url = "wss://ws-feed-public.sandbox.gdax.com"
self.products = ["LTC-USD"]
self.message_count = 0
print("Lets count the messages!")
def on_message(self, msg):
self.message_count += 1
if 'price' in msg and 'type' in msg:
print ("Message type:", msg["type"],
"\t@ {:.3f}".format(float(msg["price"])))
def on_close(self):
print("-- Goodbye! --")
wsClient = myWebsocketClient()
wsClient.start()
print(wsClient.url, wsClient.products)
while (wsClient.message_count < 500):
print ("\nmessage_count =", "{} \n".format(wsClient.message_count))
time.sleep(1)
wsClient.close()然而,我得到的价格几乎总是10000美元,而不是gdax沙箱网站上显示的价格:https://public.sandbox.gdax.com/
当使用实际的gdax websocket url: wss://ws-feed.gdax.com/时,价格似乎是正确的。
我想知道问题出在哪里。我们需要一种不同的方法来从沙箱中获取实时提要吗?
谢谢你的帮忙!
发布于 2018-01-31 11:42:13
如果你用BTC-USD代替LTC-USD运行你的代码,它会打印出来。除此之外,它工作得很好。
https://stackoverflow.com/questions/48355616
复制相似问题