All
Filter by:
How do I deposit cash into my account?
I need help with account verification
Why can't I access my account?
Are there any crypto withdrawal fees?
I need help signing into my account
Required Legal Notice: Virtual currencies, real risks. The only guarantee in crypto is risk. Read more
Required Legal Notice: Virtual currencies, real risks. The only guarantee in crypto is risk. Read more
Required Legal Notice: Virtual currencies, real risks. The only guarantee in crypto is risk. Warning: The value of your virtual currencies can rise or fall sharply, and your initial investment may be lost completely; virtual currencies are not covered by the guarantee funds that cover bank deposits; there is no legal mechanism on the virtual currencies market to prevent market manipulation or insider dealing; virtual currencies depend entirely on a specific computer technology and infrastructure, which in certain cases may be very recent and not yet adequately tested; if one loses the identification code or password giving access to the virtual wallet in which the virtual currency is stored, the currency held therein will be irretrievably lost; virtual currencies are currently accepted as a means of payment to a limited extent, and in most countries there is no legal obligation to accept them; for more information about the risks associated with an investment in virtual currencies, we advise you to read the Wikifin page What is a cryptocurrency? | Wikifin.
Required Legal Notice: Virtual currencies, real risks. The only guarantee in crypto is risk. Warning: The value of your virtual currencies can rise or fall sharply, and your initial investment may be lost completely; virtual currencies are not covered by the guarantee funds that cover bank deposits; there is no legal mechanism on the virtual currencies market to prevent market manipulation or insider dealing; virtual currencies depend entirely on a specific computer technology and infrastructure, which in certain cases may be very recent and not yet adequately tested; if one loses the identification code or password giving access to the virtual wallet in which the virtual currency is stored, the currency held therein will be irretrievably lost; virtual currencies are currently accepted as a means of payment to a limited extent, and in most countries there is no legal obligation to accept them; for more information about the risks associated with an investment in virtual currencies, we advise you to read the Wikifin page What is a cryptocurrency? | Wikifin.
Our WebSocket API can be accessed via any WebSocket capable programming language (Python, Javascript, C#, Go, etc.). Many programming languages offer WebSocket libraries that allow programmers to use a WebSocket interface without understanding the intricate details of the WebSocket protocol.
Python is one example that offers many different WebSocket libraries, so how does a programmer know which library to use, or how to use their chosen library to best effectiveness. The following provides our recommended Python WebSocket library and gives some examples of how to use the library in different scenarios.
Our recommended Python WebSocket library is the websocket-client library. The library is compatible with both Python 2 and Python 3, but for new code we recommended only using Python 3 as Python 2 is in the process of being deprecated.
The websocket-client library can be downloaded from the Python Package Index (pypi.org) and installed via the included setup.py file:
python setup.py install
or downloaded and installed simultaneously via the standard Python installation tool (pip):
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.
Synchronous WebSocket API Interface
# 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())
Asynchronous WebSocket API Interface
# 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())
Full details and instructions for the WebSocket client library are available via the library's code archive.