All
Filtreleme ölçütü:
Hesabıma nasıl nakit yatırabilirim?
Hesap doğrulaması ile ilgili yardıma ihtiyacım var
Hesabıma neden erişemiyorum?
Kripto para çekimlerinde herhangi bir ücret var mı?
Hesabıma giriş yapmak için yardıma ihtiyacım var
WebSocket API'mize, WebSocket özellikli herhangi bir programlama dili (Python, Javascript, C#, Go vb.) aracılığıyla erişilebilir. Birçok programlama dili, programcıların WebSocket protokolünün karmaşık ayrıntılarını anlamadan bir WebSocket arayüzü kullanmalarına olanak tanıyan WebSocket kütüphaneleri sunar.
Python, birçok farklı WebSocket kütüphanesi sunan bir örnektir, peki bir programcı hangi kütüphaneyi kullanacağını veya seçtiği kütüphaneyi en iyi şekilde nasıl kullanacağını nasıl bilebilir? Aşağıda, önerilen Python WebSocket kütüphanemiz ve kütüphanenin farklı senaryolarda nasıl kullanılacağına dair bazı örnekler sunulmaktadır.
Önerdiğimiz Python WebSocket kütüphanesi websocket-client kütüphanesidir. Kütüphane hem Python 2 hem de Python 3 ile uyumludur, ancak yeni kodlar için yalnızca Python 3 kullanmanızı öneririz, çünkü Python 2 kullanımdan kaldırılma sürecindedir.
websocket-client kütüphanesi, Python Paket Dizini'nden (pypi.org) indirilebilir ve dahil edilen setup.py dosyası aracılığıyla kurulabilir:
python setup.py install
veya standart Python kurulum aracı (pip) aracılığıyla aynı anda indirilip kurulabilir:
pip install websocket-client
The WebSocket client library can be used to create a synchronous (blocking) WebSocket client or an asynchronous (non blocking, event driven) client. Both versions can interact with our API successfully, so the choice would depend upon the specific requirements of the implementation (such as whether other tasks needed to happen in parallel).
For example, a simple market price watching app would be able to use a synchronous client that simply waited for new market data and compared the market price to a specified value, while a full featured trading bot would need to use an asynchronous client with the market data feeds in separate threads (so that the analysis and trading tasks could continue in parallel).
The following are basic examples of both synchronous and asynchronous clients, which can be used a a starting point for more complex API code.
Senkron WebSocket API Arayüzü
# Import WebSocket client libraryfrom websocket import create_connection# Connect to WebSocket API and subscribe to trade feed for XBT/USD and XRP/USDws = create_connection("wss://ws.kraken.com/")ws.send('{"event":"subscribe", "subscription":{"name":"trade"}, "pair":["XBT/USD","XRP/USD"]}')# Infinite loop waiting for WebSocket datawhile True: print(ws.recv())
Asenkron WebSocket API Arayüzü
# Import WebSocket client library (and others)import websocketimport _threadimport time# Define WebSocket callback functionsdef ws_message(ws, message): print("WebSocket thread: %s" % message)def ws_open(ws): ws.send('{"event":"subscribe", "subscription":{"name":"trade"}, "pair":["XBT/USD","XRP/USD"]}')def ws_thread(*args): ws = websocket.WebSocketApp("wss://ws.kraken.com/", on_open = ws_open, on_message = ws_message) ws.run_forever()# Start a new thread for the WebSocket interface_thread.start_new_thread(ws_thread, ())# Continue other (non WebSocket) tasks in the main threadwhile True: time.sleep(5) print("Main thread: %d" % time.time())
WebSocket istemci kütüphanesinin tüm ayrıntıları ve talimatları kütüphanenin kod arşivinde mevcuttur.