Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/_pre_commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
files.pythonhosted.org:443
github.com:443
proxy.golang.org:443
pypi.org:443
registry.npmjs.org:443
egress-policy: audit
# allowed-endpoints: >
# api.github.com:443
# files.pythonhosted.org:443
# github.com:443
# proxy.golang.org:443
# pypi.org:443
# registry.npmjs.org:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
rev: v0.12.7
hooks:
- id: ruff
args:
- --preview
- --fix
- --exit-non-zero-on-fix
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.17.1
hooks:
- id: mypy
name: mypy
Expand All @@ -26,11 +26,11 @@ repos:
- --install-types
- --non-interactive
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
rev: v8.28.0
hooks:
- id: gitleaks
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies: [tomli]
Expand Down Expand Up @@ -67,21 +67,21 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
rev: v3.6.2
hooks:
- id: prettier
- repo: https://github.com/PyCQA/isort # TODO: remove as soon as ruff is stable
rev: 5.13.2
rev: 6.0.1
hooks:
- id: isort
args:
- --profile=black
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
rev: 1.8.6
hooks:
- id: bandit
exclude: "^tests/.*|examples/.*"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Projects using this SDK:

- https://github.com/btschwertfeger/kraken-infinity-grid
- https://github.com/btschwertfeger/kraken-rebalance-bot
- https://github.com/btschwertfeger/python-kraken-sdk/network/dependents

---

Expand Down
5 changes: 3 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# python-kraken-sdk usage examples

This directory contains several examples demonstrating how to use the
`python-kraken-sdk`. These examples cover various functionalities such as spot
trading, futures trading, and market data retrieval using both REST and
`python-kraken-sdk`. These examples cover various functionalities such as Spot
trading, Futures trading, and market data retrieval using both REST and
WebSocket APIs.

Ideal examples of successful running trading algorithms based on the
python-kraken-sdk are listed below:

- https://github.com/btschwertfeger/kraken-infinity-grid
- https://github.com/btschwertfeger/kraken-rebalance-bot
- https://github.com/btschwertfeger/python-kraken-sdk/network/dependents

For more detailed and up-to-date usage, refer to the unit tests provided in the
main package.
83 changes: 53 additions & 30 deletions examples/futures_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#

"""
Module that implements some example usage for the Kraken Futures REST clients.

This module may not be maintained on a regular basis, so please refer to the
unit tests of this package as they provide a much deeper dive into the usage.
Module that implements *some* examples for the Kraken Futures REST clients
usage.
"""

import logging
Expand All @@ -33,22 +31,35 @@


def market_examples() -> None:
"""Example market client usage"""
# market = Market()
# print(market.get_tick_types())
# print(market.get_tradeable_products(tick_type='trade'))
# print(market.get_resolutions(tick_type='trade', tradeable='PI_XBTUSD'))
# print(market.get_ohlc(tick_type='trade', symbol='PI_XBTUSD', resolution='5m', from_='1668989233'))
# print(market.get_fee_schedules())
# # print(market.get_orderbook(symbol='fi_xbtusd_180615')) # this endpoint is broken
# print(market.get_tickers())
# print(market.get_instruments())
# print(market.get_instruments_status())
# print(market.get_instruments_status(instrument='PI_XBTUSD'))
# print(market.get_trade_history(symbol='PI_XBTUSD'))
# print(market.get_historical_funding_rates(symbol='PI_XBTUSD'))
# time.sleep(2)
"""Example Futures Market client usage"""

# Usage of the Market client to access public endpoints:
market = Market()
print(market.get_tick_types())
print(market.get_tradeable_products(tick_type="trade"))
print(market.get_resolutions(tick_type="trade", tradeable="PI_XBTUSD"))
print(
market.get_ohlc(
tick_type="trade",
symbol="PI_XBTUSD",
resolution="5m",
from_="1668989233",
),
)
print(market.get_fee_schedules())
print(
market.get_orderbook(symbol="fi_xbtusd_180615"),
) # might need adjustment of the symbol
print(market.get_tickers())
print(market.get_instruments())
print(market.get_instruments_status())
print(market.get_instruments_status(instrument="PI_XBTUSD"))
print(market.get_trade_history(symbol="PI_XBTUSD"))
print(market.get_historical_funding_rates(symbol="PI_XBTUSD"))
time.sleep(2) # Just to avoid rate limits

# Usage of the Market client to access private endpoints:
# (commented out to avoid accidental usage)
priv_market = Market(key=key, secret=secret, sandbox=True)
# print(priv_market.get_fee_schedules_vol())
print(priv_market.get_leverage_preference())
Expand All @@ -66,20 +77,25 @@ def market_examples() -> None:


def user_examples() -> None:
"""Example User client usage"""
"""Example Futures User client usage"""
# NOTE: This only works if you have set valid credentials for the the
# Futures demo environment. Remove the `sandbox=True` argument to use
# the production environment.
#
# Usage of the User client to access private endpoints:
user = User(key=key, secret=secret, sandbox=True)
print(user.get_wallets())

print(user.get_subaccounts())
print(user.get_unwind_queue())
print(user.get_notifications())

print(user.get_open_positions())
print(user.get_open_orders())

# You can retrieve the account log like so:
print(user.get_account_log(before="1604937694000"))
print(user.get_account_log(info="futures liquidation"))
time.sleep(2)
time.sleep(2) # Just to avoid rate limits

response = user.get_account_log_csv()
assert response.status_code in {200, "200"}
with Path("account_log.csv").open("wb") as file:
Expand All @@ -89,10 +105,16 @@ def user_examples() -> None:


def trade_examples() -> None:
"""Example Trade client usage"""
raise ValueError(
"Attention: Please check if you really want to execute the trade endpoints!",
"""Example Futures Trade client usage"""
print(
"Attention: Please check if you want to execute the trade endpoints!"
" Check the script manually before running this example.",
)
return
# return
# NOTE: This only works if you have set valid credentials for the the
# Futures demo environment. Remove the `sandbox=True` argument to use
# the production environment.
trade = Trade(key=key, secret=secret, sandbox=True)
print(trade.get_fills())
print(trade.get_fills(lastFillTime="2020-07-21T12:41:52.790Z"))
Expand Down Expand Up @@ -171,10 +193,11 @@ def funding_examples() -> None:


def main() -> None:
user_examples()
market_examples()
trade_examples()
funding_examples()
"""Uncomment the examples you want to run:"""
# user_examples()
# market_examples()
# trade_examples()
# funding_examples()


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion examples/futures_ws_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import asyncio
import logging
import logging.config
import os
import time

Expand Down
Loading
Loading