Beispiel #1
0
 def kraken():
     api = krakenex.API()
     k = KrakenAPI(api)
     x = k.get_ticker_information('XBTUSD')
     for i in x:
         a = x.iloc[0][0][0]
     return a
Beispiel #2
0
class CryptoTracker(object):
    def __init__(self, config):
        api = krakenex.API()
        self.k = KrakenAPI(api)
        self.config = config

    def get_exchange_rate(self, crypto, fiat):
        pair = "X{}Z{}".format(crypto, fiat)
        ticker = self.k.get_ticker_information(pair)
        return ticker

    def get_currencies(self):
        return {
            'XRP': XrpHandler(self.config),
            'ETH': EthHandler(self.config),
            'XBT': XbtHandler(self.config),
            'LTC': LtcHandler(self.config),
        }

    def get_local_currency(self):
        return self.config.local_currency

    def get_fiat_currency(self):
        return self.config.fiat_currency

    def get_exchange_rates(self, base=None):
        url = 'https://api.fixer.io/latest'
        if base is not None:
            url += '?base={}'.format(base)
        req = requests.get(url)

        rates = json.loads(req.text)
        return rates['rates']

    def update_currencies(self):
        accounts = self.config.accounts

        balances = defaultdict(float)
        rates = defaultdict(float)
        crypto_currencies = self.get_currencies()

        for curr in accounts.keys():
            ohlc = self.get_exchange_rate(
                curr, crypto_currencies[curr].fiat_currency())
            if ohlc is not None and len(ohlc) > 0:
                rates[curr] = float(ohlc.iloc[0]['c'][0])
            balances[curr] += crypto_currencies[curr].update(accounts[curr])
        positions = {
            curr: balances[curr] * rates[curr]
            for curr in balances if curr in rates and curr in balances
        }
        return balances, positions
Beispiel #3
0
def calculate_capital():

    # Connect to API:
    con = krakenex.API()
    con.load_key(kraken_key_filepath)
    api = KrakenAPI(con)

    volume = api.get_account_balance()
    crypto_on_hand = volume.loc[CRYPTO][0]
    open_position = check_openPosition(crypto_on_hand)
    if open_position:
        current_price = float(
            api.get_ticker_information(CRYPTO + FIAT)['c'][0][0])
        return round(current_price * crypto_on_hand, 2)
    else:
        return round(float(volume.loc[FIAT][0]), 2)
Beispiel #4
0
def get_price_from_kraken(kraken_token):
    krakenApi = KrakenAPI(krakenex.API());
    krakenprice = krakenApi.get_ticker_information(kraken_token).loc[kraken_token]['a'][0]
    return float(krakenprice)
Beispiel #5
0
#####################################################################
# Get tickers
#####################################################################

pd.set_option('display.max_rows',
              None)  #set pandas output to display full dataset

api = krakenex.API()
k = KrakenAPI(api)
pairs = k.get_tradable_asset_pairs()
print(type(pairs))
print(pairs)

pd.set_option('display.max_columns',
              None)  #set pandas output to display full dataset
eurgbp = k.get_ticker_information("EURGBP")
print(eurgbp)
## BTCZAR
#res = requests.get("https://api.kraken.com/0/public/Assets?currency=ZUSDZJPY")
#res_string = res.content.decode() #convert byte object to str
#btczar = json.loads(res_string) #convert str to dict
#print(btczar)

# parse BTCZAR
#for key,value in btczar.items():
#    if key == 'created':
#       valr_btczar_timestamp = value
#      #TO-DO:epoch time conversion for writing to xls
#    if key == 'askPrice':
#       valr_btczar_askprice = value