Futures REST
- class kraken.futures.User(key: str = '', secret: str = '', url: str = '', *, sandbox: bool = False)
Bases:
KrakenFuturesBaseAPIClass that implements the Kraken Futures user client
If the sandbox environment is chosen, the keys must be generated from here: https://demo-futures.kraken.com/settings/api
- Parameters:
key (str, optional) – Futures API public key (default:
"")secret (str, optional) – Futures API secret key (default:
"")url (str, optional) – Alternative URL to access the Futures Kraken API (default: https://futures.kraken.com)
sandbox (bool, optional) – If set to
Truethe URL will be https://demo-futures.kraken.com (default:False)
Futures User: Create the user client1>>> from kraken.futures import User 2>>> user = User() # unauthenticated 3>>> user = User(key="api-key", secret="secret-key") # authenticated
Futures User: Create the user client as context manager1>>> from kraken.futures import User 2>>> with User(key="api-key", secret="secret-key") as user: 3... print(user.get_wallets())
- check_trading_enabled_on_subaccount(subaccountUid: str, *, extra_params: dict | None = None) dict
Checks if trading is enabled or disabled on the specified subaccount.
Requires the
General API - Full Accesspermission in the API key settings.This endpoint is only available for institutional clients and is not tested so far and results in
KrakenAuthenticationError.- Returns:
The open futures positions/orders
- Return type:
dict
Futures User: Check if trading is enabled on a subaccount1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.set_trading_on_subaccount( 4... subaccountUid="778387bh61b-f990-4128-16a7-f4ab669a9b", 5... ) 6{ 7 "tradingEnabled": False 8}
- get_account_log(before: str | int | None = None, count: str | int | None = None, from_: str | int | None = None, info: str | None = None, since: str | int | None = None, sort: str | None = None, to: str | None = None, *, extra_params: dict | None = None) dict
Get the historical events of the user’s account. This is not available in the Kraken demo/sandbox environment.
Requires at least the
General API - Read Onlypermission in the API key settings.- Parameters:
before (str | int, optional) – Filter to only return results before a specific timestamp or date
count (str | int, optional) – Defines the maximum number of results (max:
500)from (str | int, optional) – Defines the first id to start with
info (str, optional) – Filter by info (e.g.,:
futures liquidation)since (str | int, optional) – Defines the first entry to begin with by item
sort (str, optional) – Sort the results
to (str, optional) – Id of the last entry
- Returns:
The account log
- Return type:
dict
Futures User: Get the user’s account log1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_account_log(before="2023-04-04T16:10:46.260Z", count=1) 4{ 5 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 6 'logs': [ 7 { 8 'asset': 'eth', 9 'contract': None, 10 'booking_uid': 'be3d0e19-887a-4a8e-b8f6-32b9ef7f04ab', 11 'collateral': None, 12 'date': '2023-04-04T16:10:46.260Z', 13 'execution': None, 14 'fee': None, 15 'funding_rate': None, 16 'id': 10, 17 'info': 'admin transfer', 18 'margin_account': 'ETH', 19 'mark_price': None, 20 'new_average_entry_price': None, 21 'new_balance': 2.6868286287, 22 'old_average_entry_price': None, 23 'old_balance': 0.0, 24 'realized_funding': None, 25 'realized_pnl': None, 26 'trade_price': None, 27 'conversion_spread_percentage': None 28 } 29 ], ... 30}
- get_account_log_csv(*, extra_params: dict | None = None) requests.Response
Return the account log as csv, for example to export it. This is not available in the Kraken demo/sandbox environment.
Requires at least the
General API - Read Onlypermission in the API key settings.Futures User: Get the account log and export as CSV1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> response = user.get_account_log_csv() 4>>> with open(f"account_log.csv", "wb") as file: 5... for chunk in response.iter_content(chunk_size=512): 6... if chunk: 7... file.write(chunk)
- get_execution_events(before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, tradeable: str | None = None, *, extra_params: dict | None = None) dict
Retrieve the order/position execution events of this user. The returned
continuation_tokencan be used to request more data.Requires at least the
General API - Read Onlypermission in the API key settings.(If you are facing some timeout error, just set the clients attribute
TIMEOUTtemporarily to the desired amount in seconds.)- Parameters:
before (int, optional) – Filter by time
continuation_token (str, optional) – Token that can be used to continue requesting historical events
since (int, optional) – Filter by a specifying a start point
sort (str, optional) – Sort the results
tradeable (str, optional) – The asset to filter for
- Returns:
The user-specific execution events
- Return type:
dict
Futures User: Get the user’s historical execution events1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_execution_events( 4... tradeable="PF_SOLUSD", 5... since=1668989233, 6... before=1668999999, 7... sort="asc" 8... ) 9{ 10 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 11 'continuationToken': 'alp81a', 12 'elements': [{ 13 'event': { 14 'execution': { 15 'execution': { 16 'limitFilled': false, 17 'makerOrder': { 18 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 19 'direction': 'Buy', 20 'filled': '2332.12239', 21 'lastUpdateTimestamp': 1605126171852, 22 'limitPrice': '1234.56789', 23 'orderType': 'lmt', 24 'quantity': '1234.56789', 25 'reduceOnly': false, 26 'timestamp': 1605126171852, 27 'tradeable': 'pi_xbtusd', 28 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 29 }, 30 'makerOrderData': { 31 'fee': '12.56789', 32 'positionSize': '2332.12239' 33 }, 34 'markPrice': '27001.56', 35 'oldTakerOrder': { 36 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 37 'direction': 'Buy', 38 'filled': '2332.12239', 39 'lastUpdateTimestamp': 1605126171852, 40 'limitPrice': '27002.56789', 41 'orderType': 'string', 42 'quantity': '0.156789', 43 'reduceOnly': false, 44 'timestamp': 1605126171852, 45 'tradeable': 'pi_xbtusd', 46 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 47 }, 48 'price': '2701.8163', 49 'quantity': '0.156121', 50 'takerOrder': { 51 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 52 'direction': 'Buy', 53 'filled': '0.156121', 54 'lastUpdateTimestamp': 1605126171852, 55 'limitPrice': '2702.91', 56 'orderType': 'lmt', 57 'quantity': '0.156121', 58 'reduceOnly': false, 59 'timestamp': 1605126171852, 60 'tradeable': 'pi_xbtusd', 61 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 62 }, 63 'takerOrderData': { 64 'fee': '12.83671', 65 'positionSize': '27012.91' 66 }, 67 'timestamp': 1605126171852, 68 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 69 'usdValue': '2301.56789' 70 }, 71 } 72 }, 73 'timestamp': 1605126171852, 74 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 75 }, ...], 76 'len': 0, 77 'serverTime': '2023-04-06T21:11:31.677Z' 78}
- get_notifications(*, extra_params: dict | None = None) dict
Retrieve the latest notifications from the Kraken Futures API
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
Notifications
- Return type:
dict
Futures User: Get the latest notifications1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_notifications() 4{ 5 'result': 'success', 6 'notifications': [{ 7 'type': 'general', 8 'priority': 'high', 9 'note': 'Market in post only mode until 4pm.' 10 }], 11 'serverTime': '2023-04-04T18:01:39.729Z' 12}
- get_open_orders(*, extra_params: dict | None = None) dict
Retrieve the open orders.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
The open futures positions/orders
- Return type:
dict
Futures User: Get open orders1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_open_orders() 4{ 5 'result': 'success', 6 'openOrders': [{ 7 'order_id': '2ce038ae-c144-4de7-a0f1-82f7f4fca864', 8 'symbol': 'pi_ethusd', 9 'side': 'buy', 10 'orderType': 'lmt', 11 'limitPrice': 1200, 12 'unfilledSize': 100, 13 'receivedTime': '2023-04-07T15:18:04.699Z', 14 'status': 'untouched', 15 'filledSize': 0, 16 'reduceOnly': False, 17 'lastUpdateTime': '2023-04-07T15:18:04.699Z' 18 }, { 19 'order_id': 'c8135f52-2a86-4e26-b629-43cc37da9dbf', 20 'symbol': 'pi_ethusd', 21 'side': 'buy', 22 'orderType': 'take_profit', 23 'limitPrice': 1860, 24 'stopPrice': 1880.4, 25 'unfilledSize': 10, 26 'receivedTime': '2023-04-07T15:14:25.995Z', 27 'status': 'untouched', 28 'filledSize': 0, 29 'reduceOnly': False, 30 'triggerSignal': 'last', 31 'lastUpdateTime': '2023-04-07T15:14:25.995Z' 32 }, { 33 'order_id': 'e58ed100-1fb8-4e6c-a5ea-1cf85b0f0654', 34 'symbol': 'pi_ethusd', 35 'side': 'buy', 36 'orderType': 'take_profit', 37 'limitPrice': 1860, 38 'stopPrice': 1880.4, 39 'unfilledSize': 10, 40 'receivedTime': '2023-04-07T15:12:08.131Z', 41 'status': 'untouched', 42 'filledSize': 0, 43 'reduceOnly': False, 44 'triggerSignal': 'last', 45 'lastUpdateTime': '2023-04-07T15:12:08.131Z' 46 }, { 47 'order_id': 'c8776f6e-c29e-4c6a-83ee-2d3cc6781cda', 48 'symbol': 'pf_ethusd', 49 'side': 'buy', 50 'orderType': 'take_profit', 51 'limitPrice': 1860, 52 'stopPrice': 5, 53 'unfilledSize': 0.5, 54 'receivedTime': '2023-04-07T14:57:37.849Z', 55 'status': 'untouched', 56 'filledSize': 0, 57 'reduceOnly': True, 58 'triggerSignal': 'last', 59 'lastUpdateTime': '2023-04-07T14:57:37.849Z' 60 }, ...], 61 'serverTime': '2023-04-07T15:30:29.911Z' 62}
- get_open_positions(*, extra_params: dict | None = None) dict
List the open positions of the user.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
Information about the open positions
- Return type:
dict
Futures User: Get the user’s open positions1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_open_positions() 4{ 5 'result': 'success', 6 'openPositions': [ 7 { 8 'side': 'short', 9 'symbol': 'pi_xbtusd', 10 'price': 27523.749993345933, 11 'fillTime': '2023-04-05T12:31:21.410Z', 12 'size': 8000, 13 'unrealizedFunding': 0.00005879463852989987 14 }, 15 ], 16 'serverTime': '2023-04-06T16:12:15.410Z' 17}
- get_order_events(before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, tradeable: str | None = None, *, extra_params: dict | None = None) dict
Retrieve information about the user-specific order events including opened, closed, filled, etc. The returned
continuation_tokencan be used to request more data.Requires at least the
General API - Read Onlypermission in the API key settings.- Parameters:
before (int, optional) – Filter by time
continuation_token (str, optional) – Token that can be used to continue requesting historical events
since (int, optional) – Filter by a specifying a start point
sort (str, optional) – Sort the results
tradeable (str, optional) – The asset to filter for
- Returns:
The user-specific order events
- Return type:
dict
Futures User: Get the user’s historical order events1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_order_events(tradeable="PF_SOLUSD", since=1668989233, before=1668999999, sort="asc") 4{ 5 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 6 'continuationToken': 'simb178', 7 'elements': [{ 8 'event': { 9 'OrderPlaced': { 10 'order': { 11 'accountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 12 'direction': 'Sell', 13 'filled': '12.011', 14 'lastUpdateTimestamp': 1605126171852, 15 'limitPrice': '28900.0', 16 'orderType': 'string', 17 'quantity': '13.12', 18 'reduceOnly': false, 19 'timestamp': 1605126171852, 20 'tradeable': 'pi_xbtusd', 21 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 22 }, 23 'reason': 'string', 24 'reducedQuantity': 'string' 25 } 26 }, 27 'timestamp': 1605126171852, 28 'uid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0' 29 }, ...], 30 'len': 10, 31 'serverTime': '2023-04-05T12:31:42.677Z' 32}
- get_subaccounts(*, extra_params: dict | None = None) dict
List the subaccounts of the user.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
Information about the user owned subaccounts
- Return type:
dict
Futures User: Get the user’s subaccounts1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_subaccounts() 4{ 5 'result': 'success', 6 'serverTime': '2023-04-04T18:03:33.696Z', 7 'masterAccountUid': 'f7d5571c-6d10-4cf1-944a-048d25682ed0', 8 'subaccounts': [] 9}
- get_trigger_events(before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, tradeable: str | None = None, *, extra_params: dict | None = None) dict
Retrieve information about trigger events.
The returned
continuation_tokencan be used to request more data.Requires at least the
General API - Read Onlypermission in the API key settings.- Parameters:
before (int, optional) – Filter by time
continuation_token (str, optional) – Token that can be used to continue requesting historical events
since (int, optional) – Filter by a specifying a start point
sort (str, optional) – Sort the results
tradeable (str, optional) – The asset to filter for
- Returns:
The user-specific trigger events
- Return type:
dict
Futures User: Get the user’s historical trigger events1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_trigger_events( 4... tradeable="PF_SOLUSD", 5... since=1668989233, 6... before=1668999999, 7... sort="asc" 8... ) 9{ 10 "accountUid": "f7d5571c-6d10-4cf1-944a-048d25682ed0", 11 "continuationToken": "c3RyaW5n", 12 "elements": [{ 13 "event": { 14 "OrderTriggerPlaced": { 15 "order": { 16 "accountId": 0.0, 17 "accountUid": "f7d5571c-6d10-4cf1-944a-048d25682ed0", 18 "direction": "Buy", 19 "lastUpdateTimestamp": 1605126171852, 20 "limitPrice": "29000.0", 21 "orderType": "lmt", 22 "quantity": "1.0", 23 "reduceOnly": false, 24 "timestamp": 1605126171852, 25 "tradeable": "pi_xbtusd", 26 "triggerOptions": { 27 "trailingStopOptions": { 28 "maxDeviation": "0.1", 29 "unit": "Percent" 30 }, 31 "triggerPrice": "29200.0", 32 "triggerSide": "Sell", 33 "triggerSignal": "trade" 34 }, 35 "uid": "f7d5571c-6d10-4cf1-944a-048d25682ed0" 36 }, 37 "reason": "maxDeviation triggered" 38 } 39 }, 40 "timestamp": 1605126171852, 41 "uid": "f7d5571c-6d10-4cf1-944a-048d25682ed0" 42 }, ...], 43 "len": 10, 44 "serverTime": "2022-03-31T20:38:53.677Z" 45}
- get_unwind_queue(*, extra_params: dict | None = None) dict
Retrieve information about the percentile of the open position in case of unwinding.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
Information about unwind queue
- Return type:
dict
Futures User: Get the user’s unwind queue1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_unwind_queue() 4{ 5 'result': 'success', 6 'serverTime': '2023-04-04T18:05:01.328Z', 7 'queue': [ 8 { 'symbol': 'PF_UNIUSD', 'percentile': 20 } 9 ] 10}
- get_wallets(*, extra_params: dict | None = None) dict
Lists the current wallet balances of the user.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
Information about the current balances of the user
- Return type:
dict
Futures User: Get the user’s wallets1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.get_wallets() 4{ 5 'result': 'success', 6 'accounts': { 7 'fi_xbtusd': { 8 'auxiliary': { 9 'usd': 0, 10 'pv': 0.0, 11 'pnl': 0.0, 12 'af': 0.0, 13 'funding': 0.0 14 }, 15 'marginRequirements': { 16 'im': 0.0, 17 'mm': 0.0, 18 'lt': 0.0, 19 'tt': 0.0 20 }, 21 'triggerEstimates': { 22 'im': 0, 23 'mm': 0, 24 'lt': 0, 25 'tt': 0 26 }, 27 'balances': { 28 'xbt': 0.0 29 }, 30 'currency': 'xbt', 31 'type': 'marginAccount' 32 }, 33 'cash': { 34 'balances': { 35 'eur': 4567.7117591172, 36 'gbp': 4002.4975584765, 37 'bch': 39.3081761006, 38 'usd': 5000.0, 39 'xrp': 10055.1019587339, 40 'eth': 2.6868286287, 41 'usdt': 4999.3200924674, 42 'usdc': 4999.8300057798, 43 'ltc': 53.9199827456, 44 'xbt': 0.1785169809 45 }, 46 'type': 'cashAccount' 47 }, 48 'flex': { 49 'currencies': {}, 50 'initialMargin': 0.0, 51 'initialMarginWithOrders': 0.0, 52 'maintenanceMargin': 0.0, 53 'balanceValue': 0.0, 54 'portfolioValue': 0.0, 55 'collateralValue': 0.0, 56 'pnl': 0.0, 57 'unrealizedFunding': 0.0, 58 'totalUnrealized': 0.0, 59 'totalUnrealizedAsMargin': 0.0, 60 'availableMargin': 0.0, 61 'marginEquity': 0.0, 62 'type': 'multiCollateralMarginAccount' 63 } 64 }, 65 'serverTime': '2023-04-04T17:56:49.027Z' 66}
- set_trading_on_subaccount(subaccountUid: str, *, trading_enabled: bool, extra_params: dict | None = None) dict
Enable or disable trading on a subaccount.
Requires the
General API - Full Accesspermission in the API key settings.This endpoint is only available for institutional clients and is not tested so far and always results in
INTERNAL_SERVER_ERROR.- Returns:
The open futures positions/orders
- Return type:
dict
Futures User: Dis-/Enable trading on a subaccount1>>> from kraken.futures import User 2>>> user = User(key="api-key", secret="secret-key") 3>>> user.set_trading_on_subaccount( 4... subaccountUid="778387bh61b-f990-4128-16a7-f4ab669a9b", 5... trading_enabled=True 6... ) 7{ 8 "tradingEnabled": True 9}
- class kraken.futures.Market(key: str = '', secret: str = '', url: str = '', *, sandbox: bool = False)
Bases:
KrakenFuturesBaseAPIClass that implements the Kraken Futures market client
If the sandbox environment is chosen, the keys must be generated from here: https://demo-futures.kraken.com/settings/api
- Parameters:
key (str, optional) – Futures API public key (default:
"")secret (str, optional) – Futures API secret key (default:
"")url (str, optional) – Alternative URL to access the Futures Kraken API (default: https://futures.kraken.com)
sandbox (bool, optional) – If set to
Truethe URL will be https://demo-futures.kraken.com (default:False)
Futures Market: Create the market client1>>> from kraken.futures import Market 2>>> market = Market() # unauthenticated 3>>> market = Market(key="api-key", secret="secret-key") # authenticated
Futures Market: Create the market client as context manager1>>> from kraken.futures import Market 2>>> with Market() as market: 3... print(market.get_tick_types())
- get_fee_schedules(*, extra_params: dict | None = None) dict
Retrieve information about the current fees
https://docs.futures.kraken.com/#http-api-trading-v3-api-fee-schedules-get-fee-schedules
https://support.kraken.com/hc/en-us/articles/360049269572-Fee-Schedules
This function uses caching. Run
get_fee_schedules.cache_clear()to clear.- Returns:
Dictionary containing information about the fees for wide range of tradeable assets
- Return type:
dict
Futures Market: Get the available fee schedules1>>> from kraken.futures import Market 2>>> Market().get_fee_schedules() 3{ 4 'feeSchedules': [{ 5 'uid': '5b755fea-c5b0-4307-a66e-b392cd5bd931', 6 'name': 'KF USD Multi-Collateral Fees', 7 'tiers': [ 8 {'makerFee': 0.02, 'takerFee': 0.05, 'usdVolume': 0.0}, 9 {'makerFee': 0.015, 'takerFee': 0.04, 'usdVolume': 100000.0}, 10 {'makerFee': 0.0125, 'takerFee': 0.03, 'usdVolume': 1000000.0}, 11 {'makerFee': 0.01, 'takerFee': 0.025, 'usdVolume': 5000000.0}, 12 {'makerFee': 0.0075, 'takerFee': 0.02, 'usdVolume': 10000000.0}, 13 {'makerFee': 0.005, 'takerFee': 0.015, 'usdVolume': 20000000.0}, 14 {'makerFee': 0.0025, 'takerFee': 0.0125, 'usdVolume': 50000000.0}, 15 {'makerFee': 0.0, 'takerFee': 0.01, 'usdVolume': 100000000.0} 16 ]}, ... 17 ] 18}
- get_fee_schedules_vol(*, extra_params: dict | None = None) dict
Get the personal volumes per fee schedule
Requires the
General API - Full Accesspermission in the API key settings.Futures Market: Get the personal fee schedule volumes1>>> from kraken.futures import Market 2>>> market = Market(key="api-key", secret="secret-key") 3>>> market.get_fee_schedules_vol() 4{ 5 'volumesByFeeSchedule': { 6 'ffb5403d-e82e-4ef0-8792-86a0471f526a': 0, 7 '5b755fea-c5b0-4307-a66e-b392cd5bd931': 0, 8 'eef90775-995b-4596-9257-0917f6134766': 0 9 } 10}
- get_historical_funding_rates(symbol: str, *, extra_params: dict | None = None) dict
Retrieve information about the historical funding rates for a specific asset.
- Parameters:
symbol (str) – The symbol/asset/futures contract
- Returns:
Funding rates
- Return type:
dict
Futures Market: Get the historical funding rates1>>> from kraken.futures import Market 2>>> Market().get_historical_funding_rates(symbol="PI_XBTUSD") 3{ 4 'rates': [{ 5 'timestamp': '2018-08-31T16:00:00.000Z', 6 'fundingRate': 1.0327058177e-08, 7 'relativeFundingRate': 7.182407e-05 8 }, { 9 'timestamp': '2018-08-31T20:00:00.000Z', 10 'fundingRate': -1.2047162502e-08, 11 'relativeFundingRate': -8.4873103125e-05 12 }, { 13 'timestamp': '2018-09-01T00:00:00.000Z', 14 'fundingRate': -9.645113378e-09, 15 'relativeFundingRate': -6.76651e-05 16 }, ... 17 ] 18}
- get_instruments(*, extra_params: dict | None = None) dict
Retrieve more specific information about the tradeable assets on the Futures market
https://docs.futures.kraken.com/#http-api-trading-v3-api-instrument-details-get-instruments
https://support.kraken.com/hc/en-us/articles/360022635672-Instruments
- Returns:
Dictionary containing information for all tradeable assets
- Return type:
dict
Futures Market: Get the available instruments/assets and information1>>> from kraken.futures import Market 2>>> Market().get_instruments() 3{ 4 'instruments': [{ 5 'symbol': 'pi_xbtusd', 6 'type': 'futures_inverse', 7 'underlying': 'rr_xbtusd', 8 'tickSize': 0.5, 9 'contractSize': 1, 10 'tradeable': True, 11 'impactMidSize': 1000.0, 12 'maxPositionSize': 75000000.0, 13 'openingDate': '2018-08-31T00:00:00.000Z', 14 'marginLevels': [{ 15 'contracts': 0, 16 'initialMargin': 0.02, 17 'maintenanceMargin': 0.01 18 }, { 19 'contracts': 500000, 20 'initialMargin': 0.04, 21 'maintenanceMargin': 0.02 22 }, { 23 'contracts': 1000000, 24 'initialMargin': 0.06, 25 'maintenanceMargin': 0.03 26 }, { 27 'contracts': 3000000, 28 'initialMargin': 0.1, 29 'maintenanceMargin': 0.05 30 }, { 31 'contracts': 6000000, 32 'initialMargin': 0.15, 33 'maintenanceMargin': 0.075 34 }, { 35 'contracts': 12000000, 36 'initialMargin': 0.25, 37 'maintenanceMargin': 0.125 38 }, { 39 'contracts': 20000000, 40 'initialMargin': 0.3, 41 'maintenanceMargin': 0.15 42 }, { 43 'contracts': 50000000, 44 'initialMargin': 0.4, 45 'maintenanceMargin': 0.2 46 } 47 ], 48 'fundingRateCoefficient': 24, 49 'maxRelativeFundingRate': 0.0025, 50 'isin': 'GB00J62YGL67', 51 'contractValueTradePrecision': 0, 52 'postOnly': False, 53 'feeScheduleUid': 'eef90775-995b-4596-9257-0917f6134766', 54 'retailMarginLevels': [{ 55 'contracts': 0, 56 'initialMargin': 0.5, 57 'maintenanceMargin': 0.25 58 }], 59 'category': '', 'tags': [] 60 } 61}
- get_instruments_status(instrument: str | None = None, *, extra_params: dict | None = None) dict
Retrieve status information of a specific or all futures contracts.
- Parameters:
instrument (str | None, optional) – Filter by asset
- Returns:
Status information about the asset(s)
- Return type:
dict
Futures Market: Retrieve information about a specific asset/contract/instrument1>>> from kraken.futures import Market 2>>> Market().get_instruments_status(instrument="PI_XBTUSD") 3{ 4 'tradeable': 'PI_XBTUSD', 5 'experiencingDislocation': False, 6 'priceDislocationDirection': None, 7 'experiencingExtremeVolatility': False, 8 'extremeVolatilityInitialMarginMultiplier': 1 9}
- get_leverage_preference(*, extra_params: dict | None = None) dict
Get the current leverage preferences of the user.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
The leverage preferences for all futures contracts
- Return type:
dict
Futures Market: Get the users leverage preferences1>>> from kraken.futures import Market 2>>> market = Market(key="api-key", secret="secret-key") 3>>> market.get_leverage_preference() 4{ 5 'leveragePreferences': [ 6 {'symbol': 'PF_XBTUSD', 'maxLeverage': 5.0}, 7 ... 8 ] 9}
- get_ohlc(tick_type: str, symbol: str, resolution: int, from_: int | None = None, to: int | None = None, *, extra_params: dict | None = None) dict
Retrieve the open, high, low, and close data for a specific symbol and resolution. It is also possible to filter by time.
https://docs.futures.kraken.com/#http-api-charts-ohlc-get-ohlc
https://support.kraken.com/hc/en-us/articles/4403284627220-OHLC
- Parameters:
tick_type (str) – The kind of data, based on
mark,spot, ortradesymbol (str) – The asset pair to get the ohlc from
resolution (str) – The tick resolution, one of
1m.5m,15m,1h,4h,12h,1d,1wfrom (int, optional) – From date in epoch seconds
to (int, optional) – To date in epoch seconds (inclusive)
- Returns:
The current OHLC data for a specific asset pair
- Return type:
dict
Futures Market: Get the OHLC data1>>> from kraken.futures import Market 2>>> Market().get_ohlc(tick_type="trade", symbol="PI_XBTUSD", resolution="1h") 3{ 4 'candles': [ 5 { 6 'time': 1680624000000, 7 'open': '28050.0', 8 'high': '28150', 9 'low': '27983.0', 10 'close': '28126.0', 11 'volume': '1089794.00000000' 12 } 13 ], 14 'more_candles': True 15}
- get_orderbook(symbol: str | None = None, *, extra_params: dict | None = None) dict
Get the orderbook of a specific asset/symbol. Even if the official kraken documentation states that the parameter
symbolis not required, they will always respond with an error message, so it is recommended to use thesymbolparameter until they don’t fix this issue.https://docs.futures.kraken.com/#http-api-trading-v3-api-market-data-get-orderbook
https://support.kraken.com/hc/en-us/articles/360022839551-Order-Book
- Parameters:
symbol (str, optional) – The asset/symbol to get the orderbook from
- Returns:
The current orderbook for the futures contracts
- Return type:
dict
Futures Market: Get the assets orderbook1>>> from kraken.futures import Market 2>>> Market().get_orderbook(symbol="PI_XBTUSD") 3{ 4 'result': 'success', 'orderBook': { 5 'bids': [ 6 [27909, 3000], [27908.5, 1703], [27906, 1716], 7 [27905, 2900], [27904.5, 2900], [27904, 2900], 8 [27903.5, 8900], [27903, 3415], [27902.5, 2900], 9 [27902, 2900], [27901, 4200], [27900.5, 6000], 10 ... 11 ], 12 'asks': [ 13 [27915, 4200], [27916, 1706], [27917.5, 2900], 14 [27918, 4619], [27918.5, 4200], [27919, 2900], 15 [27919.5, 78], [27920, 2900], [27920.5, 2900], 16 [27921, 6342], [27921.5, 4200], [27923, 27851], 17 ... 18 ] 19 } 20}
- get_pnl_preference(*, extra_params: dict | None = None) dict
Get the current PNL (profit & loss) preferences. This can be used to define the currency in which the profits and losses are realized.
Requires at least the
General API - Read Onlypermission in the API key settings.- Returns:
The current NPL preferences
- Return type:
dict
Futures Market: Get the users profit/loss preferences1>>> from kraken.futures import Market 2>>> market = Market(key="api-key", secret="secret-key") 3>>> market.get_pnl_preference() 4{'result': 'success', 'serverTime': '2023-04-04T15:21:29.413Z', 'preferences': []}
- get_public_execution_events(tradeable: str, before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, *, extra_params: dict | None = None) dict
Retrieve information about the public execution events. The returned
continuation_tokencan be used to request more data.https://docs.futures.kraken.com/#http-api-history-market-history-get-public-execution-events
https://support.kraken.com/hc/en-us/articles/4401755685268-Market-History-Executions
- Parameters:
tradeable (str) – The contract to filter for
before (int | None, optional) – Filter by time
continuation_token (str | None, optional) – Token that can be used to continue requesting historical events
since (int | None, optional) – Filter by a specifying a start point
sort (str | None, optional) – Sort the results
- Returns:
The public execution events
- Return type:
dict
Futures Market: Get the public execution events1>>> from kraken.futures import Market 2>>> Market().get_public_execution_events(tradeable="PI_XBTUSD") 3{ 4 'elements': [ 5 { 6 'uid': '9c74d4ba-a658-4208-891c-eee6e13bf910', 7 'timestamp': 1680874894684, 8 'event': { 9 'Execution': { 10 'execution': { 11 'uid': '3df5cb59-d410-48f7-9c6f-ee9b849b9c91', 12 'makerOrder': { 13 'uid': 'a0d28216-54f8-4af0-9adc-0d0d4738936d', 14 'tradeable': 'PI_XBTUSD', 15 'direction': 'Buy', 16 'quantity': '626', 17 'timestamp': 1680874894675, 18 'limitPrice': '27909.5', 19 'orderType': 'Post', 20 'reduceOnly': False, 21 'lastUpdateTimestamp': 1680874894675 22 }, 23 'takerOrder': { 24 'uid': '09246639-9130-42fb-8d90-4ed39913456f', 25 'tradeable': 'PI_XBTUSD', 26 'direction': 'Sell', 27 'quantity': '626', 28 'timestamp': 1680874894684, 29 'limitPrice': '27909.5000000000', 30 'orderType': 'IoC', 31 'reduceOnly': False, 32 'lastUpdateTimestamp': 1680874894684 33 }, 34 'timestamp': 1680874894684, 35 'quantity': '626', 36 'price': '27909.5', 37 'markPrice': '27915.01610466227', 38 'limitFilled': True, 39 'usdValue': '626.00' 40 }, 41 'takerReducedQuantity': '' 42 } 43 } 44 }, ... 45 ], 46 'len': 1000, 47 'continuationToken': 'MTY4MDg2Nzg2ODkxOS85MDY0OTcwMTAxNA==' 48}
- get_public_mark_price_events(tradeable: str, before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, *, extra_params: dict | None = None) dict
Retrieve information about public mark price events. The returned
continuation_tokencan be used to request more data.https://docs.futures.kraken.com/#http-api-history-market-history-get-public-mark-price-events
https://support.kraken.com/hc/en-us/articles/4401748276116-Market-History-Mark-Price
- Parameters:
tradeable (str) – The contract to filter for
before (int | None, optional) – Filter by time
continuation_token (str | None, optional) – Token that can be used to continue requesting historical events
since (int | None, optional) – Filter by a specifying a start point
sort (str | None, optional) – Sort the results
- Returns:
The public order events
- Return type:
dict
Futures Market: Get the public mark price events1>>> from kraken.futures import Market 2>>> Market().get_public_mark_price_events(tradeable="PI_XBTUSD") 3{ 4 'elements': [ 5 { 6 'uid': '', 7 'timestamp': 1680875273372, 8 'event': { 9 'MarkPriceChanged': { 10 'price': '27900.67795901584' 11 } 12 } 13 }, { 14 'uid': '', 15 'timestamp': 1680875272263, 16 'event': { 17 'MarkPriceChanged': { 18 'price': '27900.09023205142' 19 } 20 } 21 }, ... 22 ], 23 'len': 1000, 24 'continuationToken': 'MTY4MDg3NDEyNzg3OC85MDY2MjI3ODIzMA==' 25}
- get_public_order_events(tradeable: str, before: int | None = None, continuation_token: str | None = None, since: int | None = None, sort: str | None = None, *, extra_params: dict | None = None) dict
Retrieve information about the public order events - filled, closed, opened, etc, for a specific contract.The returned
continuation_tokencan be used to request more data.https://docs.futures.kraken.com/#http-api-history-market-history-get-public-order-events
https://support.kraken.com/hc/en-us/articles/4401755906452-Market-History-Orders
- Parameters:
tradeable (str) – The contract to filter for
before (int, optional) – Filter by time
continuation_token (str, optional) – Token that can be used to continue requesting historical events
since (int, optional) – Filter by a specifying a start point
sort (str, optional) – Sort the results
- Returns:
The public order events
- Return type:
dict
Futures Market: Get the public order events1>>> from kraken.futures import Market 2>>> Market().get_public_order_events(tradeable="PI_XBTUSD") 3{ 4 'elements': [ 5 { 6 'uid': '430782d7-7b6d-472a-9e92-67047289d742', 7 'timestamp': 1680875125649, 8 'event': { 9 'OrderPlaced': { 10 'order': { 11 'uid': 'f9aaf471-95ba-4fde-ab68-251f12f96e47', 12 'tradeable': 'PI_XBTUSD', 13 'direction': 'Sell', 14 'quantity': '652', 15 'timestamp': 1680875125649, 16 'limitPrice': '27927.5', 17 'orderType': 'Post', 18 'reduceOnly': False, 19 'lastUpdateTimestamp': 1680875125649 20 }, 21 'reason': 'new_user_order', 22 'reducedQuantity': '' 23 } 24 } 25 }, ... 26 ], 27 'len': 1000, 28 'continuationToken': 'MTY4MDg3NTExMzc2OS85MDY2NDA1ODIyNw==' 29}
- get_resolutions(tick_type: str, tradeable: str, *, extra_params: dict | None = None) list[str]
Retrieve the list of available resolutions for a specific asset.
This function uses caching. Run
get_resolutions.cache_clear()to clear.- Parameters:
tick_type (str) – The kind of data, based on
mark,spot, ortradetick_type – The asset of interest
- Returns:
List of resolutions
- Type:
list[str]
Futures Market: Get the available resolutions1>>> from kraken.futures import Market 2>>> Market().get_resolutions(tick_type="mark", tradeable="PI_XBTUSD") 3['1h', '12h', '1w', '15m', '1d', '5m', '30m', '4h', '1m']
- get_tick_types(*, extra_params: dict | None = None) list[str]
Retrieve the available tick types that can be used for example to access the
kraken.futures.Market.get_ohlc()endpoint.This function uses caching. Run
get_tick_types.cache_clear()to clear.- Returns:
List of available tick types
- Return type:
list[str]
Futures Market: Get the available tick types1>>> from kraken.futures import Market 2>>> Market().get_tick_types() 3['mark', 'spot', 'trade']
- get_tickers(*, extra_params: dict | None = None) dict
Retrieve information about the current tickers of all futures contracts.
https://docs.futures.kraken.com/#http-api-trading-v3-api-market-data-get-tickers
https://support.kraken.com/hc/en-us/articles/360022839531-Tickers
- Returns:
The current tickers
- Return type:
dict
Futures Market: Get the available tickers1>>> from kraken.futures import Market 2>>> Market().get_tickers() 3{ 4 'tickers': [{ 5 'tag': 'perpetual', 6 'pair': 'COMP:USD', 7 'symbol': 'pf_compusd', 8 'markPrice': 42.192, 9 'bid': 42.14, 10 'bidSize': 11.8, 11 'ask': 42.244, 12 'askSize': 80.7, 13 'vol24h': 96.8, 14 'volumeQuote': 4109.9678, 15 'openInterest': 451.3, 16 'open24h': 41.975, 17 'indexPrice': 42.193, 18 'last': 42.873, 19 'lastTime': '2023-04-04T00:07:33.690Z', 20 'lastSize': 13.9, 21 'suspended': False, 22 'fundingRate': 0.000220714078888884, 23 'fundingRatePrediction': 6.3914700437486e-05, 24 'postOnly': False 25 }, ...] 26}
- get_trade_history(symbol: str | None = None, lastTime: str | None = None, *, extra_params: dict | None = None) dict
Retrieve the trade history (max 100 entries), can be filtered using the parameters.
https://docs.futures.kraken.com/#http-api-trading-v3-api-market-data-get-trade-history
https://support.kraken.com/hc/en-us/articles/360022839511-History
- Parameters:
symbol (str, optional) – The asset to filter for
lastTime (str, optional) – Filter by time
- Returns:
Trade history
- Return type:
dict
Futures Market: Get the public trade history1>>> from kraken.futures import Market 2>>> Market().get_trade_history(symbol="PI_XBTUSD") 3{ 4 'history': [{ 5 'time': '2023-04-04T05:28:27.926Z', 6 'trade_id': 100, 7 'price': 27913, 8 'size': 2456, 9 'side': 'sell', 10 'type': 'fill', 11 'uid': 'de7a2eca-f2bc-4afb-860d-522a9dcc0b12' 12 }, { 13 'time': '2023-04-04T05:28:28.795Z', 14 'trade_id': 99, 'price': 27913.5, 15 'size': 3000, 'side': 'sell', 16 'type': 'fill', 17 'uid': 'c985c7ea-30a5-4456-b857-a4ec9156fb3b' 18 }, ... 19 ]
- get_tradeable_products(tick_type: str, *, extra_params: dict | None = None) list[str]
Retrieve a list containing the tradeable assets on the futures market.
This function uses caching. Run
get_tradeable_products.cache_clear()to clear.- Parameters:
tick_type (str) – The kind of data, based on
mark,spot, ortrade- Returns:
List of tradeable assets
- Type:
list[str]
Futures Market: Get the tradeable products1>>> from kraken.futures import Market 2>>> Market().get_tradeable_products(tick_type="trade") 3["PI_XBTUSD", "PF_XBTUSD", "PF_SOLUSD", ...]
- set_leverage_preference(symbol: str, maxLeverage: str | float | None = None, *, extra_params: dict | None = None) dict
Set a new leverage preference for a specific futures contract.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
symbol (str, optional) – The symbol to set the preference
maxLeverage (str | float, optional) – The maximum allowed leverage for a futures contract
- Returns:
Information about the success or fail
- Return type:
dict
Futures Market: Set the users leverage preferences1>>> from kraken.futures import Market 2>>> market = Market(key="api-key", secret="secret-key") 3>>> market.set_leverage_preference(symbol="PF_XBTUSD", maxLeverage=2) 4{'result': 'success', 'serverTime': '2023-04-04T05:59:49.576Z'}
- set_pnl_preference(symbol: str, pnlPreference: str, *, extra_params: dict | None = None) dict
Modify or set the current PNL preference of the user. This can be used to define a specific currency that should be used to realize profits and losses. The default is the quote currency of the futures contract.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
symbol (str) – The asset pair or futures contract
pnlPreference – The currency to pay out the profits and losses
- Returns:
Success or failure of the request
- Return type:
dict
Futures Market: Set the users profit/loss preferences1>>> from kraken.futures import Market 2>>> market = Market(key="api-key", secret="secret-key") 3>>> market.set_pnl_preference(symbol="PF_XBTUSD", pnlPreference="USD") 4{'result': 'success', 'serverTime': '2023-04-04T15:24:18.406Z'}
- class kraken.futures.Trade(key: str = '', secret: str = '', url: str = '', *, sandbox: bool = False)
Bases:
KrakenFuturesBaseAPIClass that implements the Kraken Futures trade client
If the sandbox environment is chosen, the keys must be generated from here: https://demo-futures.kraken.com/settings/api
- Parameters:
key (str, optional) – Futures API public key (default:
"")secret (str, optional) – Futures API secret key (default:
"")url (str, optional) – Alternative URL to access the Futures Kraken API (default: https://futures.kraken.com)
sandbox (bool, optional) – If set to
Truethe URL will be https://demo-futures.kraken.com (default:False)
Futures Trade: Create the trade client1>>> from kraken.futures import Trade 2>>> trade = Trade() # unauthenticated 3>>> trade = Trade(key="api-key", secret="secret-key") # authenticated
Futures Trade: Create the trade client as context manager1>>> from kraken.futures import Trade 2>>> with Trade(key="api-key", secret="secret-key") as trade: 3... print(trade.get_fills())
- cancel_all_orders(symbol: str | None = None, *, extra_params: dict | None = None) dict
Cancels all open orders, can be filtered by symbol.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
symbol (str, optional) – Filter by symbol
- Returns:
Information about the success or failure
- Return type:
dict
Futures Trade: Cancel all open orders1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.cancel_all_orders() 4{ 5 'result': 'success', 6 'cancelStatus': { 7 'receivedTime': '2023-04-04T17:09:09.986Z', 8 'cancelOnly': 'all', 9 'status': 'cancelled', 10 'cancelledOrders': [ 11 { 12 'order_id': 'fc589be9-5095-48f0-b6f1-a2dfad6d9677' 13 }, { 14 'order_id': '0365942e-4850-4e41-90c3-a10f96f7baaf' 15 } 16 ], 17 'orderEvents': [] 18 }, 19 'serverTime': '2023-04-04T17:09:09.987Z' 20}
- cancel_order(order_id: str | None = None, cliOrdId: str | None = None, processBefore: str | None = None, *, extra_params: dict | None = None) dict
This endpoint can be used to cancel a specific order by
order_idorcliOrdId.Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
order_id (str, optional) – The order_id to cancel
cliOrdId (str, optional) – The client defined order id
processBefore (str, optional) – Process before timestamp otherwise reject
- Raises:
ValueError – If both
order_idandcliOrdIdare not set- Returns:
Success or failure
- Return type:
dict
Futures Trade: Cancel an order1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.cancel_order(order_id="fc589be9-5095-48f0-b6f1-a2dfad6d9677") 4{ 5 'result': 'success', 6 'cancelStatus': { 7 'status': 'notFound', 8 'receivedTime': '2023-04-04T17:18:11.628Z' 9 }, 10 'serverTime': '2023-04-04T17:18:11.628Z' 11}
- create_batch_order(batchorder_list: list[dict], processBefore: str | None = None, *, extra_params: dict | None = None) dict
Create multiple orders at once using the batch order endpoint.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
batchorder_list (list[dict]) – List of order instructions (see example below - or the linked official Kraken documentation)
processBefore (str, optional) – Process before timestamp otherwise reject
- Returns:
Information about the submitted request
- Return type:
dict
Futures Trade: Create a batch order1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.create_batch_order( 4... batchorder_list=[ 5... { 6... "order": "send", 7... "order_tag": "1", 8... "orderType": "lmt", 9... "symbol": "PI_XBTUSD", 10... "side": "buy", 11... "size": 5, 12... "limitPrice": 1.00, 13... "cliOrdId": "my_another_client_id", 14... }, 15... { 16... "order": "send", 17... "order_tag": "2", 18... "orderType": "stp", 19... "symbol": "PI_XBTUSD", 20... "side": "buy", 21... "size": 1, 22... "limitPrice": 2.00, 23... "stopPrice": 3.00, 24... }, 25... { 26... "order": "cancel", 27... "order_id": "e35d61dd-8a30-4d5f-a574-b5593ef0c050", 28... }, 29... { 30... "order": "cancel", 31... "cliOrdId": "my_client_id", 32... }, 33... ], 34... ) 35{ 36 'result': 'success', 37 'serverTime': '2023-04-04T17:03:36.100Z', 38 'batchStatus': [ 39 { 40 'status': 'insufficientAvailableFunds', 41 'order_tag': '1', 42 'orderEvents': [] 43 }, { 44 'status': 'placed', 45 'order_tag': '2', 46 'order_id': 47 'fc589be9-5095-48f0-b6f1-a2dfad6d9677', 48 'dateTimeReceived': '2023-04-04T17:03:36.053Z', 49 'orderEvents': [ 50 { 51 'orderTrigger': { 52 'uid': 'fc589be9-5095-48f0-b6f1-a2dfad6d9677', 53 'clientId': None, 54 'type': 'lmt', 55 'symbol': 'pi_xbtusd', 56 'side': 'buy', 57 'quantity': 1, 58 'limitPrice': 2.0, 59 'triggerPrice': 3.0, 60 'triggerSide': 'trigger_above', 61 'triggerSignal': 62 'last_price', 63 'reduceOnly': False, 64 'timestamp': '2023-04-04T17:03:36.053Z', 65 'lastUpdateTimestamp': '2023-04-04T17:03:36.053Z', 66 'startTime': None 67 }, 68 'type': 'PLACE' 69 } 70 ] 71 }, { 72 'status': 'notFound', 73 'order_id': 'e35d61dd-8a30-4d5f-a574-b5593ef0c050', 74 'orderEvents': [] 75 }, { 76 'status': 'notFound', 77 'cliOrdId': 'my_client_id', 78 'orderEvents': [] 79 } 80 ] 81}
- create_order(orderType: str, size: str | float, symbol: str, side: str, cliOrdId: str | None = None, limitPrice: str | float | None = None, reduceOnly: bool | None = None, stopPrice: str | float | None = None, triggerSignal: str | None = None, trailingStopDeviationUnit: str | None = None, trailingStopMaxDeviation: str | None = None, processBefore: str | None = None, *, extra_params: dict | None = None) dict
Create and place an order on the futures market.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
orderType (str) – The order type, one of
lmt,post,ioc,mkt,stp,take_profit,trailing_stop(https://support.kraken.com/hc/en-us/sections/200577136-Order-types)size (str | float) – The volume of the position
symbol (str) – The symbol to trade
side (str) – Long or Short, i.e.,:
buyorsellcliOrdId (str, optional) – A user defined order id
limitPrice (str | float, optional) – Define a custom limit price
reduceOnly (bool, optional) – Reduces existing positions if set to
TruestopPrice (str, optional) – Define a price when to exit the order. Required for specific order types
triggerSignal (str, optional) – Define a trigger for specific orders (must be one of
mark,index,last)trailingStopDeviationUnit (str, optional) – See referenced Kraken documentation
trailingStopMaxDeviation (str, optional) – See referenced Kraken documentation
processBefore (str, optional) – Process before timestamp otherwise reject
- Returns:
Success or failure
- Return type:
dict
Futures Trade: Create and submit a new market order1>>> trade.create_order( 2... orderType="mkt", 3... size=5, 4... side="buy", 5... symbol="PI_ETHUSD", 6... ) 7{ 8 'result': 'success', 9 'sendStatus': { 10 'order_id': '67d3a732-b0d3-49e7-9577-45b31bceb833', 11 'status': 'placed', 12 'receivedTime': '2023-04-08T11:59:23.887Z', 13 'orderEvents': [ 14 { 15 'executionId': '495aae73-7cf7-4dfc-8963-3b766d8150de', 16 'price': 1869.175, 17 'amount': 5, 18 'orderPriorEdit': None, 19 'orderPriorExecution': { 20 'orderId': '67d3a732-b0d3-49e7-9577-45b31bceb833', 21 'cliOrdId': None, 22 'type': 'ioc', 23 'symbol': 'pi_ethusd', 24 'side': 'buy', 25 'quantity': 5, 26 'filled': 0, 27 'limitPrice': 1887.85, 28 'reduceOnly': False, 29 'timestamp': '2023-04-08T11:59:23.887Z', 30 'lastUpdateTimestamp': '2023-04-08T11:59:23.887Z' 31 }, 32 'takerReducedQuantity': None, 33 'type': 'EXECUTION' 34 } 35 ] 36 }, 37 'serverTime': '2023-04-08T11:59:23.888Z' 38}
Futures Trade: Create and submit a new limit order1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.create_order( 4... orderType="lmt", 5... size=1000, 6... symbol="PF_ETHUSD", 7... side="buy", 8... limitPrice=1200.0, 9... ) 10{ 11 'result': 'success', 12 'sendStatus': { 13 'order_id': '2ce038ae-c144-4de7-a0f1-82f7f4fca864', 14 'status': 'placed', 15 'receivedTime': '2023-04-07T15:18:04.699Z', 16 'orderEvents': [ 17 { 18 'order': { 19 'orderId': '2ce038ae-c144-4de7-a0f1-82f7f4fca864', 20 'cliOrdId': None, 21 'type': 'lmt', 22 'symbol': 'pi_ethusd', 23 'side': 'buy', 24 'quantity': 100, 25 'filled': 0, 26 'limitPrice': 1200.0, 27 'reduceOnly': False, 28 'timestamp': '2023-04-07T15:18:04.699Z', 29 'lastUpdateTimestamp': '2023-04-07T15:18:04.699Z' 30 }, 31 'reducedQuantity': None, 32 'type': 'PLACE' 33 } 34 ] 35 }, 36 'serverTime': '2023-04-07T15:18:04.700Z' 37}
Futures Trade: Create and submit a new take profit order1>>> trade.create_order( 2... orderType="take_profit", 3... size=10, 4... side="buy", 5... symbol="PI_ETHUSD", 6... limitPrice=2500.0, 7... triggerSignal="last", 8... stopPrice=2498.4, 9... ) 10{ 11 'result': 'success', 12 'sendStatus': { 13 'order_id': 'e58ed100-1fb8-4e6c-a5ea-1cf85b0f0654', 14 'status': 'placed', 15 'receivedTime': '2023-04-07T15:12:08.131Z', 16 'orderEvents': [ 17 { 18 'orderTrigger': { 19 'uid': 'e58ed100-1fb8-4e6c-a5ea-1cf85b0f0654', 20 'clientId': None, 21 'type': 'lmt', 22 'symbol': 'pi_ethusd', 23 'side': 'buy', 24 'quantity': 10, 25 'limitPrice': 1860.0, 26 'triggerPrice': 1880.4, 27 'triggerSide': 'trigger_below', 28 'triggerSignal': 'last_price', 29 'reduceOnly': False, 30 'timestamp': '2023-04-07T15:12:08.131Z', 31 'lastUpdateTimestamp': '2023-04-07T15:12:08.131Z', 32 'startTime': None 33 }, 34 'type': 'PLACE' 35 } 36 ] 37 }, 38 'serverTime': '2023-04-07T15:12:08.131Z' 39}
- dead_mans_switch(timeout: int | None = 0, *, extra_params: dict | None = None) dict
The Death Man’s Switch can be used to cancel all orders after a specific timeout. If the timeout is set to 60, all orders will be cancelled after 60 seconds. The timeout can be pushed back by accessing this endpoint over and over again. Set the timeout to zero to reset.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
timeout (int, optional) – The timeout in seconds
- Returns:
Success or failure
- Return type:
dict
Futures Trade: Setup the Death man’s Switch1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.dead_mans_switch(timeout=60) 4{ 5 'result': 'success', 6 'serverTime': '2023-04-04T17:14:34.113Z', 7 'status': { 8 'currentTime': '2023-04-04T17:14:34.076Z', 9 'triggerTime': '0' 10 } 11}
- edit_order(orderId: str | None = None, cliOrdId: str | None = None, limitPrice: str | float | None = None, size: str | float | None = None, stopPrice: str | float | None = None, processBefore: str | None = None, *, extra_params: dict | None = None) dict
Edit an open order.
Requires the
General API - Full Accesspermission in the API key settings.- Parameters:
orderId (str, optional) – The order id to cancel
cliOrdId (str, optional) – The client defined order id
limitPrice (str | float None) – The new limit price
size (str | float, optional) – The new size of the position
stopPrice (str | float, optional) – The stop price
processBefore (str, optional) – Process before timestamp otherwise reject
- Raises:
ValueError – If both
orderIdandcliOrdIdare not set- Returns:
Success or failure
- Return type:
dict
Futures Trade: Edit an open order1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.edit_order(orderId="fc589be9-5095-48f0-b6f1-a2dfad6d9677", size=100) 4{ 5 'result': 'success', 6 'serverTime': '2023-04-04T17:24:53.233Z', 7 'editStatus': { 8 'status': 'orderForEditNotFound', 9 'orderId': 'fc589be9-5095-48f0-b6f1-a2dfad6d9677', 10 'receivedTime': 11 '2023-04-04T17:24:53.233Z', 12 'orderEvents': [] 13 } 14}
- get_fills(lastFillTime: str | None = None, *, extra_params: dict | None = None) dict
Return the current fills of the user.
Requires at least the
General API - Read Onlypermission in the API key settings.- Parameters:
lastFillTime (str, optional) – Filter by last filled timestamp
- Returns:
Fills
- Return type:
dict
Futures Trade: Get the recent fills1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.get_fills() 4{ 5 'result': 'success', 6 'fills': [{ 7 'fill_id': '15dae264-01e9-4d4c-8962-2f49b98c46f6', 8 'symbol': 'pi_ethusd', 9 'side': 'buy', 10 'order_id': '267372ec-272f-4ca7-9b8c-99a0dc8f781c', 11 'size': 5, 12 'price': 1859.075, 13 'fillTime': '2023-04-07T15:07:46.540Z', 14 'fillType': 'taker' 15 }, ...], 16 'serverTime': '2023-04-07T15:23:48.705Z' 17}
- get_max_order_size(orderType: str, symbol: str, limitPrice: float | None = None, *, extra_params: dict | None = None) dict
Retrieve the maximum order price for a specific symbol. Can be adjusted by
limitPrice. This endpoint only supports multi-collateral futures.Requires at least the
General API - Read Accesspermission in the API key settings.- Parameters:
orderType (str) –
lmtormktsymbol (str) – The symbol to filter for
limitPrice (Optional[float], optional) – Limit price if
orderType == lmt, defaults to None
- get_orders_status(orderIds: str | list[str] | None = None, cliOrdIds: str | list[str] | None = None, *, extra_params: dict | None = None) dict
Get the status of multiple orders.
Requires at least the
General API - Read Onlypermission in the API key settings.- Parameters:
orderIds (str | list[str], optional) – The order ids to cancel
cliOrdId (str | list[str], optional) – The client defined order ids
- Returns:
Success or failure
- Return type:
dict
Futures Trade: Get the order status1>>> from kraken.futures import Trade 2>>> trade = Trade(key="api-key", secret="secret-key") 3>>> trade.get_orders_status( 4... orderIds=[ 5... "2c611222-bfe6-42d1-9f55-77bddc01a313", 6... "5f204f95-4354-4610-bb3b-c902ad333012" 7... ]) 8{'result': 'success', 'serverTime': '2023-04-04T17:27:29.667Z', 'orders': []}
- class kraken.futures.Funding(key: str = '', secret: str = '', url: str = '', *, sandbox: bool = False)
Bases:
KrakenFuturesBaseAPIClass that implements the Kraken Futures Funding client
If the sandbox environment is chosen, the keys must be generated from here: https://demo-futures.kraken.com/settings/api
- Parameters:
key (str, optional) – Futures API public key (default:
"")secret (str, optional) – Futures API secret key (default:
"")url (str, optional) – Alternative URL to access the Futures Kraken API (default: https://futures.kraken.com)
sandbox (bool, optional) – If set to
Truethe URL will be https://demo-futures.kraken.com (default:False)
Futures Funding: Create the funding client1>>> from kraken.futures import Funding 2>>> funding = Funding() # unauthenticated 3>>> funding = Funding(key="api-key", secret="secret-key") # authenticated
Futures Funding: Create the funding client as context manager1>>> from kraken.futures import Funding 2>>> with Funding(key="api-key", secret="secret-key") as funding: 3... print(funding.get_historical_funding_rates(symbol="PI_XBTUSD"))
- get_historical_funding_rates(symbol: str, *, extra_params: dict | None = None) dict
Retrieve information about the historical funding rates of a specific
symbol- Parameters:
symbol (str) – The futures symbol to filter for
- Returns:
The funding rates for a specific asset/contract
- Return type:
dict
Futures Funding: Get the historical funding rates1>>> from kraken.futures import Funding 2>>> Funding().get_historical_funding_rates(symbol="PI_XBTUSD") 3{ 4 'rates': [ 5 { 6 'timestamp': '2019-02-27T16:00:00.000Z', 7 'fundingRate': 1.31656208775e-07, 8 'relativeFundingRate': 0.0005 9 }, { 10 'timestamp': '2019-02-27T20:00:00.000Z', 11 'fundingRate': 1.30695377827e-07, 12 'relativeFundingRate': 0.0005 13 }, ... 14 ] 15}
- initiate_subaccount_transfer(amount: str | float, fromAccount: str, fromUser: str, toAccount: str, toUser: str, unit: str, *, extra_params: dict | None = None) dict
Submit a request to transfer funds between the regular and subaccount.
Requires the
General API - Full AccessandWithdrawal API - Full accesspermissions in the API key settings.- Parameters:
amount (str | float) – The volume to transfer
fromAccount (str) – The account to withdraw from
fromUser (str) – The user account to transfer from
toAccount (str) – The account to deposit to
unit (str) – The asset to transfer
Futures Funding: Transfer funds between subaccounts1>>> from kraken.futures import Funding 2>>> funding = Funding(key="api-key", secret="secret-key") 3>>> funding.initiate_subaccount_transfer( 4... amount='2', 5... fromAccount='MyCashWallet', 6... fromUser='Subaccount1', 7... toAccount='MyCashWallet', 8... toUser='Subaccount2', 9... unit='XBT' 10... ))
- initiate_wallet_transfer(amount: str | float, fromAccount: str, toAccount: str, unit: str, *, extra_params: dict | None = None) dict
Submit a wallet transfer request to transfer funds between margin accounts.
Requires the
General API - Full AccessandWithdrawal API - Full accesspermissions in the API key settings.- Parameters:
amount (str | float) – The volume to transfer
fromAccount (str) – The account to withdraw from
fromAccount – The account to deposit to
unit (str) – The currency or asset to transfer
Futures Funding: Transfer funds between wallets1>>> from kraken.futures import Funding 2>>> funding = Funding(key="api-key", secret="secret-key") 3>>> funding.initiate_wallet_transfer( 4... amount='100', 5... fromAccount='some cash or margin account', 6... toAccount='another cash or margin account', 7... unit='ADA' 8... )) 9{ 10 'result': 'success', 11 'serverTime': '2023-04-07T15:23:45.196Z" 12}
- initiate_withdrawal_to_spot_wallet(amount: str | float, currency: str, sourceWallet: str | None = None, *, extra_params: dict | None = None) dict
Enables the transfer of funds between the futures and spot wallet.
Requires the
General API - Full AccessandWithdrawal API - Full accesspermissions in the API key settings.- Parameters:
amount (str | float) – The volume to transfer
currency (str) – The asset or currency to transfer
sourceWallet (str, optional) – The wallet to withdraw from (default:
cash)
- Raises:
ValueError – If this function is called within the sandbox/demo environment
Futures Funding: Transfer funds between Spot and Futures wallets1>>> from kraken.futures import Funding 2>>> funding = Funding(key="api-key", secret="secret-key") 3>>> funding.initiate_withdrawal_to_spot_wallet( 4... amount=100, 5... currency='USDT', 6... sourceWallet='cash' 7... ))