Collection of clients and methods to interact with the cryptocurrency exchange Kraken.
Project description
Welcome to the Python SDK for the Kraken Cryptocurrency Exchange! 🦑
This is an unofficial collection of REST and websocket clients to interact with the Kraken exchange API in Python.
There is no guarantee that this software will work flawlessly at this or later times. Everyone has to look at the underlying source code themselves and consider whether this is appropriate for their own use.
Of course, no responsibility is taken for possible profits or losses. No one should be motivated or tempted to invest assets in speculative forms of investment.
Table of Contents
- Installation
- Spot Clients Example Usage
- Futures Clients Example Usage
- Spot Clients Documentation
- Futures Clients Documentation
- Notes
- References
Installation
python3 -m pip install python-kraken-sdk
Spot Clients Example Usage
REST API
... can be found in /examples/examples.py
from kraken.spot.client import User, Market, Trade, Funding, Staking
def main() -> None:
key = 'Kraken pub key'
secret = 'Kraken secret key'
# ____USER________
user = User(key=key, secret=secret)
print(user.get_account_balance())
print(user.get_open_orders())
# ____MARKET_______
market = Market(key=key, secret=secret)
print(market.get_ticker(pair='BTCUSD'))
# ____TRADE________
trade = Trade(key=key, secret=secret)
print(trade.create_order(
ordertype='limit',
side='buy',
volume=1,
pair='BTC/EUR',
price=20000
))
# ____FUNDING______
funding = Funding(key=key, secret=secret)
print(funding.withdraw_funds(asset='DOT', key='MyPolkadotWallet', amount=200))
print(funding.cancel_widthdraw(asset='DOT', refid='<some id>'))
# ____STAKING______
staking = Staking(key=key, secret=secret)
print(staking.list_stakeable_assets())
print(staking.stake_asset(asset='DOT', amount=20, method='polkadot-staked'))
if __name__ == '__main__':
main()
Websockets
... can be found in /examples/ws_examples.py
import asyncio
from kraken.spot.client import WsClient
from kraken.spot.websocket.websocket import KrakenSpotWSClient
async def main() -> None:
key = 'kraken public key'
secret = 'kraken secret key'
class Bot(KrakenSpotWSClient):
async def on_message(self, msg) -> None:
if 'event' in msg:
if msg['event'] in ['pong', 'heartbeat']: return
print(msg)
# await self._client.create_order(
# ordertype='limit',
# side='buy',
# pair='BTC/EUR',
# price=20000,
# volume=1
# )
# ... it is also possible to call regular REST endpoints
# but using the websocket messages is more efficient
bot = Bot(WsClient(key=key, secret=secret))
await bot.subscribe(pair=['BTC/EUR'], subscription={ 'name': 'ticker' }, private=False)
await bot.subscribe(subscription={ 'name': 'ownTrades' }, private=True)
while True: await asyncio.sleep(6)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
Futures Clients Example Usage
REST API
... can be found in /examples/futures_examples.py
from kraken.futures.client import Market, User, Trade, Funding
def main() -> None:
demo: bool = False
key = 'Kraken futures public key'
secret = 'Kraken futures secret key'
# ____USER__________
user = User(key=key,secret=secret, sandbox=demo)
print(user.get_wallets())
print(user.get_open_orders())
print(user.get_open_positions())
print(user.get_subaccounts())
# ....
# ____MARKET_________
market = Market()
print(market.get_ohlc(tick_type='trade', symbol='PI_XBTUSD', resolution='5m'))
priv_market = Market(key=key,secret=secret, sandbox=demo)
print(priv_market.get_fee_schedules_vol())
print(priv_market.get_execution_events())
# ....
# ____TRADE_________
trade = Trade(key=key, secret=secret, sandbox=demo)
print(trade.get_fills())
print(trade.create_batch_order(
batchorder_list = [{
"order": "send",
"order_tag": "1",
"orderType": "lmt",
"symbol": "PI_XBTUSD",
"side": "buy",
"size": 1,
"limitPrice": 12000,
"cliOrdId": "another-client-id"
}, {
"order": "send",
"order_tag": "2",
"orderType": "stp",
"symbol": "PI_XBTUSD",
"side": "buy",
"size": 1,
"limitPrice": 10000,
"stopPrice": 110000,
}, {
"order": "cancel",
"order_id": "e35dsdfsdfsddd-8a30-4d5f-a574-b5593esdf0",
}, {
"order": "cancel",
"cliOrdId": "some-client-id",
}],
))
print(trade.cancel_all_orders())
print(trade.create_order(
orderType='lmt', side='buy', size=1, limitPrice=4, symbol='pf_bchusd'
))
# ....
# ____FUNDING_______
funding = Funding(key=key, secret=secret, sandbox=demo)
# ....
if __name__ == '__main__':
main()
Websockets
... not implemented so far
Sport Clients Documentation
User
Trade
Method | Documentation |
---|---|
create_order |
https://docs.kraken.com/rest/#operation/addOrder |
create_order_batch |
https://docs.kraken.com/rest/#operation/addOrderBatch |
edit_order |
https://docs.kraken.com/rest/#operation/editOrder |
cancel_order |
https://docs.kraken.com/rest/#operation/cancelOrder |
cancel_all_orders |
https://docs.kraken.com/rest/#operation/cancelAllOrders |
cancel_all_orders_after_x |
https://docs.kraken.com/rest/#operation/cancelAllOrdersAfter |
cancel_order_batch |
https://docs.kraken.com/rest/#operation/cancelOrderBatch |
Market
Method | Documentation |
---|---|
get_assets |
https://docs.kraken.com/rest/#operation/getAssetInfo |
get_tradable_asset_pair |
https://docs.kraken.com/rest/#operation/getTradableAssetPairs |
get_ticker |
https://docs.kraken.com/rest/#operation/getTickerInformation |
get_ohlc |
https://docs.kraken.com/rest/#operation/getOHLCData |
get_order_book |
https://docs.kraken.com/rest/#operation/getOrderBook |
get_recent_trades |
https://docs.kraken.com/rest/#operation/getRecentTrades |
get_recend_spreads |
https://docs.kraken.com/rest/#operation/getRecentSpreads |
get_system_status |
Funding
Method | Documentation |
---|---|
get_deposit_methods |
https://docs.kraken.com/rest/#operation/getDepositMethods |
get_deposit_address |
https://docs.kraken.com/rest/#operation/getDepositAddresses |
get_recend_deposits_status |
https://docs.kraken.com/rest/#operation/getStatusRecentDeposits |
get_withdrawal_info |
https://docs.kraken.com/rest/#operation/getWithdrawalInformation |
withdraw_funds |
https://docs.kraken.com/rest/#operation/withdrawFund |
get_recend_withdraw_status |
https://docs.kraken.com/rest/#operation/getStatusRecentWithdrawals |
cancel_withdraw |
https://docs.kraken.com/rest/#operation/cancelWithdrawal |
wallet_transfer |
https://docs.kraken.com/rest/#operation/walletTransfer |
Staking
Method | Documentation |
---|---|
stake_asset |
https://docs.kraken.com/rest/#operation/stake |
unstake_asset |
https://docs.kraken.com/rest/#operation/unstake |
list_stakeable_assets |
https://docs.kraken.com/rest/#operation/getStakingAssetInfo |
get_pending_staking_transactions |
https://docs.kraken.com/rest/#operation/getStakingPendingDeposits |
list_staking_transactions |
https://docs.kraken.com/rest/#operation/getStakingTransactions |
WsClient
Method | Documentation |
---|---|
get_ws_token |
https://docs.kraken.com/rest/#tag/Websockets-Authentication |
create_order |
https://docs.kraken.com/websockets/#message-addOrder |
edit_order |
https://docs.kraken.com/websockets/#message-editOrder |
cancel_order |
https://docs.kraken.com/websockets/#message-cancelOrder |
cancel_all_orders |
https://docs.kraken.com/websockets/#message-cancelAll |
cancel_all_orders_after |
https://docs.kraken.com/websockets/#message-cancelAllOrdersAfter |
subscribe |
|
unsubscribe |
|
get_available_subscriptions |
Futures Client Documentation
User
Trade
Market
Funding
Method | Documentation |
---|---|
get_historical_funding_rates |
https://docs.futures.kraken.com/#http-api-trading-v3-api-historical-funding-rates-historicalfundingrates |
initiate_wallet_transfer |
https://docs.futures.kraken.com/#http-api-trading-v3-api-transfers-initiate-wallet-transfer |
initiate_subccount_transfer |
https://docs.futures.kraken.com/#http-api-trading-v3-api-transfers-initiate-sub-account-transfer |
initiate_withdrawal_to_spot_wallet |
https://docs.futures.kraken.com/#http-api-trading-v3-api-transfers-initiate-withdrawal-to-spot-wallet |
Notes:
- Pull requests will be ignored until the owner finished the core idea
References
- https://docs.kraken.com/websockets
- https://docs.kraken.com/rest/
- https://docs.futures.kraken.com/
- https://support.kraken.com/hc/en-us/sections/360012894412-Futures-API
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_kraken_sdk-0.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2ceb0f7a9606e2b38af873d59193f4fb82fe9dcf4894fb602c14e6e45a28b5 |
|
MD5 | debc93802b358169fc513780a3731416 |
|
BLAKE2b-256 | 137606c3262bdf6b3903d7d31a0535c40bd16f0ea7dad5d4abf9dc168f3f05c8 |