예제 #1
0
def sell(base, nBase, post=True):
    """
    Execute a buy order with the following specs :
        type : limit order
        fees : applied in quote currency
        quote : eur
    By default, post is set to True to garantee maker fees are applied.

    Inputs:
        base: base to buy (uppercase)
        nBase: amount of euros to spend
        post: boolean
    """

    flags = ['fciq', 'post']
    if not post:
        flags = ['fciq']

    ticker = krakenAPI.ticker(base)
    ask = ticker['a'][0]
    price = round(ask, 2)

    api_data = {
        'pair': utils.set_pair(base),
        'type': 'sell',
        'ordertype': 'limit',
        'price': price,
        'volume': nBase / price,
        'orderflags': flags
    }
    krakenAPI.add_order(api_data)
    return price
예제 #2
0
def load_OHLC_data(base):
    """
    Load previous data corresponding to base and that is stored in csv files.
    """
    pair = utils.set_pair(base)
    filename = pair + config.PERIOD + '.csv'
    path = config.data_dir / filename
    data = pd.read_csv(path, sep=config.CSV_SEP)
    data.set_index('time', inplace=True)
    return data
예제 #3
0
def pull_OHLC_data(base):
    # get data from api
    data, last = krakenAPI.OHLC(base)
    df_data = pd.DataFrame(data, columns=config.DATA_COLUMNS)
    df_data = df_data.astype(float)
    df_data.set_index('time', inplace=True)

    # store data into csv file
    pair = utils.set_pair(base)
    filename = pair + config.PERIOD + '.csv'
    utils.dump_as_csv(content=df_data, path=config.data_dir / filename)

    return last
예제 #4
0
def OHLC(base, since=0):
    """
    Get OHLC data.
    
    Inputs :
        pair : asset pair to get OHLC data for
        interval : time frame interval in minutes (optional) :
            1 (default),
            5,
            15,
            30,
            60,
            240,
            1440,
            10080,
            21600
        since : return committed OHLC data since given id (optional, exclusive)
        
    Results:
        array of array entries :
            time (opening the candle),
            open,
            high,
            low,
            close,
            vwap,
            volume,
            count
        last : id to be used as since when pulling for new, committed OHLC data
        
    N.B. : Maximum data length returned at once : 720 values
    """
    try:
        api_method = 'OHLC'
        pair = utils.set_pair(base)
        api_data = {
            'pair': pair,
            'interval': config.TIME_FRAMES[config.PERIOD],
            'since': since
        }
        api_reply = request(api_method, api_data)
        last = api_reply['result']['last']
        #  The last entry is not committed yet, hence ignore it
        api_reply = api_reply['result'][pair][:-1]
        return api_reply, last
    except:
        return OHLC(base, since)
예제 #5
0
def ticker(base):
    """
    Get ticker information.
    For more details about the Kraken API:
    https://www.kraken.com/features/api

    Inputs :
        pair : comma delimited list of asset pairs to get info on

    Results :
        a : ask array
            price,
            whole lot volume,
            lot volume
        
        b : bid array
            price,
            whole lot volume,
            lot volume

        c : last trade closed array
            price,
            lot volume
        
        v : volume array
            today,
            last 24 hours
        
        p : volume weighted average price array
            today,
            last 24 hours
        
        t : number of trades array
            today,
            last 24 hours
        
        l : low array
            today,
            last 24 hours
        
        h : high array
            today,
            last 24 hours
        
        o : today's opening price
    
    N.B. : Today's prices start at 00:00:00 UTC
    """

    try:
        api_method = 'Ticker'
        pair = utils.set_pair(base)
        api_data = {'pair': pair}
        api_reply = request(api_method, api_data)
        api_reply = api_reply['result'][pair]
        for each in list(api_reply.keys())[:-1]:
            api_reply[each] = list(map(float, api_reply[each]))
        api_reply['o'] = float(api_reply['o'])
        return api_reply
    except:
        return ticker(base)
예제 #6
0
def update_OHLC_data_csv(base, data):
    pair = utils.set_pair(base)
    filename = pair + config.PERIOD + '.csv'
    utils.dump_as_csv(content=data, path=config.data_dir / filename)