Esempio n. 1
0
#sys.stderr = open(os.devnull, 'w')
tty.setcbreak(sys.stdin)

anal = open('anal', 'w')

print("\033?25l")
os.system('clear')
while True:
    if index == 0:
        if ctr % cycles_before_data_update == 0:
            if not lib.is_fake:
                print("                                    ")
                print("   ... refreshing data source ...   ")
                print("                                    ")
            ticker = lib.returnTicker(forceUpdate = True)
            trades = lib.tradeHistory(forceUpdate = True)
            all_bal = lib.returnCompleteBalances()

            if not lib.is_fake:
                os.system('clear')
            print("\033[0;0H")
            stats = lib.analyze(lib.tradeHistory('BTC_STRAT'), brief = True)
            anal.write("{} {}\n".format(stats['avgBuy'], stats['btc']))
        ctr += 1

    currency = currency_list[index]
    index = (index + 1) % mod 

    did_act = False
    if currency in next_act:
        if lib.unixtime() > next_act[currency]:
# .005 is accounted for in the trades.
frac = {}
lower = {}
upper = {}

for what in ['buy', 'sell']:
    frac[what] = 1 + ((margin[what] - 0.005) * 0.92)
    lower[what] = (1 - margin[what])
    upper[what] = 1 / lower[what] + 0.00005

cycle = 0

holdList = ['GAS', 'DOGE']  #'DGB', 'GNT', 'ZRX', 'RADS', 'DCR']#'XMR', 'ETC']

while True:
    all_trades = lib.tradeHistory('all', forceUpdate=True)
    cur_balances = {
        k: v
        for k, v in lib.returnCompleteBalances().items()
        if v['btcValue'] > 0.00001
    }
    positive_balances = {k: v['cur'] for k, v in cur_balances.items()}

    all_prices = lib.returnTicker(forceUpdate=True)
    trade_ix = 0
    for k, v in positive_balances.items():
        if k == 'BTC' or k == 'LTC':
            continue

        exchange = "BTC_{}".format(k)
        backwardList = list(reversed(all_trades[exchange]))
Esempio n. 3
0
                                       rate).groups()
    else:
        word, oper, amount = '', '', ''
    rate = None

    if word == 'ask':
        rate = ask

    if word == 'bid':
        rate = bid

    if word == 'last':
        rate = last

    if word in ['break', 'profit', 'lowest', 'highest', 'high', 'low']:
        hist = lib.analyze(lib.tradeHistory(exchange), currency=exchange)

        if word == 'lowest' or word == 'low':
            if action == 'buy':
                rate = hist['lowestBuy']

            if action == 'sell':
                rate = bid

        elif word == 'highest' or word == 'high':
            if action == 'buy':
                rate = ask

            if action == 'sell':
                rate = hist['highestSell']
Esempio n. 4
0
ticker = lib.returnTicker(forceUpdate = args.force)
cur_balances = lib.returnCompleteBalances(forceUpdate = args.force)
all_balances = list([(k, float(v['btcValue']), float(v['available']) + float(v['onOrders'])) for k,v in cur_balances.items() ])
all_positive = list(filter(lambda x: x[1] > 0, all_balances))

if args.gt:
    min = float(args.gt)
    all_positive = list(filter(lambda x: x[1] > min, all_positive))

if args.list:

    print("\n".join(sorted([x[0] for x in all_positive])))
    sys.exit(0)

all_history = lib.tradeHistory()

if args.json:
    list = []
    for k,v in all_history.items():

        row = lib.analyze(v, currency=k, brief=True, sort='date')
        row['exchange'] = k
        cur = k[4:]
        if cur in cur_balances:
            row['bal'] = cur_balances[cur]

        list.append(row)

    print(json.dumps(list))
    sys.exit(0)
        max_btc_invested = max(max_btc_invested, -btc)

    break_even = -btc / cur
    return {
        'break': break_even,
        'low': cur_low,
        'high': cur_high,
        'max_btc_invested': max_btc_invested,
        'btc': btc,
        'cur': cur,
        'len': len(tradeList)
    }


print("{} {}".format(currency, profit))
data = lib.tradeHistory(currency)
process(data)
ttl = tally(data)

sortlist = sorted(data, key=lambda x: x['rate'])
#
# We want to equally weight the tranches based on currently
# outstanding investments.
#
# So we sort the trades based on price and then run through them
# until we get to a breakpoint (currently outstanding / group size)
#
groups = 6
threshold = abs(ttl['btc'] / groups)

tranche = []
def should_act(exchange, margin_buy, margin_sell, please_skip=False, extra=""):
    currency = exchange[4:]
    pList = lib.returnTicker(forceCache=True)
    data = lib.tradeHistory(exchange, forceCache=True)
    balanceMap = lib.returnCompleteBalances(forceCache=True)

    strike = find_next(data)
    if strike:
        sell_price = strike * (1 + margin_sell)
        buy_price = strike * (1 - margin_buy)
    # if we can't find anything then we can go off our averages
    else:
        analyzed = lib.analyze(data)
        sortlist = sorted(data, key=lambda x: x['rate'])
        sell_price = analyzed['lowestBuy'] * (1 + margin_sell)
        buy_price = analyzed['lowestBuy'] * (1 - margin_buy)

    order = False

    market_low = pList[exchange]['highestBid']
    market_high = pList[exchange]['lowestAsk']
    buy_rate = pList[exchange]['highestBid'] + 0.00000001
    sell_rate = pList[exchange]['lowestAsk'] - 0.00000001

    graph = graph_make(buy_price, market_low, market_high, sell_price,
                       margin_buy, margin_sell)
    market_graphic = "{:.8f} {}{:.8f}{:.8f} {}{:.8f} {}".format(
        buy_price, ' ' if buy_price < buy_rate else '>', buy_rate, sell_rate,
        ' ' if sell_price > sell_rate else '>', sell_price, graph)

    if please_skip:
        lib.plog("{:5} {:6} {} {:4}".format(currency, '*SKIP*', market_graphic,
                                            extra))
        return False

    if buy_rate < buy_price:

        p = lib.connect()
        amount_to_trade = unit / buy_rate
        order = p.buy(exchange, buy_rate, amount_to_trade)
        rate = buy_rate
        trade_type = 'buy'

    elif sell_rate > sell_price:

        p = lib.connect()
        amount_to_trade = unit / sell_rate
        if amount_to_trade < balanceMap[currency]['available']:
            #try:
            order = p.sell(exchange, sell_rate, amount_to_trade)
            rate = sell_rate
            trade_type = 'sell'
            #except:
            #    lib.plog("{:9} Failed sell {:.8f} @ {:.8f} (bal: {:.8f})".format(exchange, amount_to_trade, buy_price, balanceMap[currency]['available']))

    else:
        lib.plog("{:5} {:6} {} {:4}".format(currency, "", market_graphic,
                                            extra))
        return False

    if order:
        lib.showTrade(order,
                      exchange,
                      source='bot',
                      trade_type=trade_type,
                      rate=rate,
                      amount=amount_to_trade,
                      doPrint=False)
        lib.plog("{:5} {:6} {}".format(currency, trade_type, market_graphic))
        return True
    ttl_sell_currency = sum([x['amount'] for x in sellList])
    ttl_sell_btc = sum([x['total'] for x in sellList])

    ttl_buy_currency = 0
    ttl_buy_btc = 0
    for x in buyList:
        if ttl_buy_currency >= ttl_sell_currency:
            return x['rate']
            break
        ttl_buy_currency += x['amount']
        ttl_buy_btc += x['total']


if __name__ == "__main__":
    lib.bprint("{} @ {:.8f}".format(currency, rate))
    data = lib.tradeHistory(currency, forceUpdate=True)

    next_price = []
    for i in range(0, 10):
        strike = find_next(data)
        if strike:
            next_price.append(find_next(data))
        fake.sell(data, 0.0005 / rate, rate)

    marker = {True: '*', False: ' '}
    for p_int in range(100, 120, 2):
        p = float(p_int) / 100
        lib.bprint("{:.2f} {}".format(
            p, "\t".join([
                "{} {:.8f}".format(marker[rate > i * p], i * p)
                for i in next_price