Beispiel #1
0
def check_statuses(twitter, twitter_user, seen_coins):

    coin_of_the_day_tweet = utils.get_coin_of_the_day_tweet(twitter, ocr)
    finished = False

    for word in coin_of_the_day_tweet.split(" "):
        lowered_word = word.lower()

        if lowered_word in binance_coins and lowered_word not in seen_coins:
            utils.print_and_write_to_logfile("FOUND COIN: " + lowered_word)
            market = binance_coins[lowered_word][0]
            utils.buy_from_binance(binance, market)
            symbol = market.split('BTC')[0].lower()
            utils.add_to_seen_coins(binance_coins, bittrex_coins, symbol)
            finished = True
            state['binance'] = True

        if lowered_word in bittrex_coins and lowered_word not in seen_coins:
            utils.print_and_write_to_logfile("FOUND COIN: " + lowered_word)
            market = bittrex_coins[lowered_word][0]
            utils.buy_from_bittrex(bittrex, market)
            symbol = market.split('-')[1].lower()
            utils.add_to_seen_coins(binance_coins, bittrex_coins, symbol)
            seen_coins = utils.get_seen_coins()
            if lowered_word not in seen_coins:
                utils.add_to_seen_coins(binance_coins, bittrex_coins, symbol)
            finished = True
            state['bittrex'] = True

        if finished:
            state['symbol'] = symbol
            return True, symbol
    return False, ''
Beispiel #2
0
def handle_selling(bought_price, market, amount_bought):
    global max_price
    global reached_goal
    global percentage_change
    global price_bought
    global cur_price

    percentage_change = 0
    reached_goal = False
    max_price = bought_price
    price_bought = bought_price

    wait_until_time_to_sell(market)

    status, order_id = binance_utils.limit_sell_on_binance(binance, market, amount_bought, cur_price,
                                                           sell_order_underprice_percent)
    amount_sold = 0
    utils.print_and_write_to_logfile("WAITING FOR SELL ORDER TO GO THROUGH")
    while status != 'FILLED':
        cur_price = binance_utils.get_most_recent_buy_order_price(binance, market)

        order = binance.get_order(
            symbol=market,
            orderId=order_id)

        status = order['status']
        float(order['executedQty'])

        percent_change = utils.percent_change(bought_price, cur_price)

        time.sleep(seconds_before_checking_binance)
    utils.print_and_write_to_logfile(market + " SOLD")
Beispiel #3
0
    def process_message(msg):
        global max_price
        global reached_goal
        global percentage_change
        global price_bought
        global cur_price

        cur_price = float(msg['p'])

        percent_from_max = utils.percent_change(max_price, cur_price)
        percent_from_bought = utils.percent_change(price_bought, cur_price)

        # COMMENT THIS LINE OUT IF YOU DON'T WANT TOO MUCH DATA
        print_trade_data(price_bought, cur_price, max_price, percent_from_max, percent_from_bought)

        if reached_goal == False and percent_from_bought >= sell_order_desired_percentage_profit:
            reached_goal = True
            utils.print_and_write_to_logfile("REACHED PRICE GOAL")

        if percent_from_max < sell_percent_down_to_sell and reached_goal == True:
            utils.print_and_write_to_logfile("PERCENT DOWN FROM PEAK: " + str(percent_from_max) + ". TIME TO SELL")
            try:
                reactor.stop()
            except:
                print("REACTOR ALREADY STOPPED")

        max_price = max(cur_price, max_price)
Beispiel #4
0
def wait_for_tweet_and_buy():
    bought = False
    while not bought:
        try:
            bought, symbol = check_statuses(twitter, twitter_user, seen_coins)
        except:
            utils.print_and_write_to_logfile(traceback.format_exc())
        time.sleep(4)
    return symbol
    def on_status(self, status):
        tweet_time = int(status.timestamp_ms)
        cur_time = int(round(time.time() * 1000))

        # Tweets will queue wile we are waiting to sell
        # and we don't want to buy on old data
        if cur_time - tweet_time < one_minute_in_milliseconds:

            if utils.contains_words_to_look_for(status.text, words_to_look_for):
                coin_name = utils.get_coin_name_in_text(status.text, ignored_coins, binance_coins)

                if coin_name:

                    utils.print_and_write_to_logfile(coin_name + " in tweet: " + status.text)
                    market = binance_coins[coin_name][0]
                    bought, bought_price, amount = binance_utils.market_buy_from_binance(binance, market,
                                                                                         market_max_buy_percent_from_first_order)

                    if bought:
                        sell_after_pecentage_gain(bought_price, market, amount)
Beispiel #6
0
    def on_status(self, status):
        try:
            tweet_time = int(status.timestamp_ms)
            cur_time = int(round(time.time() * 1000))

            # Tweets will queue while we are waiting to sell
            # and we don't want to buy on old data. Also don't take
            # tweets that are replies.
            if cur_time - tweet_time < one_minute_in_milliseconds and not status.in_reply_to_screen_name:

                if utils.contains_words_to_look_for(status.text, words_to_look_for):

                    coin_name = utils.get_coin_name_in_text(status.text, ignored_coins, binance_coins)

                    if coin_name:
                        utils.print_and_write_to_logfile(coin_name + " in Tweet: " + status.text)
                        market = binance_coins[coin_name][0]

                        bought_price, amount_bought = handle_buying(market)

                        if amount_bought > 0:
                            handle_selling(bought_price, market, amount_bought)
        except Exception as e:
            utils.print_and_write_to_logfile(traceback.format_exc())
Beispiel #7
0
def handle_buying(market):
    status, bought_price, order_id, amount_bought = binance_utils.limit_buy_from_binance(binance, market,
                                                                                         buy_order_overprice_percent)

    if amount_bought > 0:
        utils.print_and_write_to_logfile("WAITING FOR BUY ORDER TO BE FILLED")

        cancel_price = bought_price * (1 + buy_order_cap_percent / 100)

        while status != 'FILLED':
            order = binance.get_order(
                symbol=market,
                orderId=order_id)

            status = order['status']

            amount_bought = float(order['executedQty'])

            if status == "FILLED":
                utils.print_and_write_to_logfile("ORDER FILLED")
                break

            cur_price = binance_utils.get_most_recent_sell_order_price(binance, market)

            if cur_price > cancel_price:
                utils.print_and_write_to_logfile(
                    "CANCELING ORDER: PRICE WENT UP TOO MUCH BEFORE ORDER WENT THROUGH. CUR PRICE: " + cur_price)
                result = binance.cancel_order(
                    symbol=market,
                    orderId=order_id)
                print(result)
                break

            time.sleep(seconds_before_checking_binance)

    if amount_bought > 0:
        utils.print_and_write_to_logfile("BUY ORDER HAS BEEN FILLED")

    return bought_price, amount_bought
Beispiel #8
0
def sell_at_peak(state, symbol):
    if state['bittrex']:
        last_price_bittrex = get_price_bittrex(bittrex, symbol)
    if state['binance']:
        last_price_binance = get_price_binance(binance, symbol)

    while state['bittrex'] or state['binance']:
        time.sleep(CHECK_TIMER)

        if state['bittrex']:
            cur_price_bittrex = get_price_bittrex(bittrex, symbol)
            delta = (cur_price_bittrex -
                     last_price_bittrex) / last_price_bittrex
            last_price_bittrex = cur_price_bittrex

            utils.print_and_write_to_logfile('CHECKING PRICE ON BITTREX')
            utils.print_and_write_to_logfile("CURRENT PRICE: " +
                                             str(last_price_bittrex))
            utils.print_and_write_to_logfile("DELTA: " + str(delta) + '\n')

            if delta < SELL_THRESHOLD:
                utils.print_and_write_to_logfile(
                    "THRESHOLD REACHED | SELLING ON BITTREX...")
                utils.sell_on_bittrex(bittrex, 'BTC-' + symbol.upper())
                state['bittrex'] = False

        if state['binance']:
            cur_price_binance = get_price_binance(binance, symbol)
            delta = (cur_price_binance -
                     last_price_binance) / last_price_binance
            last_price_binance = cur_price_binance

            utils.print_and_write_to_logfile('CHECKING PRICE ON BINANCE')
            utils.print_and_write_to_logfile("CURRENT PRICE: " +
                                             str(last_price_binance))
            utils.print_and_write_to_logfile("DELTA: " + str(delta) + '\n')

            if delta < SELL_THRESHOLD:
                utils.print_and_write_to_logfile(
                    "THRESHOLD REACHED | SELLING ON BINANCE...")

                utils.sell_on_binance(binance, symbol + 'BTC')

                state['bittrex'] = False
Beispiel #9
0
import time
import math
import threading
from threading import Thread
import traceback

# CONSTANTS # # # # # # # #
SELL_THRESHOLD = -0.08  # % drop/gain in the timespan of CHECK_TIMER
CHECK_TIMER = 10  # calculates the drop/gain over the last X seconds
# # # # # # # # # # # # # #

state = {}
state['binance'] = False
state['bittrex'] = False

utils.print_and_write_to_logfile('STARTING...')

binance = utils.get_binance_account()
bittrex = utils.get_bittrex_account()

binance_coins = utils.binance_symbols_and_names_to_markets_and_names(binance)
bittrex_coins = utils.bittrex_symbols_and_names_to_markets_and_names()

twitter = utils.get_twitter_account()
twitter_user = '******'

ocr = utils.get_ocr_account()

seen_coins = utils.get_seen_coins()

twitter = utils.get_twitter_account()
import time
import traceback
import time
import tweepy
import binance_utils

"""

Monitors someone's tweets for specific words.
If it contains those words, it then looks for a coin symbol in the
tweet and buys it if it can be bought on binance. Then
waits to sell the coin at a profit.

"""

utils.print_and_write_to_logfile('STARTING...')

# Get twitter id's from http://gettwitterid.com
twitter_user_ids_to_follow = ['759916693']
twitter, auth = utils.get_twitter_account()

binance = binance_utils.get_binance_account()
binance_coins = binance_utils.get_binance_buyable_coins(binance)

ignored_coins = utils.get_ignored_coins()

words_to_look_for = utils.get_words_to_look_for()

seconds_before_checking_binance_price = 30

# .05 is 5%
Beispiel #11
0
def print_trade_data(price_bought, cur_price, max_price, percent_from_max, percent_from_bought):
    formatted_cur_price = f'{cur_price:.6f}'
    formatted_bought_price = f'{price_bought:.6f}'
    formatted_max_price = f'{max_price:.6f}'

    utils.print_and_write_to_logfile("\n" + "************** NEW TRADE **************")
    utils.print_and_write_to_logfile("PRICE BOUGHT " + str(formatted_bought_price))
    utils.print_and_write_to_logfile("CUR PRICE " + formatted_cur_price)
    utils.print_and_write_to_logfile("MAX PRICE " + str(formatted_max_price))
    utils.print_and_write_to_logfile("PERCENT FROM MAX: " + str(percent_from_max))
    utils.print_and_write_to_logfile("PERCENT FROM BOUGHT PRICE: " + str(percent_from_bought) + "\n")
Beispiel #12
0
                    coin_name = utils.get_coin_name_in_text(status.text, ignored_coins, binance_coins)

                    if coin_name:
                        utils.print_and_write_to_logfile(coin_name + " in Tweet: " + status.text)
                        market = binance_coins[coin_name][0]

                        bought_price, amount_bought = handle_buying(market)

                        if amount_bought > 0:
                            handle_selling(bought_price, market, amount_bought)
        except Exception as e:
            utils.print_and_write_to_logfile(traceback.format_exc())

    def on_exception(self, exception):
        print("Exception", exception)
        print("Restarting Stream...")
        return


# Begin Listening for new Tweets
utils.print_and_write_to_logfile("AWAITING TWEETS...")

while True:
    try:
        streamListener = MyStreamListener()
        stream = tweepy.Stream(auth, streamListener, timeout=600)
        stream.filter(follow=twitter_user_ids_to_follow)
    except Exception as e:
        utils.print_and_write_to_logfile("Restarting Stream...")
        utils.print_and_write_to_logfile(e.message)