Ejemplo n.º 1
0
def get_data(granularity=3600, max_=200):
    eth_data = gdax_data.get_data("ETH-USD", granularity, max_)
    btc_data = gdax_data.get_data("BTC-USD", granularity, max_)
    ltc_data = gdax_data.get_data("LTC-USD", granularity, max_)

    eth_df = pd.DataFrame(list(reversed(eth_data)), columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    btc_df = pd.DataFrame(list(reversed(btc_data)), columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    ltc_df = pd.DataFrame(list(reversed(ltc_data)), columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    return {"eth": eth_df, "btc": btc_df, "ltc": ltc_df}
Ejemplo n.º 2
0
def run(interval,
        product_id="ETH-USD",
        window=20,
        sd=2,
        lower_limit=10,
        upper_limit=90):
    best_bid_ask = trading.get_best_bid_ask(product_id)
    best_bid = float(best_bid_ask['bid'])

    data, start, end = gdax_data.get_data(product_id, interval, window)
    df = pd.DataFrame(
        list(reversed(data)),
        columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    indicators.add_bol(df, window, sd)

    last_data = df.iloc[-1]

    upper_bol = round(float(last_data['Bol_upper']), 2)
    lower_bol = round(float(last_data['Bol_lower']), 2)
    bol_range = upper_bol - lower_bol
    range_pc = round(((1 - (upper_bol - best_bid) / bol_range) * 100), 2)

    res_string = ""
    res_score = 0

    if range_pc > upper_limit:
        res = "SELL"
        res_score = -10
    elif range_pc < lower_limit:
        res = "BUY"
        res_score = 10
    else:
        res = "-"

    return {"score": res_score, "indicator": "Boll"}
Ejemplo n.º 3
0
def run(interval, product_id="ETH-USD"):

    data, start, end = gdax_data.get_data(product_id, interval, 3)
    df = pd.DataFrame(
        list(reversed(data)),
        columns=['date', 'low', 'high', 'open', 'close', 'volume'])

    indicators.check_engulfing(df)
    indicators.check_hammer(df)
    indicators.check_doji(df)

    res_string = ""
    res_score = 0
    last_data_point = df.iloc[-1]
    if bool(last_data_point['engulfing']) is True:
        res_string = res_string + "BUY (engulfing)"
        res_score = res_score + 10

    if bool(last_data_point['hammer']) is True:
        res_string = res_string + "BUY (hammer)"
        res_score = res_score + 10

    if bool(last_data_point['doji']) is True:
        res_string = res_string + "BUY (doji)"
        res_score = res_score + 10

    return {"score": res_score, "indicator": res_string}
Ejemplo n.º 4
0
def run(intervals, product_id="ETH-USD", window=3):
    is_reversed = True
    for interval in intervals:
        data, start, end = gdax_data.get_data(product_id, interval, 200)
        if is_reversed:
            df = pd.DataFrame(
                list(reversed(data)),
                columns=['date', 'low', 'high', 'open', 'close', 'volume'])
        else:
            df = pd.DataFrame(
                list(data),
                columns=['date', 'low', 'high', 'open', 'close', 'volume'])

        if not is_reversed:
            df['temp'] = df['open']
            df['open'] = df['close']
            df['close'] = df['temp']

        indicators.check_color(df)

        have_position = False

        num_green = 0
        fiat_start_balance = 1000.0
        fiat_balance = fiat_start_balance
        eth_balance = 0.0
        close_price = 0.0

        for index, row in df.iterrows():
            close_price = row['close']

            if row['color'] == 'green':
                num_green = num_green + 1

            if have_position and row['color'] == 'green':
                print("HOLD SHIZZLE " + str(close_price))

            if not have_position and num_green == 3:
                eth_balance = fiat_balance / close_price
                fiat_balance = 0.0
                have_position = True
                num_green = 0
                print("BUY " + str(close_price))

            if have_position and row['color'] == 'red':
                fiat_balance = eth_balance * close_price
                eth_balance = 0.0
                have_position = False
                num_green = 0
                print("SELL " + str(close_price))

        print(str(fiat_balance) + " " + str(close_price * eth_balance))
Ejemplo n.º 5
0
def plot(product_id, granularity=60, max=200):
    crypto_id = product_id.upper()
    product_id = crypto_id + '-USD'
    gdax_data_, start, end = gdax_data.get_data(product_id, granularity, max)

    df = pd.DataFrame(
        list(reversed(gdax_data_)),
        columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    print(trading.get_best_bid_ask(product_id))

    indicators.add_macd(df)
    indicators.add_bol(df)

    fig, axes = plt.subplots(nrows=2, ncols=1)
    df.plot(y=['close', 'Bol_upper', 'Bol_lower'], ax=axes[0])
    df.plot(y=['MACD'], ax=axes[1])
    plt.show(block=not standalone)
    return
Ejemplo n.º 6
0
def run(interval, product_id="ETH-USD", slow_ema=26, fast_ema=12, history=3):

    data, start, end = gdax_data.get_data(product_id, interval,
                                          (slow_ema + history))
    df = pd.DataFrame(
        list(reversed(data)),
        columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    indicators.add_macd(df, slow_ema, fast_ema)

    is_last_above_zero = False
    is_last_below_zero = False
    rest_above_zero = False
    rest_below_zero = False
    for i in range(0, history):
        data = df.iloc[-1 - i]

        if i == 0:
            if float(data['MACD']) > 0.0:
                is_last_above_zero = True
            else:
                is_last_below_zero = True

        if i != 0:
            if float(data['MACD']) > 0.0:
                rest_above_zero = True
            else:
                rest_below_zero = True
                break

    res_string = ""
    res_score = 0

    if is_last_above_zero and rest_below_zero:
        res = "BUY"
        res_score = 10
    elif is_last_below_zero and rest_above_zero:
        res = "SELL"
        res_score = -10
    else:
        res = "-"

    return {"score": res_score, "indicator": "MACD"}
Ejemplo n.º 7
0
def run(intervals, product_id="ETH-USD", window=19, history=5):
    results = []
    for interval in intervals:
        data, start, end = gdax_data.get_data(product_id, interval,
                                              (window + history))

        df = pd.DataFrame(
            list(reversed(data)),
            columns=['date', 'low', 'high', 'open', 'close', 'volume'])
        indicators.add_ema('mean', df, window)

        df = df.dropna(how='any').reset_index(drop=True)
        x = list(range(1, history + 1))
        y = df['mean'].values[-history:]
        z = np.polyfit(x=x, y=y, deg=1)
        p = np.poly1d(z)
        results.append({
            "interval": interval,
            "score": z[0],
            "indicator": "Slope"
        })
        print(str(interval) + " " + str(z[0]))
    return results
Ejemplo n.º 8
0
import pandas as pd

import indicators
import trading
from data import gdax_data

intervals = [60, 300, 600, 1200, 3600]

best_bid_ask = trading.get_best_bid_ask('ETH-USD')
best_bid = float(best_bid_ask['bid'])

display_str = ""

for int_ in intervals:
    data, start, end = gdax_data.get_data("ETH-USD", int_, 200)
    df = pd.DataFrame(list(reversed(data)), columns=['date', 'low', 'high', 'open', 'close', 'volume'])
    indicators.add_macd(df)
    indicators.add_bol(df)

    last_data = df.iloc[-1]

    macd = round(float(last_data['MACD']), 2)
    upper_bol = round(float(last_data['Bol_upper']), 2)
    lower_bol = round(float(last_data['Bol_lower']), 2)
    bol_range = upper_bol - lower_bol
    range_pc = round(((1 - (upper_bol - best_bid) / bol_range) * 100), 2)

    print(str(int_) + " " + str(range_pc) + "/" + str(macd) + "  ["
          + str(lower_bol) + " <- " + str(best_bid) + " -> " + str(upper_bol) + "]")
    time.sleep(1)