Ejemplo n.º 1
0
def load_data(start):

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

    # Load past trading data:
    count = 0
    total_count = 1
    df_list = []
    unix_start = api.datetime_to_unixtime(pd.to_datetime(start))
    while count < total_count:
        df, all_count = api.get_trades_history(start=unix_start, ofs=count)
        df = df[df['pair'] == CRYPTO + FIAT]
        df_list.append(df)
        total_count = all_count
        count += len(df)
    df = pd.concat(df_list).reset_index()
    df = df.drop_duplicates()

    # Convert to Central time:
    df['dtime'] = pd.to_datetime(
        pd.to_datetime(df['dtime']).dt.tz_localize('UTC').dt.tz_convert(
            'US/Central').dt.strftime('%Y-%m-%d %H:%M:%S'))

    # Merge trades with the same order id:
    df_wrangled = df.reset_index().groupby('ordertxid', as_index=False).agg({
        'dtime':
        'min',
        'type':
        'min',
        'ordertype':
        'min',
        'price':
        'min',
        'cost':
        'sum',
        'fee':
        'sum',
        'vol':
        'sum'
    }).sort_values('dtime').reset_index(drop=True)
    # Build buy/sell matching ids:
    df_wrangled['trade_matchID'] = 0
    buy = False
    matchID = 1
    for i, row in df_wrangled.iterrows():
        # Skip the first trade if it's a sell
        if row['type'] == 'sell':
            if buy:
                df_wrangled['trade_matchID'][i] = matchID
                matchID += 1
                buy = False
            else:
                continue
        elif row['type'] == 'buy':
            df_wrangled['trade_matchID'][i] = matchID
            buy = True

    # Put the buy and the sell on the same line:
    df_sell = df_wrangled[df_wrangled['type'] == 'sell'].set_index(
        'trade_matchID')
    df_buy = df_wrangled[df_wrangled['type'] == 'buy'].set_index(
        'trade_matchID')
    df_trade = df_buy.merge(df_sell,
                            how='left',
                            left_index=True,
                            right_index=True,
                            suffixes=['_buy', '_sell'])

    # Build new fields:
    df_trade['time_held'] = df_trade['dtime_sell'] - df_trade['dtime_buy']
    df_trade['time_held'] = [str(x) for x in df_trade['time_held']]
    df_trade['fee_total'] = df_trade['fee_buy'] + df_trade['fee_sell']
    df_trade['abs_return'] = df_trade['cost_sell'] - df_trade['cost_buy']
    df_trade['feeAdjusted_abs_return'] = df_trade['cost_sell'] - df_trade[
        'fee_total'] - df_trade['cost_buy']
    df_trade['pct_return'] = df_trade['abs_return'] / df_trade['cost_buy']
    df_trade['feeAdjusted_pct_return'] = df_trade[
        'feeAdjusted_abs_return'] / df_trade['cost_buy']
    df_trade['winning_trade'] = [
        1 if x > 0 else 0 for x in df_trade['feeAdjusted_pct_return']
    ]
    return df_trade
Ejemplo n.º 2
0
def get_open_orders(trades=None, userref=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    #result = kraken.query_private('OpenOrders', {'trades': trades, 'userref':userref})
    result = kraken.query_private('OpenOrders', {})
    return result
Ejemplo n.º 3
0
#
#
# Balance Result:
# {'error': [], 'result': {'ZUSD': '0.0000', 'XXBT': '0.0434289700'}}
# ISSUE WITH STRING VALUES
#
#

import os
import schedule
import time, datetime
import krakenex
from influxdb import InfluxDBClient

k = krakenex.API()
k.load_api_key(os.environ.get('KRAKEN_API_KEY'),
               os.environ.get('KRAKEN_API_SECRET'))

infx_client = InfluxDBClient(host=os.environ.get('INFLUXDB_HOST'),
                             port=os.environ.get('INFLUXDB_PORT'))
infx_client.switch_database('db')


def collect():
    balance_result = k.query_private('Balance')
    balance_return = balance(balance_result)
    print(balance_return)


def balance(balance_result):
    # data = [
Ejemplo n.º 4
0
def get_ticker_info(pair):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Ticker', {'pair': pair})
    return result
Ejemplo n.º 5
0
def get_recent_trades(pair, since=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Trades', {'pair': pair, 'since': since})
    return result
Ejemplo n.º 6
0
def query_ledgers(ids):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_private('QueryLedgers', {'id': ids})
    return result
Ejemplo n.º 7
0
def get_server_time():
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Time')
    return result
Ejemplo n.º 8
0
def initApi(key, secret):
    api = krakenex.API(key=key, secret=secret)
    k = pykrakenapi.KrakenAPI(api, retry=0, crl_sleep=0)
    return k
Ejemplo n.º 9
0
class Kraken(ExchangeBase):
    api = krakenex.API()
    k = KrakenAPI(api)

    def __init__(self):
        super().__init__()
        self.wallets["LTC"] = Wallet("LTC", 0)
        self.wallets["ETH"] = Wallet("ETH", 0)
        self.wallets["BCH"] = Wallet("BCH", 0)
        self.wallets["BTC"] = Wallet("BTC", 0)
        self.wallets["USD"] = Wallet("USD", 500)
        self.valueWallet = self.wallets["USD"]

        # Maker fee
        # self.fee = 0.0016
        # Taker fee
        self.fee = 0.0026

    def get_last_trade_price(self, symbol):
        my_symbol = symbol.replace("BTC", "XBT").replace("-", "")
        kraken_ticker = self.k.get_ticker_information(my_symbol)
        # c = last trade
        return float(kraken_ticker['c'][0][0])

    def get_buy_price_for(self, key):
        # Maker order
        # return self.getHighestBidPriceFor(key) * (1 - self.fee)) * (1 + self.fee)
        # Taker order
        return self.get_market_buy_price_for(key, self.arbitrar.amount * (1 - self.fee)) * (1 + self.fee)

    def get_sell_price(self):
        key = self.valueWallet.currency
        # Maker order
        # return self.getLowestAskPriceFor(key) * (1 - self.fee)) * (1 - self.fee)
        # Taker order
        return self.get_market_sell_price_for(key, self.wallets[key].amount * (1 - self.fee)) * (1 - self.fee)

    def get_highest_bid_price_for(self, key):
        symbol = key + "-" + self.arbitrar.currency
        pair = symbols[symbol]
        book = self.k.get_order_book(pair)[1].astype('float').sort_values(by=['price'], ascending=False)
        return float(book.iloc[0]['price'])

    def get_lowest_ask_price_for(self, key):
        symbol = key + "-" + self.arbitrar.currency
        pair = symbols[symbol]
        book = self.k.get_order_book(pair)[0].astype('float').sort_values(by=['price'])
        return float(book.iloc[0]['price'])

    def get_market_buy_price_for(self, key, amount):
        symbol = key + "-" + self.arbitrar.currency
        pair = symbols[symbol]
        book = self.k.get_order_book(pair)[0].astype('float').sort_values(by=['price'])
        full_amount = amount
        price = i = 0
        while amount > 0:
            volume = float(book.iloc[i]['volume'])
            this_price = float(book.iloc[i]['price'])
            this_amount = amount if amount < volume * this_price else volume * this_price
            price += this_price * this_amount / full_amount
            amount -= this_amount
            i += 1
        return price

    def get_market_sell_price_for(self, key, amount):
        symbol = key + "-" + self.arbitrar.currency
        pair = symbols[symbol]
        book = self.k.get_order_book(pair)[1].astype('float').sort_values(by=['price'], ascending=False)
        full_amount = amount
        price = i = 0
        while amount > 0:
            volume = float(book.iloc[i]['volume'])
            this_price = float(book.iloc[i]['price'])
            this_amount = amount if amount < volume else volume
            price += this_price * this_amount / full_amount
            amount -= this_amount
            i += 1
        return price

    def get_name(self):
        return "kraken"
Ejemplo n.º 10
0
import socket
#import gdax #pip install gdax
from twilio.rest import Client  #pip install twilio
#from bitfinex.client import Client as bfxClient
'''
This used to be a program that would trade the time delay between Kraken and GDAX/Bitfinex
but that difference is now gone so it's just used as an interface for other trading programs to
take methods from
'''

#for twilio
client = Client("AC1c40800c09f14885137023f22ac618b6",
                "264ebf359aedd9157f654f160ca22eb7")

#for Kraken
k = krakenex.API()  #private methods
k.load_key('kraken.key')
kpublic = krakenex.API()  # public methods

# transaction IDs/info for closing extra trades:
mainTXID = ''
closeTXID = ''
stoplossTXID = ''
main = ''
trade = ''
closedirection = ''
inPosition = False

# Api Key Strings:
_RATE_LIMIT_ERROR_ = 'EAPI:Rate limit exceeded'
_K_CURR_ = 'XETHXXBT'
Ejemplo n.º 11
0
 def __init__(self, key_path):
     self.kraken_api = krakenex.API()
     self.kraken_api.load_key(key_path)
Ejemplo n.º 12
0
def create_client_from_file(filename):
    kraken_client = krakenex.API()
    kraken_client.load_key(filename)
    return kraken_client
Ejemplo n.º 13
0
# =============================================================================
# Script working
# (a) Hard stop to prevent loss of capital
# Initially one that takes account balance and cashes everything 
# out when less than a certain value.
# TODO:
# 1) What errors need to be caught

# set mininum account balance
min_bal = 100000
invested = True
pause_period = 60 # seconds

# location of the api keys
api_dir ="/home/austin/Dropbox/kraken_data/api"
k = krakenex.API() # start api instance and load keys
k.load_key(os.path.join(api_dir, 'kraken.key'))

while(invested):

    # get the current balance
    curr_bal = k.query_private('Balance')

    # if the current balance is below our minimum
    if (curr_bal < min_bal): 
 
        # get open positions
        # START: this code is copied verbatim from 
        # https://github.com/veox/python3-krakenex/blob/master/examples/print-open-positions.py
        
        # prepare request
Ejemplo n.º 14
0
def fetch_data():
    api = krakenex.API()
    k = KrakenAPI(api)
    ohlc, last = k.get_ohlc_data("BCHUSD")
    return ohlc, last
Ejemplo n.º 15
0
def get_trades_history(ofs, type=None, trades=None, start=None, end=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_private('TradesHistory', {'ofs': ofs})
    return result
Ejemplo n.º 16
0
#linear regression and data plotting algorithm

#third priority is integrating threading such that both processes run concurrently
#fourth priority is making a GUI
#fifth and final priority is implementing machine learning techniques
import krakenex
import time
import datetime
import threading
from tkinter import *
from queue import Queue
key = krakenex.API()
key.load_key('kraken.key')
pair = 'XXBTZUSD'
init_price = 0
init_quant = 0
iterator = 1
root = Tk()
run_tot_price = 0
run_tot_quant = 0
pq_ratio = 0
prev_ratio = 0
count = 1


def updateGUI(text):
    GUISTR = Label(root, text=text)
    GUISTR.pack()


def compute_variance(price, quantity, average_price, average_quant):
Ejemplo n.º 17
0
def query_trades_info(txid, trades=False):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_private('QueryTrades', {'txid': txid})
    return result
Ejemplo n.º 18
0
 def __init__(self):
     self.cache = ExpiringDict(max_len=100, max_age_seconds=5)
     self.logger = Logger().get_logger()
     self.k = krakenex.API()
Ejemplo n.º 19
0
def cancel_open_order(txid):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_private('CancelOrder', {'txid': txid})
    return result
Ejemplo n.º 20
0
 def __init__(self) :
     self.k = krakenex.API()
     self.k.load_key('kraken.key')
Ejemplo n.º 21
0
def get_asset_pairs(info=None, pair=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Assets', {'info': info, 'pair': pair})
    return result
Ejemplo n.º 22
0
    def __init__(self, pair, api_key_file, minimum_fund, percent_alloc,
                 sleepage):

        self.pair = pair
        self.api_key_file = api_key_file
        self.minimum_fund = minimum_fund
        self.k = krakenex.API()
        self.k.load_key(self.api_key_file)
        self.balance = self.k.query_private('Balance')['result']
        self.open_orders = self.k.query_private('OpenOrders')['result']['open']
        #self.trades = self.k.query_private('TradesHistory')
        self.assets = list(self.balance.keys())
        self.tickers = {
            'BTC/EUR': 'XXBT',
            'ETH/EUR': 'XETH',
            'DASH/EUR': 'XDASH',
            'XRP/EUR': 'XXRP',
            'DOT/EUR': 'DOT',
            'BAT/EUR': 'BAT',
            'ADA/EUR': 'ADA'
        }
        self.percent_alloc = percent_alloc
        self.sleepage = sleepage
        self.fund = float(self.balance['ZEUR'])
        self.buying_power = self.fund * self.percent_alloc
        try:
            self.crypto_value = float(self.balance[self.tickers[self.pair]])
        except:
            pass
        self.candle_rankings = {
            "CDL3LINESTRIKE_Bull": 1,
            "CDL3LINESTRIKE_Bear": 2,
            "CDL3BLACKCROWS_Bull": 3,
            "CDL3BLACKCROWS_Bear": 3,
            "CDLEVENINGSTAR_Bull": 4,
            "CDLEVENINGSTAR_Bear": 4,
            "CDLTASUKIGAP_Bull": 5,
            "CDLTASUKIGAP_Bear": 5,
            "CDLINVERTEDHAMMER_Bull": 6,
            "CDLINVERTEDHAMMER_Bear": 6,
            "CDLMATCHINGLOW_Bull": 7,
            "CDLMATCHINGLOW_Bear": 7,
            "CDLABANDONEDBABY_Bull": 8,
            "CDLABANDONEDBABY_Bear": 8,
            "CDLBREAKAWAY_Bull": 10,
            "CDLBREAKAWAY_Bear": 10,
            "CDLMORNINGSTAR_Bull": 12,
            "CDLMORNINGSTAR_Bear": 12,
            "CDLPIERCING_Bull": 13,
            "CDLPIERCING_Bear": 13,
            "CDLSTICKSANDWICH_Bull": 14,
            "CDLSTICKSANDWICH_Bear": 14,
            "CDLTHRUSTING_Bull": 15,
            "CDLTHRUSTING_Bear": 15,
            "CDLINNECK_Bull": 17,
            "CDLINNECK_Bear": 17,
            "CDL3INSIDE_Bull": 20,
            "CDL3INSIDE_Bear": 56,
            "CDLHOMINGPIGEON_Bull": 21,
            "CDLHOMINGPIGEON_Bear": 21,
            "CDLDARKCLOUDCOVER_Bull": 22,
            "CDLDARKCLOUDCOVER_Bear": 22,
            "CDLIDENTICAL3CROWS_Bull": 24,
            "CDLIDENTICAL3CROWS_Bear": 24,
            "CDLMORNINGDOJISTAR_Bull": 25,
            "CDLMORNINGDOJISTAR_Bear": 25,
            "CDLXSIDEGAP3METHODS_Bull": 27,
            "CDLXSIDEGAP3METHODS_Bear": 26,
            "CDLTRISTAR_Bull": 28,
            "CDLTRISTAR_Bear": 76,
            "CDLGAPSIDESIDEWHITE_Bull": 46,
            "CDLGAPSIDESIDEWHITE_Bear": 29,
            "CDLEVENINGDOJISTAR_Bull": 30,
            "CDLEVENINGDOJISTAR_Bear": 30,
            "CDL3WHITESOLDIERS_Bull": 32,
            "CDL3WHITESOLDIERS_Bear": 32,
            "CDLONNECK_Bull": 33,
            "CDLONNECK_Bear": 33,
            "CDL3OUTSIDE_Bull": 34,
            "CDL3OUTSIDE_Bear": 39,
            "CDLRICKSHAWMAN_Bull": 35,
            "CDLRICKSHAWMAN_Bear": 35,
            "CDLSEPARATINGLINES_Bull": 36,
            "CDLSEPARATINGLINES_Bear": 40,
            "CDLLONGLEGGEDDOJI_Bull": 37,
            "CDLLONGLEGGEDDOJI_Bear": 37,
            "CDLHARAMI_Bull": 38,
            "CDLHARAMI_Bear": 72,
            "CDLLADDERBOTTOM_Bull": 41,
            "CDLLADDERBOTTOM_Bear": 41,
            "CDLCLOSINGMARUBOZU_Bull": 70,
            "CDLCLOSINGMARUBOZU_Bear": 43,
            "CDLTAKURI_Bull": 47,
            "CDLTAKURI_Bear": 47,
            "CDLDOJISTAR_Bull": 49,
            "CDLDOJISTAR_Bear": 51,
            "CDLHARAMICROSS_Bull": 50,
            "CDLHARAMICROSS_Bear": 80,
            "CDLADVANCEBLOCK_Bull": 54,
            "CDLADVANCEBLOCK_Bear": 54,
            "CDLSHOOTINGSTAR_Bull": 55,
            "CDLSHOOTINGSTAR_Bear": 55,
            "CDLMARUBOZU_Bull": 71,
            "CDLMARUBOZU_Bear": 57,
            "CDLUNIQUE3RIVER_Bull": 60,
            "CDLUNIQUE3RIVER_Bear": 60,
            "CDL2CROWS_Bull": 61,
            "CDL2CROWS_Bear": 61,
            "CDLBELTHOLD_Bull": 62,
            "CDLBELTHOLD_Bear": 63,
            "CDLHAMMER_Bull": 65,
            "CDLHAMMER_Bear": 65,
            "CDLHIGHWAVE_Bull": 67,
            "CDLHIGHWAVE_Bear": 67,
            "CDLSPINNINGTOP_Bull": 69,
            "CDLSPINNINGTOP_Bear": 73,
            "CDLUPSIDEGAP2CROWS_Bull": 74,
            "CDLUPSIDEGAP2CROWS_Bear": 74,
            "CDLGRAVESTONEDOJI_Bull": 77,
            "CDLGRAVESTONEDOJI_Bear": 77,
            "CDLHIKKAKEMOD_Bull": 82,
            "CDLHIKKAKEMOD_Bear": 81,
            "CDLHIKKAKE_Bull": 85,
            "CDLHIKKAKE_Bear": 83,
            "CDLENGULFING_Bull": 84,
            "CDLENGULFING_Bear": 91,
            "CDLMATHOLD_Bull": 86,
            "CDLMATHOLD_Bear": 86,
            "CDLHANGINGMAN_Bull": 87,
            "CDLHANGINGMAN_Bear": 87,
            "CDLRISEFALL3METHODS_Bull": 94,
            "CDLRISEFALL3METHODS_Bear": 89,
            "CDLKICKING_Bull": 96,
            "CDLKICKING_Bear": 102,
            "CDLDRAGONFLYDOJI_Bull": 98,
            "CDLDRAGONFLYDOJI_Bear": 98,
            "CDLCONCEALBABYSWALL_Bull": 101,
            "CDLCONCEALBABYSWALL_Bear": 101,
            "CDL3STARSINSOUTH_Bull": 103,
            "CDL3STARSINSOUTH_Bear": 103,
            "CDLDOJI_Bull": 104,
            "CDLDOJI_Bear": 104
        }
Ejemplo n.º 23
0
def get_order_book(pair, count=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Depth', {'pair': pair, 'count': count})
    return result
Ejemplo n.º 24
0
    def __init__(self,
                 test_session=True,
                 account_type="starter",
                 key="",
                 secret=""):
        """
        in fact all functions work in the same way, if the Kapi
        object is not live, each function will make a call to
        connection

        :param live_connection:
        :param test_session:
        :param key: the key used for kraken authentication
        :param secret: the secret used for kraken authentication
        """

        if account_type not in ["starter", "intermediate", "pro"]:
            raise Exception(
                f"Invalid parameter for account_type: {account_type}")

        if not isinstance(test_session, bool):
            raise Exception(
                f"Invalid parameter for test_section: {test_session}")

        self._api = krakenex.API(key, secret)
        self._test_session = test_session
        self._account_type = account_type

        self._max_api_counter = {
            "starter": 15,
            "intermediate": 20,
            "pro": 20,
        }[self._account_type]
        self._api_call_counter = 0

        self._max_num_orders = {
            "starter": 60,
            "intermediate": 80,
            "pro": 225,
        }[self._account_type]
        self._order_counter = 0

        self._max_rate_count = {
            "starter": 60,
            "intermediate": 125,
            "pro": 180,
        }[self._account_type]
        self._order_rate_counter = 0

        self._api_counter_decay = {
            "starter": 0.33,
            "intermediate": 0.5,
            "pro": 1.,
        }[self._account_type]

        self._ratecount_decay = {
            "starter": 1.,
            "intermediate": 2.34,
            "pro": 3.75,
        }[self._account_type]

        self._last_pair_used = None
        self._last_query_time = None
Ejemplo n.º 25
0
def get_recent_spread_data(pair, since=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_public('Spread', {'pair': pair, 'since': since})
    # Note: returns arrays of [time, bid, ask]
    return result
Ejemplo n.º 26
0
	def __init__(self, keyfile="kraken.key"):
		self.k = krakenex.API()
		self.k.load_key(keyfile)
Ejemplo n.º 27
0
from Utils import notify, loadConfig

logging.basicConfig(filename="log.log",
                    format='%(asctime)s %(levelname)s: %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S',
                    level=logging.DEBUG)

config = loadConfig("config.ini")

if config["debugOnConsole"]:
    stderrLogger = logging.StreamHandler()
    stderrLogger.setFormatter(
        logging.Formatter('%(asctime)s %(levelname)s: %(message)s'))
    logging.getLogger().addHandler(stderrLogger)

exchange = krakenex.API()
exchange.load_key(config["apiFileName"])

api = KrakenApi(exchange)
dailyTimeframe = 1440
fourHourTimeframe = 240

logging.info(config["botName"] + " started up!")
if config["notifications"]:
    notify(config["botName"], config["botId"], config["chatId"], "Started up!")

lastCandles = api.getCandlesSinceTime(config["pair"],
                                      time() - 86400 * (config["days"] + 1),
                                      dailyTimeframe)[:-1]
lastDailyCandle = api.getLastCandle(config["pair"], dailyTimeframe)
lastFourHourCandle = api.getLastCandle(config["pair"], fourHourTimeframe)
Ejemplo n.º 28
0
def get_query_orders(txid, trades=None, userref=None):
    kraken = krakenex.API(key=public_key, secret=private_key)
    result = kraken.query_private('QueryOrders', {'txid': txid})
    return result
Ejemplo n.º 29
0
        c_price = config['PRICE']
        c_type = config['TYPE']
        c_api = config['API']

        # Seconds to delay each iteration
        delay = int(c_time['delay'])

        # Sell every X minutes
        delay_sell = (60 / delay) * int(c_time['attempt_minutes'])

        # API variables
        api_key = c_api['key']
        api_sec = c_api['sec']

        # Kraken API variables
        k = krakenex.API(key=api_key, secret=api_sec)

        # Trade variables
        buy_at = Decimal(0.67)
        sell_at = Decimal(0.75)
        max_buy = Decimal(c_price['max_buy'])
        coin = c_type['coin']
        currency = c_type['currency']

        # Dictionaries to send
        pair = '{coin}{currency}'.format(coin=coin, currency=currency)
        buy_dict = {
            'pair': pair,
            'ordertype': 'market',
            'type': 'buy',
            'volume': Decimal(c_volume['buy'])
Ejemplo n.º 30
0
        help='Sets the periodicity of order book queries in seconds.'
    )
    parser.add_argument(
        '-w',
        '--write_period',
        type=float,
        default=3600,
        required=False,
        help='Sets the write periodicity to S3 in seconds.'
    )
    args = parser.parse_args()

    if args.sentry:
        sentry_sdk.init(args.sentry)  # handles error alerting via email

    kraken = krakenex.API()  # starts kraken session

    trade_ledger = []
    time_id = args.time_id  # used as initial time stamp for kraken to get data from
    collection_cycle_start_time = time.time()  # tracking for upload periodicity to S3

    if time_id == -1:  # set time id to current time
        time_id = get_kraken_server_time() * 10 ** 9

    while True:

        # query trades
        query_time = time.time()
        new_trades, time_id = get_recent_trade_data(args.pair, time_id)
        trade_ledger += new_trades
        logging.info("Current number of collected trades in memory: %s", len(trade_ledger))