• 15-04-2022, 20:49:21
    #1
    Merhaba arkadaşlar aynı anda 2 farklı zamanın mum verilerini çekmek istiyorum bu şekilde yaptım fakat randıman alır mıyım ? bunun daha stabil olanı var mıdır ? yapılabilir mi ?
    yardımcı olacak arkadaşlara şimdiden tşk ederim. Amacım websocket ile 2 farklı zaman dilimine ait mum verileri aynı anda almak...


    import json, time
    from threading import Thread
    from websocket import create_connection, WebSocketConnectionClosedException
    from datetime import datetime





    def mum_verileri(dakika1,saat4):
    print(dakika1,saat4, "ZAMAN : ",datetime.now())




    def main():

    ws = None
    thread = None
    thread_running = False
    thread_keepalive = None
    def websocket_thread():
    global ws
    ws = create_connection("wss://stream.binance.com:9443/ws")
    ws.send(
    json.dumps(
    {
    "method": "SUBSCRIBE",
    "params": ["btcusdt@kline_1m"],
    "id": 1,
    }
    )
    )
    wst = create_connection("wss://stream.binance.com:9443/ws")
    wst.send(
    json.dumps(
    {
    "method": "SUBSCRIBE",
    "params": ["btcusdt@kline_4h"],
    "id": 1,
    }
    )
    )
    thread_keepalive.start()
    rakam = 0
    while not thread_running:

    try:
    data = ws.recv()
    datam = wst.recv()
    if data != "":
    msg = json.loads(data)
    msgi = json.loads(datam)
    else:
    msg = {}
    except ValueError as e:
    print(e)
    print("{} - data: {}".format(e, data))
    except Exception as e:
    print(e)
    print("{} - data: {}".format(e, data))
    else:

    if "result" not in msg:

    if msg['k']['i']=='1m':
    durum_1m = msg['k']['o']
    if msgi['k']['i']=='4h':
    durum_4h = msgi['k']['o']

    mum_verileri(durum_1m,durum_4h)

    try:
    if ws:
    ws.close()
    except WebSocketConnectionClosedException:
    pass
    finally:
    thread_keepalive.join()

    def websocket_keepalive(interval=30):
    global ws
    while ws.connected:
    ws.ping("keepalive")
    time.sleep(interval)

    thread = Thread(target=websocket_thread)
    thread_keepalive = Thread(target=websocket_keepalive)
    thread.start()


    if __name__ == "__main__":
    main()
  • 15-04-2022, 21:13:39
    #2
    cctx kütüphanesini yükleyerek oradan alabilirsiniz verileri
  • 15-04-2022, 21:50:58
    #3
    tempest adlı üyeden alıntı: mesajı görüntüle
    cctx kütüphanesini yükleyerek oradan alabilirsiniz verileri
    bu şekilde mi yapmak daha mantıklı binance ping limiti var limite bununla takılır mıyım ?

    import ccxt
    import time
    from datetime import datetime

    exchange = ccxt.binance()
    while True:
    try:
    bars = exchange.fetch_ohlcv('BTC/USDT', timeframe='1m')
    bars2 = exchange.fetch_ohlcv('BTC/USDT', timeframe='4h')
    print(bars)
    print(bars[-1][1]," : : ",bars2[-1][1])

    except:
    #telegram_bot_sendtext("Sistemde Hata oluştuuu !!!!!!")
    print("HATA VAR", datetime.datetime.now())
    continue
    time.sleep(1) # 30 sn ediyor...