Skip to content

Commit

Permalink
released v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
btschwertfeger committed Jul 13, 2022
1 parent 9a54879 commit 9a52192
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python3 -m pip install python-kraken-sdk
#### REST
... can be found in `/examples/examples.py`
```python
from kraken.client import User, Market, Trade, Funding, Staking
from kraken.spot.client import User, Market, Trade, Funding, Staking

def main() -> None:
key = 'kraken pub key'
Expand Down Expand Up @@ -58,21 +58,21 @@ if __name__ == '__main__':
... can be found in `/examples/ws_examples.py`
```python
import asyncio
from kraken.client import WsClient
from kraken.websocket.websocket import KrakenWsClient
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(KrakenWsClient):
class Bot(KrakenSpotWSClient):

async def on_message(self, msg) -> None:
if 'event' in msg:
if msg['event'] in ['pong', 'heartbeat': return

print(f'--->{msg}')
print(msg)
# await self._client.create_order(
# ordertype='limit',
# side='buy',
Expand All @@ -90,8 +90,7 @@ async def main() -> None:
while True: await asyncio.sleep(6)

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.get_event_loop().run_until_complete(main())
```

## What else?
Expand All @@ -102,6 +101,6 @@ Logging messages are enabled, so you can configure your own logger to track ever
## References
- https://docs.kraken.com/websockets
- https://docs.kraken.com/rest/

## Notes:
- Triggers: stop-loss, stop-loss-limit, take-profit and take-profit-limit orders.
- https://support.kraken.com/hc/en-us/sections/360012894412-Futures-API
<!-- ## Notes: -->
<!-- - Triggers: stop-loss, stop-loss-limit, take-profit and take-profit-limit orders. -->
4 changes: 2 additions & 2 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from datetime import datetime

try:
from kraken.client import User, Market, Trade, Funding, Staking
from kraken.spot.client import User, Market, Trade, Funding, Staking
except:
sys.path.append('/Users/benjamin/repositories/Trading/python-kraken-sdk')
from kraken.client import User, Market, Trade, Funding, Staking
from kraken.spot.client import User, Market, Trade, Funding, Staking


logging.basicConfig(
Expand Down
13 changes: 6 additions & 7 deletions examples/ws_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from datetime import datetime

try:
from kraken.client import WsClient
from kraken.websocket.websocket import KrakenWsClient
from kraken.spot.client import WsClient
from kraken.spot.websocket.websocket import KrakenSpotWSClient
except:
sys.path.append('/Users/benjamin/repositories/Trading/python-kraken-sdk')
from kraken.client import WsClient
from kraken.websocket.websocket import KrakenWsClient
from kraken.spot.client import WsClient
from kraken.spot.websocket.websocket import KrakenSpotWSClient

logging.basicConfig(
format='%(asctime)s %(module)s,line: %(lineno)d %(levelname)8s | %(message)s',
Expand All @@ -29,7 +29,7 @@ async def main() -> None:
secret = dotenv_values('.env')['SECRET_KEY']

# ___Custom_Trading_Bot______________
class Bot(KrakenWsClient):
class Bot(KrakenSpotWSClient):

async def on_message(self, event) -> None:
if 'event' in event:
Expand All @@ -55,5 +55,4 @@ async def on_message(self, event) -> None:
while True: await asyncio.sleep(6)

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.get_event_loop().run_until_complete(main())
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import traceback


class ConnectWebsocket:
class ConnectSpotWebsocket:
MAX_RECONNECTS = 5
MAX_RECONNECT_SECONDS = 60

Expand Down Expand Up @@ -154,7 +154,7 @@ async def send_message(self, msg, private: bool=False, retry_count: int=0):
await self._socket.send(json.dumps(msg))


class KrakenWsClient(object):
class KrakenSpotWSClient(object):
'''https://docs.kraken.com/websockets/#overview'''

PROD_ENV_URL = 'ws.kraken.com'
Expand All @@ -166,14 +166,14 @@ def __init__(self, client, callback=None, beta: bool=False):
self._callback = callback
self._client = client

self._pub_conn = ConnectWebsocket(
self._pub_conn = ConnectSpotWebsocket(
client=self._client,
endpoint=self.PROD_ENV_URL if not beta else BETA_ENV_URL,
callback=self.on_message,
private=False
)

self._priv_conn = ConnectWebsocket(
self._priv_conn = ConnectSpotWebsocket(
client=self._client,
endpoint=self.AUTH_PROD_ENV_URL if not beta else AUTH_BETA_ENV_URL,
callback=self.on_message,
Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
except FileNotFoundError:
long_description = DESCRIPTION

# Load the package's __version__.py module as a dictionary.
about = {}
if not VERSION:
project_slug = 'kraken'
Expand All @@ -47,14 +46,13 @@
exit()

class UploadCommand(Command):
"""Support setup.py upload."""
'''Support setup.py upload.'''

description = 'Build and publish the package.'
user_options = []

@staticmethod
def status(s):
"""Prints things in bold."""
print(f'\033[1m{s}\033[0m')

def initialize_options(self):
Expand Down Expand Up @@ -83,14 +81,13 @@ def run(self):
sys.exit()

class TestUploadCommand(Command):
"""Support setup.py test upload."""
'''Support setup.py test upload.'''

description = 'Build and test publishing the package.'
user_options = []

@staticmethod
def status(s):
"""Prints things in bold."""
print(f'\033[1m{s}\033[0m')

def initialize_options(self):
Expand Down

0 comments on commit 9a52192

Please sign in to comment.