Exemplo n.º 1
0
    def update_keltner_coins(self):
        highest_price_history = utils.file_to_json(
            'coin_highest_price_history.json')

        for market in self.keltner_coins:
            if market in self.bittrex_coins:
                bittrex_coin = self.bittrex_coins[market]
                cur_price = bittrex_coin['Last']
                self.keltner_coins[market]['price_data_seconds'].append(
                    cur_price)

                highest_price_history = self.update_highest_price(
                    market, highest_price_history, cur_price)

                if self.ten_second_count > 5:
                    self.keltner_coins[market]['price_data_minutes'].append(
                        cur_price)
                    self.update_atr(market)
                    self.update_ema(market)
                    self.update_bands(market)
                    self.keltner_coins[market]['price_data_seconds'] =\
                        self.keltner_coins[market]['price_data_seconds'][-6:]

                    if len(self.keltner_coins[market]
                           ['price_data_minutes']) == self.keltner_period:
                        self.keltner_coins[market]['price_data_minutes'].pop(0)
        if self.ten_second_count > 5:
            self.ten_second_count = 0
        else:
            self.ten_second_count += 1

        utils.json_to_file(highest_price_history,
                           'coin_highest_price_history.json')
        utils.json_to_file(self.keltner_coins, "keltner_coins.json")
    def update_reddit_coins(self):
        self.mentioned_words = {}
        reddit_coins = utils.file_to_json('reddit_coins.json')
        for submission in self.reddit_api.subreddit('CryptoCurrency').top(
                'day'):
            if submission not in reddit_coins['submissions']:
                self.add_to_words_coins(submission.title, submission.score,
                                        submission.created)

                reddit_coins = self.find_mentions(submission.title,
                                                  reddit_coins,
                                                  str(submission),
                                                  submission.created,
                                                  submission.score)
                for comment in submission.comments:

                    try:
                        reddit_coins = self.find_mentions(
                            comment.body, reddit_coins, str(comment),
                            comment.created, comment.score)
                        self.add_to_words_coins(comment.body, comment.score,
                                                comment.created)
                    except:
                        pass
            reddit_coins['submissions'].append(str(submission))
        utils.json_to_file(reddit_coins, 'reddit_coins.json')
        self.rank_by_mentions()
        self.rank_by_upvotes()
        self.rank_by_upvotes_and_sentiment()
Exemplo n.º 3
0
    def add_bittrex_coins_to_keltner_coins(self, coinmarketcap_coins):
        self.keltner_coins = {}
        self.coinmarketcap_coins = self.update_coinmarketcap_coins()
        self.bittrex_coins = self.update_bittrex_coins(
            self.coinmarketcap_coins)
        for market in self.bittrex_coins:
            if market.startswith('BTC'):
                symbol = utils.get_second_market_coin(market)
                if symbol in coinmarketcap_coins:
                    coin_rank = int(coinmarketcap_coins[symbol])
                    if coin_rank <= self.lowest_rank:
                        t = {}
                        t['market'] = market
                        t['price_data_seconds'] = []
                        t['price_data_minutes'] = []
                        t['tr_data'] = []
                        t['atr_data'] = []
                        t['ema_data'] = []
                        t['upper_band_data'] = []
                        t['middle_band_data'] = []
                        t['lower_band_data'] = []

                        self.keltner_coins[market] = t

        utils.json_to_file(self.keltner_coins, "keltner_coins.json")
Exemplo n.º 4
0
    def keltner_buy_strat(self, total_bitcoin):
        if len(self.keltner_coins['BTC-ETH']
               ['upper_band_data']) > self.keltner_period:
            keltner_slots_open = self.keltner_slots - len(
                self.held_coins) - len(self.pending_orders['Buying']) - len(
                    self.pending_orders['Selling'])

            for coin in self.keltner_coins:
                market = self.bittrex_coins[coin]['MarketName']
                lower_band_data = self.keltner_coins[market]['lower_band_data']
                if len(lower_band_data) == self.keltner_period:
                    coins_pending_buy = [
                        market for market in self.pending_orders['Buying']
                    ]
                    coins_pending_sell = [
                        market for market in self.pending_orders['Selling']
                    ]

                    if market not in self.held_coins and market not in coins_pending_buy and market not in coins_pending_sell:

                        cur_price = self.bittrex_coins[coin]['Last']
                        if self.upward_cross(market, 'lower_band_data'):
                            bitcoin_to_use = float(total_bitcoin /
                                                   (keltner_slots_open + .25))
                            amount = bitcoin_to_use / cur_price
                            percent_change_24h = utils.get_percent_change_24h(
                                coin)
                            utils.buy(self.api, market, amount, cur_price,
                                      percent_change_24h, 0)

                            keltner_slots_open = self.total_slots - len(
                                self.held_coins) - len(
                                    self.pending_orders['Buying']) - len(
                                        self.pending_orders['Selling'])
Exemplo n.º 5
0
    def percent_sell_strat(self):
        """
        If a coin drops more than 10% of its highest price then sell
        """

        held_markets = [market for market in self.held_coins]
        for coin_market in held_markets:
            current_high = self.history_coins[coin_market]
            coin_price = float(self.bittrex_coins[coin_market]['Last'])
            """
            if cur_24h_change > highest_24h_change:
                self.held_coins[coin_market]['highest_24h_change'] = cur_24h_change
                highest_24h_change = cur_24h_change
                utils.json_to_file(self.held_coins, "held_coins.json")

                self.held_coins[coin_market]['sell_threshold'] = self.updated_threshold(coin_market, self.held_coins)
                utils.json_to_file(self.held_coins, "held_coins.json")
            """

            if coin_price < current_high * 0.97:

                coin_to_sell = utils.get_second_market_coin(coin_market)

                balance = self.api.get_balance(coin_to_sell)

                if balance['success']:
                    amount = float(balance['result']['Available'])
                    if amount > 0:
                        utils.sell(self.api, amount, coin_market,
                                   self.bittrex_coins)
                else:
                    utils.print_and_write_to_logfile(
                        "Could not retrieve balance: " + balance['message'])
Exemplo n.º 6
0
    def __init__(self, api, total_slots):
        self.api = api
        self.total_slots = total_slots

        self.bittrex_coins = utils.get_updated_bittrex_coins()

        self.held_coins = utils.file_to_json("held_coins.json")
        self.pending_orders = utils.file_to_json("pending_orders.json")
    def percent_sell_strat(self):
        ignored = utils.file_to_json("ignored_coins.json")
        held_markets = [market for market in self.held_coins]
        for coin_market in held_markets:
            current_high = self.history_coins[coin_market]
            coin_price = float(self.bittrex_coins[coin_market]['Last'])
            percent_change_24h = utils.get_percent_change_24h(
                self.bittrex_coins[coin_market])

            if coin_price < current_high * 0.80 \
                    or percent_change_24h >= 110:

                coin_to_sell = utils.get_second_market_coin(coin_market)

                balance = self.api.get_balance(coin_to_sell)

                if balance['success']:
                    amount = float(balance['result']['Available'])
                    if amount > 0:
                        utils.sell(self.api, amount, coin_market,
                                   self.bittrex_coins)
                        ignored[coin_market] = 1
                        utils.json_to_file(ignored, "ignored_coins.json")
                else:
                    utils.print_and_write_to_logfile(
                        "Could not retrieve balance: " + balance['message'])
Exemplo n.º 8
0
def update_pending_orders(orders):
    """
    Checks bitttrex's open orders and if a coin that's in
    pending_orders is no longer in bittrex's pending orders
    it has gone through, so we add it to our held coins.
    :param orders:
    :return:
    """

    pending_orders = utils.file_to_json("pending_orders.json")

    # Move processed buy orders from pending_orders into held_coins
    processing_orders = [order['OrderUuid'] for order in orders]

    buy_uuids_markets = [(pending_orders['Buying'][market]['uuid'], market)
                         for market in pending_orders['Buying']]

    for buy_uuids_market in buy_uuids_markets:
        buy_uuid = buy_uuids_market[0]
        if buy_uuid not in processing_orders:
            buy_market = buy_uuids_market[1]

            pending_buy_order = pending_orders['Buying'][buy_market]
            amount = str(pending_buy_order['amount'])
            utils.print_and_write_to_logfile("Buy order: " + amount + " of " +
                                             buy_market +
                                             " Processed Successfully " +
                                             "UUID: " + buy_uuid + " " +
                                             utils.get_date_time())
            move_to_from_held(buy_market, 'Buying')

            # Add price to highest_price_history
            highest_price_list = utils.file_to_json(
                "coin_highest_price_history.json")
            highest_price_list[buy_market] = pending_orders['Buying'][
                buy_market]['price_bought']
            utils.json_to_file(highest_price_list,
                               'coin_highest_price_history.json')

    # Move processed sold orders from pending_orders into held_coins
    sell_uuids_markets = [(pending_orders['Selling'][market]['uuid'], market)
                          for market in pending_orders['Selling']]

    for sell_uuids_market in sell_uuids_markets:
        if sell_uuids_market[0] not in processing_orders:
            pending_sell_order = pending_orders['Selling'][
                sell_uuids_market[1]]
            amount = str(pending_sell_order['amount'])
            utils.print_and_write_to_logfile("Sell order: " + amount + " of " +
                                             " " + sell_uuids_market[1] +
                                             " Processed Successfully " +
                                             "UUID: " + sell_uuids_market[0] +
                                             " " + utils.get_date_time())
            move_to_from_held(sell_uuids_market[1], 'Selling')
Exemplo n.º 9
0
def initialize_percent_strat():
    utils.init_global_return()
    buy_min_percent = 30
    buy_max_percent = 1000
    buy_desired_1h_change = 10
    total_slots = 4
    data_ticks_to_save = 180

    return PS.PercentStrat(api, buy_min_percent, buy_max_percent,
                           buy_desired_1h_change, total_slots,
                           data_ticks_to_save)
Exemplo n.º 10
0
 def update_bittrex_coins(self, coinmarketcap_coins):
     bittrex_data = utils.query_url(
         "https://bittrex.com/api/v1.1/public/getmarketsummaries")['result']
     coins = {}
     for coin in bittrex_data:
         symbol = utils.get_second_market_coin(coin['MarketName'])
         if symbol in coinmarketcap_coins:
             coin_rank = int(coinmarketcap_coins[symbol])
             if coin_rank <= self.lowest_rank:
                 key = coin['MarketName']
                 coins[key] = coin
     return coins
Exemplo n.º 11
0
 def reset_keltner_coins(self):
     self.keltner_coins = utils.file_to_json("keltner_coins.json")
     for coin in self.keltner_coins:
         self.keltner_coins[coin]['price_data_minutes'] = []
         self.keltner_coins[coin]['price_data_seconds'] = []
         self.keltner_coins[coin]['tr_data'] = []
         self.keltner_coins[coin]['atr_data'] = []
         self.keltner_coins[coin]['ema_data'] = []
         self.keltner_coins[coin]['upper_band_data'] = []
         self.keltner_coins[coin]['middle_band_data'] = []
         self.keltner_coins[coin]['lower_band_data'] = []
     utils.json_to_file(self.keltner_coins, "keltner_coins.json")
Exemplo n.º 12
0
    def __init__(self, api, desired_gain, desired_low_point, total_slots):
        self.api = api
        self.desired_gain = desired_gain
        self.desired_low_point = desired_low_point
        self.total_slots = total_slots
        self.count_until_reddit_strat = 0

        self.bittrex_coins = utils.get_updated_bittrex_coins()

        self.held_coins = utils.file_to_json("held_coins.json")
        self.pending_orders = utils.file_to_json("pending_orders.json")
        self.fill_low_bars()
Exemplo n.º 13
0
def clean_orders(orders):
    """
    Finds any order that has been attempting to buy
    or sell for longer than the variable
    time_until_cancel_processing_order_minutes
    and attempt to cancel them on bittrex, and
    also deletes them from pending_orders.json

    :param orders:
    :return void:
    """

    pending_orders = utils.file_to_json("pending_orders.json")

    for order in orders:
        time_opened = order['Opened']
        time_passed = utils.get_time_passed_minutes(time_opened)

        uuid = order['OrderUuid']
        market = ""

        buying_or_selling = 'Buying' if order[
            'OrderType'] == 'LIMIT_BUY' else 'Selling'

        for pending_market in pending_orders[buying_or_selling]:
            if pending_orders[buying_or_selling][pending_market][
                    'uuid'] == uuid:
                market = pending_market

        if time_passed > time_until_cancel_processing_order_minutes:
            uuid = order['OrderUuid']
            cancel_order = api.cancel(uuid)

            if cancel_order['success']:

                if market in pending_orders[buying_or_selling]:
                    del pending_orders[buying_or_selling][market]

                    utils.json_to_file(pending_orders, "pending_orders.json")
                    utils.print_and_write_to_logfile("Cancel Order of " +
                                                     str(order["Quantity"]) +
                                                     " " +
                                                     str(order['Exchange']) +
                                                     " Successful " +
                                                     utils.get_date_time())
            else:
                utils.print_and_write_to_logfile("Cancel Order of " +
                                                 str(order["Quantity"]) +
                                                 order['Exchange'] +
                                                 " Unsuccessful: " +
                                                 cancel_order['message'] +
                                                 " " + utils.get_date_time())
Exemplo n.º 14
0
    def store_top_10_data(self):
        most_upvoted = self.coins_ranked_by_upvotes
        # most_mentioned = self.coins_ranked_by_mentions
        reddit_coins = utils.file_to_json('reddit_coins.json')
        count = 10
        out_string = ""
        top_coins = {}
        rank = 0
        for pair in most_upvoted:
            if count <= 0:
                break
            count -= 1
            symbol = pair[0]
            coin_data = reddit_coins[symbol]
            out_string += "*********************** " + symbol + " ***********************" + "\n"

            self.add_to_top_coins("BTC-" + symbol, top_coins, rank)
            rank += 1

            upvote_list = coin_data['upvotes']
            text_list = coin_data['text']
            time_list = coin_data['mentioned_times']

            sorted_comments = self.sort_comments(upvote_list, text_list,
                                                 time_list)

            for i in range(len(upvote_list)):
                out_string += str(
                    sorted_comments[i][0]) + " : " + utils.time_stamp_to_date(
                        sorted_comments[i]
                        [2]) + " : " + sorted_comments[i][1] + "\n\n"
            out_string += "\n\n"
        utils.json_to_file(top_coins, 'reddit_top_coins.json')
        utils.clear_and_write_to_file('reddit_info.txt', out_string)
        utils.send_to_ftp_server('reddit_info.txt')
Exemplo n.º 15
0
    def __init__(self, bittrex_api, reddit_api, total_slots):
        self.bittrex_api = bittrex_api
        self.reddit_api = reddit_api
        self.total_slots = total_slots

        self.bittrex_coins = utils.get_updated_bittrex_coins()

        self.held_coins = utils.file_to_json("held_coins.json")
        self.pending_orders = utils.file_to_json("pending_orders.json")

        self.coins_ranked_by_mentions = ('CoinName', 0)

        self.coins_ranked_by_upvotes = ('CoinName', 0)

        self.initialize_reddit_coins()
Exemplo n.º 16
0
    def add_to_keltner_coins(self, market):

        t = {}
        t['market'] = market
        t['price_data_seconds'] = []
        t['price_data_minutes'] = []
        t['tr_data'] = []
        t['atr_data'] = []
        t['ema_data'] = []
        t['upper_band_data'] = []
        t['middle_band_data'] = []
        t['lower_band_data'] = []

        self.keltner_coins[market] = t
        utils.json_to_file(self.keltner_coins, "keltner_coins.json")
    def low_high_buy_strat(self, total_bitcoin):
        top_reddit_coins = utils.file_to_json('reddit_top_coins.json')
        markets_to_ignore = ['BTC-ETH', 'BTC-BTC']

        for rank in range(len(top_reddit_coins)):
            market = top_reddit_coins[str(rank)]['market']

            if market not in markets_to_ignore:

                slots_open = self.total_slots - len(self.held_coins) - len(
                    self.pending_orders['Buying']) - len(
                        self.pending_orders['Selling'])
                bitcoin_to_use = float(total_bitcoin / (slots_open + .25))

                coins_pending_buy = [
                    market for market in self.pending_orders['Buying']
                ]
                coins_pending_sell = [
                    market for market in self.pending_orders['Selling']
                ]

                if market not in self.held_coins and market not in coins_pending_buy and market not in \
                        coins_pending_sell:

                    percent_change_24h = utils.get_percent_change_24h(
                        self.bittrex_coins[market])
                    coin_low_bars = utils.file_to_json('coin_low_bars.json')
                    low_bar = coin_low_bars[market]

                    if percent_change_24h <= self.desired_low_point and percent_change_24h <= low_bar:
                        coin_low_bars[market] = low_bar - 10
                        utils.json_to_file(coin_low_bars, 'coin_low_bars.json')

                    elif low_bar != self.desired_low_point and percent_change_24h > low_bar + 10:
                        self.update_bittrex_coins()
                        coin_price = float(self.bittrex_coins[market]['Last'])
                        amount = bitcoin_to_use / coin_price
                        if amount > 0:
                            result = utils.buy(self.api, market, amount,
                                               coin_price, percent_change_24h,
                                               self.desired_gain, 0)
                            if not result['success']:
                                utils.print_and_write_to_logfile(
                                    "Failed to make buy order " + market)
                            else:
                                utils.print_and_write_to_logfile(
                                    "Attempting buy order of " + str(amount) +
                                    " of " + market)
Exemplo n.º 18
0
    def find_mentions(self, string, reddit_coins, mentioned_id, mentioned_time,
                      upvotes):
        submissions = reddit_coins['submissions']
        del reddit_coins['submissions']
        coins_with_common_names = utils.file_to_json(
            'coins_to_dismiss.json')['coins_with_common_names']
        for symbol in reddit_coins:
            full_name = reddit_coins[symbol]['full_name']
            full_name_reg = r"\b" + full_name + r"\b"
            symbol_reg = r"\b" + symbol + r"\b"
            if symbol not in coins_with_common_names:
                if re.search(symbol_reg, string, re.IGNORECASE) or re.search(
                        full_name_reg, string, re.IGNORECASE):
                    reddit_coins = self.add_to_reddit_coin(
                        reddit_coins, symbol, mentioned_id, mentioned_time,
                        string, upvotes)
            else:
                if symbol.lower() != full_name.lower():
                    if re.search(symbol_reg, string) or re.search(
                            full_name_reg, string, re.IGNORECASE):
                        reddit_coins = self.add_to_reddit_coin(
                            reddit_coins, symbol, mentioned_id, mentioned_time,
                            string, upvotes)
                    else:
                        if re.search(symbol_reg, string):
                            reddit_coins = self.add_to_reddit_coin(
                                reddit_coins, symbol, mentioned_id,
                                mentioned_time, string, upvotes)

        reddit_coins['submissions'] = submissions
        return reddit_coins
    def find_mentions(self, string, reddit_coins, mentioned_id, mentioned_time,
                      upvotes):
        submissions = reddit_coins['submissions']
        del reddit_coins['submissions']
        coins_with_common_names = utils.file_to_json(
            'coins_to_dismiss.json')['coins_with_common_names']

        symbols_and_names_map = {}
        for symbol in reddit_coins:
            if symbol not in coins_with_common_names:
                symbols_and_names_map[symbol] = symbol
                full_name = reddit_coins[symbol]['full_name'].lower()
                symbols_and_names_map[full_name] = symbol
        already_seen = set()
        for word in string.split(" "):
            lower_case_word = word.lower()
            if lower_case_word in symbols_and_names_map:
                if lower_case_word not in already_seen and symbols_and_names_map[
                        lower_case_word] not in lower_case_word:
                    reddit_coins = self.add_to_reddit_coin(
                        reddit_coins, symbols_and_names_map[lower_case_word],
                        mentioned_id, mentioned_time, string, upvotes)
                already_seen.add(lower_case_word)
                already_seen.add(symbols_and_names_map[lower_case_word])
        reddit_coins['submissions'] = submissions
        return reddit_coins
    def add_to_top_coins(self, market, top_coins, rank):
        coin_info = self.bittrex_coins[market]
        t = {}
        t['market'] = market
        t['cur_price'] = coin_info['Last']
        t['24h_change'] = utils.get_percent_change_24h(coin_info)

        top_coins[rank] = t
 def add_to_reddit_coin(self, reddit_coins, symbol, mentioned_id,
                        mentioned_time, string, upvotes):
     reddit_coins[symbol]['mentioned_ids'].append(mentioned_id)
     reddit_coins[symbol]['mentioned_times'].append(mentioned_time)
     reddit_coins[symbol]['text'].append(string)
     reddit_coins[symbol]['upvotes'].append(upvotes)
     reddit_coins[symbol]['sentiments'].append(utils.get_sentiment(string))
     return reddit_coins
 def rank_by_upvotes(self):
     reddit_coins = utils.file_to_json('reddit_coins.json')
     del reddit_coins['submissions']
     ranked_coins = {}
     for coin in reddit_coins:
         ranked_coins[coin] = sum(reddit_coins[coin]['upvotes'])
     sorted_coins = sorted(ranked_coins.items(),
                           key=operator.itemgetter(1),
                           reverse=True)
     self.coins_ranked_by_upvotes = sorted_coins
Exemplo n.º 23
0
    def __init__(self, api, keltner_period, keltner_multiplier, keltner_slots,
                 lowest_rank):
        self.api = api
        self.keltner_period = keltner_period
        self.keltner_multiplier = keltner_multiplier
        self.keltner_slots = keltner_slots

        self.lowest_rank = lowest_rank

        self.keltner_coins = utils.file_to_json("keltner_coins.json")
        self.coinmarketcap_coins = self.update_coinmarketcap_coins()
        self.bittrex_coins = self.update_bittrex_coins(
            self.coinmarketcap_coins)

        self.held_coins = utils.file_to_json("held_coins.json")
        self.pending_orders = utils.file_to_json("pending_orders.json")

        self.reset_keltner_coins()

        self.ten_second_count = 0
Exemplo n.º 24
0
 def update_reddit_coins(self):
     reddit_coins = utils.file_to_json('reddit_coins.json')
     for submission in self.reddit_api.subreddit('CryptoCurrency').top(
             'day'):
         if submission not in reddit_coins['submissions']:
             reddit_coins = self.find_mentions(submission.title,
                                               reddit_coins,
                                               str(submission),
                                               submission.created,
                                               submission.score)
             for comment in submission.comments:
                 reddit_coins = self.find_mentions(comment.body,
                                                   reddit_coins,
                                                   str(comment),
                                                   comment.created,
                                                   comment.score)
         reddit_coins['submissions'].append(str(submission))
     utils.json_to_file(reddit_coins, 'reddit_coins.json')
     self.rank_by_mentions()
     self.rank_by_upvotes()
    def __init__(self, api, buy_min_percent, buy_max_percent,
                 buy_desired_1h_change, total_slots, data_ticks_to_save):
        self.api = api
        self.buy_min_percent = buy_min_percent
        self.buy_max_percent = buy_max_percent
        self.buy_desired_1h_change = buy_desired_1h_change
        self.total_slots = total_slots
        self.data_ticks_to_save = data_ticks_to_save

        self.bittrex_coins = utils.get_updated_bittrex_coins()
        self.coinmarketcap_coins = utils.get_updated_coinmarketcap_coins()

        self.historical_coin_data = {}

        self.refresh_held_pending_history()

        self.held_coins = utils.file_to_json("held_coins.json")
        self.pending_orders = utils.file_to_json("pending_orders.json")
        self.history_coins = utils.file_to_json(
            "coin_highest_price_history.json")
    def buy(self, market, total_bitcoin):
        coins_pending_buy = [
            market for market in self.pending_orders['Buying']
        ]
        coins_pending_sell = [
            market for market in self.pending_orders['Selling']
        ]

        if market not in self.held_coins and market not in coins_pending_buy and market not in \
                coins_pending_sell:

            slots_open = self.total_slots - len(self.held_coins) - len(
                self.pending_orders['Buying']) - len(
                    self.pending_orders['Selling'])
            bitcoin_to_use = float(total_bitcoin / (slots_open + .25))

            coin_price = float(self.bittrex_coins[market]['Last'])
            amount = bitcoin_to_use / coin_price

            if amount > 0:
                percent_change_24h = utils.get_percent_change_24h(
                    self.bittrex_coins[market])
                result = utils.buy(self.api, market, amount, coin_price,
                                   percent_change_24h, 0, 0)
                if result['success']:
                    utils.print_and_write_to_logfile('Buy order of' +
                                                     str(amount) + 'of' +
                                                     market + 'Unsuccessful')
                else:
                    utils.print_and_write_to_logfile('Buy order of' +
                                                     str(amount) + 'of' +
                                                     market + 'Successful')
                return result
Exemplo n.º 27
0
def run_percent_strat():
    ps.refresh_held_pending_history()
    ps.update_bittrex_coins()

    ps.historical_coin_data = utils.update_historical_coin_data(
        ps.historical_coin_data, ps.bittrex_coins, ps.data_ticks_to_save)

    ps.update_coinmarketcap_coins()
    if total_bitcoin > satoshi_50k:
        ps.percent_buy_strat(total_bitcoin)

    ps.percent_sell_strat()
    time.sleep(10)
    def rank_by_upvotes_and_sentiment(self):
        reddit_coins = utils.file_to_json('reddit_coins.json')
        del reddit_coins['submissions']
        ranked_coins = {}

        for coin in reddit_coins:
            upvote_list = reddit_coins[coin]['upvotes']
            sentiment_list = reddit_coins[coin]['sentiments']

            rank = 0
            for i in range(len(upvote_list)):
                rank += upvote_list[i] * sentiment_list[i]
                ranked_coins[coin] = rank

        sorted_coins = sorted(ranked_coins.items(),
                              key=operator.itemgetter(1),
                              reverse=True)
        self.coins_ranked_by_upvotes_and_sentiment = sorted_coins
Exemplo n.º 29
0
    def low_high_sell_strat(self):
        for market in self.held_coins:
            cur_price = float(self.bittrex_coins[market]['Last'])
            bought_price = self.held_coins[market]['price_bought']
            change = utils.percent_change(bought_price, cur_price)

            desired_gain = self.held_coins[market]['desired_gain']
            high_bar = self.held_coins[market]['high_bar']

            if change >= desired_gain and change >= high_bar:
                self.held_coins[market]['high_bar'] = high_bar + 10
                utils.json_to_file(self.held_coins, 'held_coins.json')
            elif high_bar != desired_gain and change < high_bar - 10:
                coin_to_sell = utils.get_second_market_coin(market)
                balance = self.api.get_balance(coin_to_sell)
                if balance['success']:
                    amount = float(balance['result']['Available'])
                    self.update_bittrex_coins()
                    utils.sell(self.api, amount, market, self.bittrex_coins)
                else:
                    utils.print_and_write_to_logfile("Could not retrieve balance: " + balance['message'])
    def reddit_buy_strat(self, total_bitcoin):
        coin_rank = 0
        coins_to_dismiss = utils.file_to_json(
            'coins_to_dismiss.json')["coins_to_dismiss"]

        slots_open = self.total_slots - len(self.held_coins) - len(
            self.pending_orders['Buying']) - len(
                self.pending_orders['Selling'])

        while coin_rank < 5:
            cur_coin = self.rank_by_upvotes()[coin_rank][0]
            if cur_coin not in coins_to_dismiss:
                market = "BTC-" + cur_coin
                coins_pending_buy = [
                    market for market in self.pending_orders['Buying']
                ]
                coins_pending_sell = [
                    market for market in self.pending_orders['Selling']
                ]

                if market not in self.held_coins and market not in coins_pending_buy and market not in \
                        coins_pending_sell:
                    bitcoin_to_use = float(total_bitcoin / (slots_open + .25))
                    coin_price = float(self.bittrex_coins[market]['Last'])
                    amount = bitcoin_to_use / coin_price

                    if amount > 0:
                        percent_change_24h = utils.get_percent_change_24h(
                            self.bittrex_coins[market])
                        buy_request = utils.buy(self.api, market, amount,
                                                coin_price, percent_change_24h,
                                                0)
                        if buy_request['success']:
                            utils.print_and_write_to_logfile("Buy order of " +
                                                             str(amount) +
                                                             " " + market +
                                                             " requested")
                        else:
                            utils.print_and_write_to_logfile(
                                buy_request['message'])
            if cur_coin not in coins_to_dismiss:
                coin_rank += 1