예제 #1
0
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info("select coin online from %s to %s"
                     % (datetime.fromtimestamp(end - (DAY * volume_average_days) - volume_forward).strftime('%Y-%m-%d %H:%M'),
                        datetime.fromtimestamp(end - volume_forward).strftime('%Y-%m-%d %H:%M')))

        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        if k.endswith('_BTC'):
                            # BTCが後ろなら逆数にする
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(self.__get_total_volume(pair=k, global_end=end,
                                                               days=volume_average_days,
                                                               forward=volume_forward))
        self._df = pd.DataFrame({'coin': coins, 'pair': pairs, 'volume': volumes, 'price': prices})
        self._df = self._df.set_index('coin')
예제 #2
0
파일: main.py 프로젝트: mtrazzi/cryptofolio
def create_coinlist():
    polo = Poloniex()
    vol = polo.marketVolume()
    ticker = polo.marketTicker()
    pairs = []
    coins = []
    volumes = []
    prices = []
    for k, v in vol.items():
        if k.startswith("BTC_") or k.endswith("_BTC"):
            pairs.append(k)
            for c, val in v.items():
                if c != 'BTC':
                    if k.endswith('_BTC'):
                        coins.append('reversed_' + c)
                        prices.append(1.0 / float(ticker[k]['last']))
                    else:
                        coins.append(c)
                        prices.append(float(ticker[k]['last']))
                else:
                    volumes.append(0.0)
    coin_list = pd.DataFrame({
        'coin': coins,
        'pair': pairs,
        'volume': volumes,
        'price': prices
    })
    coin_list = coin_list.set_index('coin')
    return coin_list
예제 #3
0
class CoinList(object):
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info("select coin online from %s to %s"
                     % (datetime.fromtimestamp(end - (DAY * volume_average_days) - volume_forward).strftime('%Y-%m-%d %H:%M'),
                        datetime.fromtimestamp(end - volume_forward).strftime('%Y-%m-%d %H:%M')))

        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        if k.endswith('_BTC'):
                            # BTCが後ろなら逆数にする
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(self.__get_total_volume(pair=k, global_end=end,
                                                               days=volume_average_days,
                                                               forward=volume_forward))
        self._df = pd.DataFrame({'coin': coins, 'pair': pairs, 'volume': volumes, 'price': prices})
        self._df = self._df.set_index('coin')

    def __get_total_volume(self, pair, global_end, days, forward):
        """
        指定した日数のVOLUMEを返します。
        :param pair: 通貨ペア
        :param global_end: 終了日
        :param days: 日数。終了日からこの日数を引いた分が開始日となる
        :param forward: シフト
        :return:
        """
        start = global_end - (DAY * days) - forward
        end = global_end - forward
        chart = self.get_chart_until_success(pair=pair, period=DAY, start=start, end=end)
        result = 0
        for one_day in chart:
            if pair.startswith("BTC_"):
                result += one_day['volume']
            else:
                result += one_day["quoteVolume"]
        return result

    def get_chart_until_success(self, pair, start, period, end):
        return get_chart_until_success(self._polo, pair, start, period, end)
예제 #4
0
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        # connect the internet to accees volumes
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info("select coin online from %s to %s" % (datetime.fromtimestamp(end-(DAY*volume_average_days)-
                                                                                  volume_forward).
                                                           strftime('%Y-%m-%d %H:%M'),
                                                           datetime.fromtimestamp(end-volume_forward).
                                                           strftime('%Y-%m-%d %H:%M')))
        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        if k.endswith('_BTC'):
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(self.__get_total_volume(pair=k, global_end=end,
                                                               days=volume_average_days,
                                                               forward=volume_forward))
        self._df = pd.DataFrame({'coin': coins, 'pair': pairs, 'volume': volumes, 'price':prices})
        self._df = self._df.set_index('coin')
    def __init__(self,
                 end=1483315200,
                 volume_average_days=30,
                 volume_forward=0.08):
        #opens Poloniex, gets data
        self._polo = Poloniex()
        # connect the internet to accees volumes
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info(
            "select coin online from %s to %s" %
            (datetime.fromtimestamp(end - (DAY * volume_average_days) -
                                    volume_forward).strftime('%Y-%m-%d %H:%M'),
             datetime.fromtimestamp(end - volume_forward).strftime(
                 '%Y-%m-%d %H:%M')))
        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        #add coin prices
                        if k.endswith('_BTC'):
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(
                            self.__get_total_volume(pair=k,
                                                    global_end=end,
                                                    days=volume_average_days,
                                                    forward=volume_forward))
        #generates a pd.DataFrame with coins, pairs, volumes, prices of all coins
        self._df = pd.DataFrame({
            'coin': coins,
            'pair': pairs,
            'volume': volumes,
            'price': prices
        })
        self._df = self._df.set_index('coin')
        print(self._df)
예제 #6
0
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        # connect the internet to accees volumes
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info("select coin online from %s to %s" % (
            datetime.fromtimestamp(end - (DAY * volume_average_days) -
                                   volume_forward).strftime("%Y-%m-%d %H:%M"),
            datetime.fromtimestamp(end -
                                   volume_forward).strftime("%Y-%m-%d %H:%M"),
        ))
        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != "BTC":
                        if k.endswith("_BTC"):
                            coins.append("reversed_" + c)
                            prices.append(1.0 / float(ticker[k]["last"]))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]["last"]))
                    else:
                        volumes.append(
                            self.__get_total_volume(
                                pair=k,
                                global_end=end,
                                days=volume_average_days,
                                forward=volume_forward,
                            ))
        self._df = pd.DataFrame({
            "coin": coins,
            "pair": pairs,
            "volume": volumes,
            "price": prices
        })
        self._df = self._df.set_index("coin")
예제 #7
0
파일: main.py 프로젝트: mtrazzi/cryptofolio
def create_data(coin, coin_list, start, end, period):
    polo = Poloniex()
    chart = get_chart_until_success(polo=polo,
                                    pair=coin_list.at[coin, 'pair'],
                                    start=start,
                                    end=end,
                                    period=period)
    for c in chart:
        if c["date"] > 0:
            if c['weightedAverage'] == 0: c['weightedAverage'] = c['close']

            # NOTE here the USDT is in reversed order
            if 'reversed_' in coin:
                c['low'], c['high'], c[
                    'open'] = 1.0 / c['low'], 1.0 / c['high'], 1.0 / c['open']
                c['close'], c['weightedAverage'] = 1.0 / c['close'], 1.0 / c[
                    'weightedAverage']
    return chart
예제 #8
0
class CoinList(object):
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        # connect the internet to accees volumes
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info(
            "select coin online from %s to %s" %
            (datetime.fromtimestamp(end - (DAY * volume_average_days) -
                                    volume_forward).strftime('%Y-%m-%d %H:%M'),
             datetime.fromtimestamp(end - volume_forward).strftime(
                 '%Y-%m-%d %H:%M')))
        #
        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        if k.endswith('_BTC'):
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(
                            self.__get_total_volume(pair=k,
                                                    global_end=end,
                                                    days=volume_average_days,
                                                    forward=volume_forward))
        self._df = pd.DataFrame({
            'coin': coins,
            'pair': pairs,
            'volume': volumes,
            'price': prices
        })
        self._df = self._df.set_index('coin')

    @property
    def allActiveCoins(self):
        return self._df

    @property
    def allCoins(self):
        return self._polo.marketStatus().keys()

    @property
    def polo(self):
        return self._polo

    def get_chart_until_success(self, pair, start, period, end):
        return get_chart_until_success(self._polo, pair, start, period, end)

    # get several days volume
    def __get_total_volume(self, pair, global_end, days, forward):
        start = global_end - (DAY * days) - forward
        end = global_end - forward
        chart = self.get_chart_until_success(pair=pair,
                                             period=DAY,
                                             start=start,
                                             end=end)
        result = 0
        for one_day in chart:
            if pair.startswith("BTC_"):
                result += one_day['volume']
            else:
                result += one_day["quoteVolume"]
        return result

    def topNVolume(self, n=5, order=True, minVolume=0):
        if minVolume == 0:
            r = self._df.loc[self._df['price'] > 2e-6]
            r = r.sort_values(by='volume', ascending=False)[:n]
            print(r)
            if order:
                return r
            else:
                return r.sort_index()
        else:
            return self._df[self._df.volume >= minVolume]
예제 #9
0
class CoinList(object):
    def __init__(self, end, volume_average_days=1, volume_forward=0):
        self._polo = Poloniex()
        # connect the internet to accees volumes
        vol = self._polo.marketVolume()
        ticker = self._polo.marketTicker()
        pairs = []
        coins = []
        volumes = []
        prices = []

        logging.info("select coin online from %s to %s" % (datetime.fromtimestamp(end-(DAY*volume_average_days)-
                                                                                  volume_forward).
                                                           strftime('%Y-%m-%d %H:%M'),
                                                           datetime.fromtimestamp(end-volume_forward).
                                                           strftime('%Y-%m-%d %H:%M')))
        for k, v in vol.items():
            if k.startswith("BTC_") or k.endswith("_BTC"):
                pairs.append(k)
                for c, val in v.items():
                    if c != 'BTC':
                        if k.endswith('_BTC'):
                            coins.append('reversed_' + c)
                            prices.append(1.0 / float(ticker[k]['last']))
                        else:
                            coins.append(c)
                            prices.append(float(ticker[k]['last']))
                    else:
                        volumes.append(self.__get_total_volume(pair=k, global_end=end,
                                                               days=volume_average_days,
                                                               forward=volume_forward))
        self._df = pd.DataFrame({'coin': coins, 'pair': pairs, 'volume': volumes, 'price':prices})
        self._df = self._df.set_index('coin')

    @property
    def allActiveCoins(self):
        return self._df

    @property
    def allCoins(self):
        return self._polo.marketStatus().keys()

    @property
    def polo(self):
        return self._polo

    def get_chart_until_success(self, pair, start, period, end):
        return get_chart_until_success(self._polo, pair, start, period, end)

    # get several days volume
    def __get_total_volume(self, pair, global_end, days, forward):
        start = global_end-(DAY*days)-forward
        end = global_end-forward
        chart = self.get_chart_until_success(pair=pair, period=DAY, start=start, end=end)
        result = 0
        for one_day in chart:
            if pair.startswith("BTC_"):
                result += one_day['volume']
            else:
                result += one_day["quoteVolume"]
        return result


    def topNVolume(self, n=5, order=True, minVolume=0):
        if minVolume == 0:
            r = self._df.loc[self._df['price'] > 2e-6]
            r = r.sort_values(by='volume', ascending=False)[:n]
            print(r)
            if order:
                return r
            else:
                return r.sort_index()
        else:
            return self._df[self._df.volume >= minVolume]