def set_credentials(self, client_credentials, cancel_order=True): super().set_credentials(client_credentials) self._should_have_balance = False username = '' key = '' secret = '' if cancel_order: self.cancel_timed_order() try: if client_credentials is not None and 'username' in client_credentials and \ 'key' in client_credentials and 'secret' in client_credentials: username = client_credentials['username'] key = client_credentials['key'] secret = client_credentials['secret'] if len(username) != 0 and len(key) != 0 and len(secret) != 0: self._kraken_client = pykraken.Client(key=key, private_key=secret) self._signed_in_user = username self._balance_changed = True self._is_client_init = True else: self._signed_in_user = '' self._kraken_client = None except Exception as e: self.log.error("Sign in exception: {}".format(e)) self._kraken_client = None self._signed_in_user = '' self._balance_changed = False self._is_client_init = False return self._kraken_client is not None
def test_openPositions(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_openpositions() # TODO find a better test this one tests nothing assert type(t) == dict
def test_tradeVolume(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_tradevolume() # TODO find a better test assert 'currency' in t.keys()
def test_server_time(): client = pykraken.Client(API_KEY, PRIVATE_KEY, requests_kwargs=PROXY) utcnow = time.time() t = client.kpublic_time() # t_compare = datetime.strptime(t[1], '%a, %d %b %y %H:%M:%S +0000') t_compare = t[0] print("t_compare: {} utcnow: {}".format(t_compare, utcnow)) delta = t_compare - utcnow assert abs(delta)<= 10
def test_tradesHistory_queryTrades(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_tradeshistory(trades=False) assert 'count' in t.keys() txidexample = [list(t['trades'].keys())][0] t1 = client.kprivate_querytrades(txid=txidexample) assert (txidexample[0] in t1.keys())
def test_trade_balance(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_tradebalance() # print(t.keys()) # ml should be in this list, dunno why on my account it's not, maybe because i don't have margin yet tbkeys = ['eb', 'tb', 'm', 'n', 'c', 'v', 'e', 'mf'] tbbool = [k in t.keys() for k in tbkeys] assert all(tbbool)
def test_getLedgers_and_query(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_ledgers() # TODO find a better test assert 'count' in t.keys() ledgeriidlist = [list(t['ledger'].keys())[0]] t1 = client.kprivate_queryledgers(id=ledgeriidlist) # TODO find a better test assert ledgeriidlist[0] in t1.keys()
def test_addAndCancelOrder(): # add validate=True just to enter false orders client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_addorder(pair='XETHZEUR', typeo='buy', ordertype='limit', price='+5.0', volume=0.01, validate=True) assert 'descr' in t.keys()
def test_spread(): client = pykraken.Client(API_KEY, PRIVATE_KEY, requests_kwargs=PROXY) t = client.kpublic_spread(pair=['XETHXXBT']) print(t) assert 'XETHXXBT' in t.keys()
def test_no_api_key(): with pytest.raises(Exception): client = pykraken.Client()
def test_assetpairs(): client = pykraken.Client(API_KEY, PRIVATE_KEY, requests_kwargs=PROXY) t = client.kpublic_assetpairs() # TODO: find a better test assert 'XXBTZUSD' in t.keys()
def test_assets_aclass_parameter(): with pytest.raises(pykraken.exceptions.BadParamterError): client = pykraken.Client(API_KEY, PRIVATE_KEY, requests_kwargs=PROXY) t = client.kpublic_assets(aclass='mouahahah bad parameter')
def test_assets_asset_parameter(): client = pykraken.Client(API_KEY, PRIVATE_KEY, requests_kwargs=PROXY) t = client.kpublic_assets(asset=['XETH']) assert u'XETH' in t.keys()
def test_order_required_pair(): with pytest.raises(RequiredParameterError): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_addorder()
def test_balance(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_balance() assert 'XXBT' in t.keys()
def test_closed_orders(): client = pykraken.Client(key=API_KEY, private_key=PRIVATE_KEY, requests_kwargs=PROXY) t = client.kprivate_closedorders(trades=False) assert 'closed' in t.keys()