0
Follow
2
Followers
Exemplo de cotações de Websocket multimoeda da Binance - Python
Created 2021-06-15 20:16:47
4
4501
Eu usei o FMZ por quase 2 meses, e depois de executar algumas estratégias, o lucro foi bom, senti que era necessário fazer uma pequena contribuição para a comunidade, olhando para os exemplos atuais do Websocket, que não são muitos, contribuam para o exemplo de Websocket para obter várias moedas, é mais simples, obter informações, imprimir informações no ciclo.
A interface do rest é mais rápida para a estratégia de arbitragem de cobertura em várias moedas, mas a diferença é grande se houver mais moedas sendo negociadas ao mesmo tempo, esperamos que seja ú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

