Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kraken integration #144

Open
wants to merge 16 commits into
base: development
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions blankly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from blankly.frameworks.strategy import StrategyState as StrategyState
from blankly.frameworks.screener.screener import Screener
from blankly.frameworks.screener.screener_state import ScreenerState
from blankly.exchanges.interfaces.kraken.kraken import Kraken

from blankly.exchanges.managers.ticker_manager import TickerManager
from blankly.exchanges.managers.orderbook_manager import OrderbookManager
Expand Down
4 changes: 3 additions & 1 deletion blankly/exchanges/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from blankly.exchanges.interfaces.alpaca.alpaca_interface import AlpacaInterface
from blankly.exchanges.interfaces.binance.binance_interface import BinanceInterface
from blankly.exchanges.interfaces.kucoin.kucoin_interface import KucoinInterface
from blankly.exchanges.interfaces.kraken.kraken_interface import KrakenInterface
from blankly.exchanges.interfaces.okx.okx_interface import OkxInterface



class Exchange(ABCExchange, abc.ABC):
interface: ABCExchangeInterface

Expand Down Expand Up @@ -83,6 +83,8 @@ def construct_interface_and_cache(self, calls):
self.interface = KucoinInterface(self.__type, calls)
elif self.__type == "okx":
self.interface = OkxInterface(self.__type, calls)
elif self.__type == "kraken":
self.interface = KrakenInterface(self.__type, calls)

blankly.reporter.export_used_exchange(self.__type)

Expand Down
Empty file.
75 changes: 75 additions & 0 deletions blankly/exchanges/interfaces/kraken/kraken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Kraken definition & setup
Copyright (C) 2022 Emerson Dove

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from blankly.exchanges.exchange import Exchange
from blankly.exchanges.auth.auth_constructor import AuthConstructor
from blankly.utils import info_print
from blankly.exchanges.interfaces.paper_trade.paper_trade_interface import PaperTradeInterface
from blankly.exchanges.interfaces.kraken.kraken_interface import KrakenInterface


class Kraken(Exchange):
def __init__(self, portfolio_name=None, keys_path="keys.json", settings_path=None):
Exchange.__init__(self, "kraken", portfolio_name, settings_path)

# Load the auth from the keys file
auth = AuthConstructor(keys_path, portfolio_name, 'kraken', ['API_KEY', 'API_SECRET', 'sandbox'])

keys = auth.keys

sandbox = super().evaluate_sandbox(auth)

try:
import krakenex
except ImportError:
raise ImportError("Please \"pip install krakenex\" to use kraken with blankly.")

calls = krakenex.API()
#calls.load_key('tests/config/keys.json')
calls.__init__(keys['API_KEY'], keys['API_SECRET'])

# Always finish the method with this function
super().construct_interface_and_cache(calls)

# Kraken is unique because we can continue by wrapping the interface in paper trade
if sandbox:
info_print('The sandbox setting is enabled for this key. Kraken has been created as a '
'paper trading instance.')
self.interface = PaperTradeInterface(KrakenInterface(calls, settings_path))

"""
Builds information about the asset on this exchange by making particular API calls
"""

def get_asset_state(self, symbol):
"""
This determines the internal properties of the exchange block.
Should be implemented per-class because it requires different types of interaction with each exchange.
"""
# TODO Populate this with useful information
return self.interface.get_account(symbol)

def get_exchange_state(self):
"""
Exchange state is the external properties for the exchange block
"""
# TODO Populate this with useful information
return self.interface.get_fees()

def get_direct_calls(self) -> dict:
return self.calls
Loading