0
Follow
2
Followers
Ejemplo de cotizaciones de WebSocket multidivisa de Binance: Python
Created 2021-06-15 20:16:47
4
4499
He estado usando FMZ por casi 2 meses, he usado varias estrategias y he ganado bastante, me siento obligado a hacer una pequeña contribución a la comunidad, si veo los ejemplos de Websocket, no hay muchos, contribuya a un ejemplo de Websocket de múltiples monedas, es más simple, obtenga las transacciones, imprima las transacciones en el ciclo.
La respuesta de la interfaz de rest es más rápida que en las estrategias de arbitraje de cobertura de monedas múltiples, y la diferencia es bastante grande si se negocian más monedas al mismo tiempo, espero que sea útil.
python
#websocket 更新 行情
# {
# "e":"bookTicker", // 事件类型
# "u":400900217, // 更新ID
# "E": 1568014460893, // 事件推送时间
# "T": 1568014460891, // 撮合时间
# "s":"BNBUSDT", // 交易对
# "b":"25.35190000", // 买单最优挂单价格
# "B":"31.21000000", // 买单最优挂单数量
# "a":"25.36520000", // 卖单最优挂单价格
# "A":"40.66000000" // 卖单最优挂单数量
# }
def on_msg(msg) : #更新行情
if msg is not None and len(msg)>0:
bookTicker = json.loads(msg)
else:
# Log('book tick msg is none')
return
Log(bookTicker)
def main():
SetErrorFilter("502:|503:|tcp|character|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused|Unknown")
trade_symbols = 'TRX,ZEC,DENT,BLZ,ENJ,ZIL,MANA,ONT,XMR,ICX,SC,THETA,CVC,BAT,STMX,VET,IOST,NEO,MTL,DASH,KNC,ZRX,IOTA'.split(',')
ary_symbol_streams = []
for i in range(len(trade_symbols)):
symbol = trade_symbols[i].lower()
stream_client = Dial(f"wss://fstream.binance.com/ws/{symbol}usdt@bookTicker|reconnect=true")
ary_symbol_streams.append(stream_client)
while (true):
for item in ary_symbol_streams:
#-2读取最新数据
msg = item.read(-2)
on_msg(msg)
Related Recommendations
How to Specify Different Versions of Data for the Rented Strategy by Its Rental Code MetadataAdvanced Tutorial for FMZ Quant platform Strategy WritingElementary Tutorial for FMZ Quant platform Strategy WritingGet Started with FMZ Quant PlatformSECURITY BUGI keep getting error: Exchange_GetAccount: Invalid ContractTypeWe have an incredibly profitable market making algorithm for sideways markets on Bitmex - but need expert to help eliminate wait times during downward volatility in the marketError with deribitLimitations of the backtesting engineHow to install ta-lib on linux docker?
Comment
All comments (4)
Dial("wss://stream.binance.com:9443/stream?streams=btcusdt@aggTrade/ethusdt@aggTrade/axsusdt@aggTrade/ltcusdt@aggTrade/dogeusdt@aggTrade|reconnect=true");
5 years ago
- 1

