Exemplo n.º 1
0
    def sync_account_info(self, force=True):
        u = self.times.get('a')
        if not force and u:
            t = now_minus(seconds=self.sync_interval)
            if u > t:
                return False

        self.gdax.sync_accounts()
        self.times['a'] = now()
Exemplo n.º 2
0
 def export_chart():
     d = GdaxChartData(
         g,
         'ETH-USD',
         now_minus(days=1),
         now(),
         granularity=60 * 5,
     )
     d.df.to_csv(chart_path, index=False)
Exemplo n.º 3
0
    def sync_ticker_info(self, force=True):
        u = self.times.get('t')
        if not force and u:
            t = now_minus(seconds=self.sync_interval)
            if u > t:
                return False

        t = self.gdax.get_ticker(self.name)
        self._price = float(t['price'])
        self._volume24hr = float(t['volume'])
        self.times['t'] = now()
Exemplo n.º 4
0
    def sync_24hr_stats(self, force=True):
        u = self.times.get('s')
        if not force and u:
            t = now_minus(seconds=self.sync_interval)
            if u > t:
                return False

        s = self.gdax.get_24hr_stats(self.name)
        self._volume24hr = float(s['volume'])
        self._high24hr = float(s['high'])
        self._low24hr = float(s['low'])
        self.times['s'] = now()
Exemplo n.º 5
0
def get_sample_chart(size=31, price_factor=1.25, minute_interval=5):
    data = list()
    start = now_minus(hours=10)
    price = 1
    for i in range(1, size + 1):
        data.append((start, price))
        start += DateOffset(minutes=minute_interval)
        price *= price_factor

    return DataFrame(data=data,
                     columns=['time', 'price'],
                     index=range(len(data)))
Exemplo n.º 6
0
def generate_candles(product,
                     gdax=None,
                     out_path=None,
                     start=None,
                     end=None,
                     granularity=60 * 60 * 24):
    """
    Generates a .csv file containing open, high, low, close & volume
    information for a given product.

    :param product:
    :param gdax:
    :param out_path:
    :param start:
    :param end:
    :param granularity:
    :return: (GdaxChartData, str)
        Returns the generated ChartData object along with the out_path.
    """

    if gdax is None:
        gdax = Gdax()

    if out_path is None:
        import os
        from stocklook.config import config
        d = config['DATA_DIRECTORY']
        c = product.split('-')[0]
        n = '{}_candles.csv'.format(c)
        out_path = os.path.join(d, n)

    if start is None:
        from stocklook.utils.timetools import now_minus
        start = now_minus(weeks=4)

    if end is None:
        from stocklook.utils.timetools import now
        end = now()

    data = GdaxChartData(gdax, product, start, end, granularity)
    data.df.to_csv(out_path, index=False)
    get_buypoint(data)

    return data, out_path
Exemplo n.º 7
0
    def get_chart(self, time_frame='5M'):
        """
        Access to GdaxChartData objects that are automatically created,
        cached, and/or refreshed on an interval.
        :param time_frame (str, default '5M')
            The timeframe interval of chart data to get.
            5M: 5 minutes
            15M: 15 minutes
            1H: 1 hour
            4H: 4 hours
            1D: daily
        :return: (stocklook.crypto.gdax.chartdata.GdaxChartData)
        """
        assert time_frame in self.TIME_FRAMES

        key = 'chart_data_{}'.format(time_frame)
        chart = self._charts.get(key, None)
        granularity, hours_back, seconds = self.TIMEFRAME_MAP[time_frame]
        timed_out = timeout_check(key, t_data=self._t_data, seconds=seconds)
        start = now_minus(hours=hours_back)
        end = now_plus(days=1)

        if chart is None:
            from stocklook.crypto.gdax.chartdata import GdaxChartData

            chart = GdaxChartData(self.gdax,
                                  self.product_id,
                                  start,
                                  end,
                                  granularity=granularity)
            chart.get_candles()

            self._charts[key] = chart
        elif timed_out:
            chart.start = start
            chart.end = end
            chart.get_candles()

        return chart
Exemplo n.º 8
0
import pytest, os
from stocklook.crypto.gdax.chartdata import GdaxChartData
from stocklook.crypto.gdax.api import Gdax
from stocklook.utils.timetools import now_minus, now_plus

gdax = Gdax()
yesterday = now_minus(hours=6)
today = now_plus(hours=12)

FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixtures')


def test_chart_rsi():
    fp = os.path.join(FIXTURES_DIR, 'btc_test_chart.csv')
    c = GdaxChartData(gdax,
                      'BTC-USD',
                      yesterday,
                      today,
                      granularity=60*5,)
    c.df.to_csv(fp, index=False)


Exemplo n.º 9
0
"""

from stocklook.crypto.gdax import Gdax, GdaxProducts, GdaxOrderBook, GdaxChartData, get_buypoint, GdaxDatabase
from stocklook.utils.timetools import now_minus, now

if __name__ == '__main__':
    g = Gdax()
    #for a in g.accounts.values():
    #    print(a)
    #    print("\n")
    # print("Total account value: ${}".format(g.get_total_value()))
    pair = GdaxProducts.LTC_USD
    book = GdaxOrderBook(g, pair)
    product = g.get_product(pair)

    start = now_minus(days=5)
    end = now()
    granularity = 60 * 60 * 24
    chart = GdaxChartData(g, pair, start, end, granularity)

    price = product.price
    res_price, res_qty = book.get_next_resistance()
    su_price, su_qty = book.get_next_support()
    avg_vol = int(chart.avg_vol)
    avg_range = round(chart.avg_range, 2)
    avg_close = round(chart.avg_close, 2)
    avg_rsi = round(chart.avg_rsi, 2)

    cdf = chart.df
    bdf = book.get_data_frame()
Exemplo n.º 10
0
    def sync_chart_data(self):
        """
        Ensures GdaxChartData objects are created and kept up-to-date.
        These objects are assigned to GdaxAnalyzer objects so they'll
        all be analyzing the same set(s) of data refreshed on a timely basis.

        ChartData objects are assigned as follows:
            GdaxTrader.h: 4 hours of data, 5 minutes timeframes
            GdaxTrader.d: 1 day of data, 15 minutes timeframes
            GdaxTrader.w: 1 week of data, 4 hours timeframes
            GdaxTrader.m 1 month of data, 4 hours timeframes

        Default Timeframes are as follows:
            GdaxTrader.h: 3 minute refreshes - most-up-to-date
            GdaxTrader.d: 15 minute refreshes
            GdaxTrader.w: 2 hour refreshes
            GdaxTrader.m: 6 hour refreshes

        :return:
        """

        times = self.get_next_sync_times()
        t = now()
        h_due = times['h'] <= t
        d_due = times['d'] <= t
        w_due = times['w'] <= t
        m_due = times['m'] <= t

        # Hour Chart
        if self.h is None or h_due:
            start, end = now_minus(hours=4), now()
            granularity = 60 * 5

            if self.h is None:
                self.h = GdaxChartData(self.gdax,
                                       self.product,
                                       start,
                                       end,
                                       granularity)
            else:
                self.h.refresh(start=start, end=end)

            self.times['h'] = end

        # Day chart
        if self.d is None or d_due:
            start, end = now_minus(hours=24), now()
            granularity = 60 * 15
            if self.d is None:
                self.d = GdaxChartData(self.gdax,
                                       self.product,
                                       start,
                                       end,
                                       granularity)
            else:
                self.d.refresh(start=start, end=end)

            self.times['d'] = end

        # Week chart
        if self.w is None or w_due:
            start = now_minus(days=7)
            end = now()
            granularity = 60 * 60 * 4
            if self.w is None:
                self.w = GdaxChartData(self.gdax,
                                       self.product,
                                       start,
                                       end,
                                       granularity)
            else:
                self.w.refresh(start=start, end=end)

            self.times['w'] = end

        # Month chart
        if self.m is None or m_due:
            start = now_minus(months=1)
            end = now()
            granularity = 60 * 60 * 24
            if self.m is None:
                self.m = GdaxChartData(self.gdax,
                                       self.product,
                                       start,
                                       end,
                                       granularity)
            else:
                self.m.refresh(start=start, end=end)
            self.times['m'] = end

        book = self.gdax.get_book(self.product)
        # Make sure analyzers aren't missing charts.
        # if h chart is missing all are probably missing.
        for a in self.analyzers.values():
            if a.h is None:
                a.register_data(self.h, self.d, self.w, self.m)

        return self.h, self.d, self.w, self.m
Exemplo n.º 11
0
    strat_df.to_csv(pout_path, index=False)
    trade_df.to_csv(tout_path, index=False)
    print("Done: {}".format(out_path))
    try:
        top_id = int(strat_df.iloc[0]['maker_id'])
        print("Top decision maker: {}".format(strat.makers[top_id]))
    except:
        pass
    return tout_path, trade_df


if __name__ == '__main__':
    data_dir = config['DATA_DIRECTORY']
    product = 'LTC-USD'
    day_range = 60
    start = now_minus(days=60)
    end = now()
    granularity = 60 * 60 * 4
    grans = [(60 * 60, 4), (60 * 15, 3)]

    results = list()
    for i in range(30):
        fp, df = run_macd_rsi_decisions(data_dir,
                                        product,
                                        start,
                                        end,
                                        granularity,
                                        overwrite=False)
        results.append((fp, df))
        start -= pd.DateOffset(day_range)
        end -= pd.DateOffset(day_range)