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]))
        last_trade = all_trades[exchange][-1]
        maxhistory = max(history['buy'], history['sell'])
Exemple #2
0
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]:
            del(next_act[currency])
Exemple #3
0
            lib.bprint(" Price isn't at the market price. Nothing changed")

    lib.bprint(
        " Bid:  {:.8f}\n Last: {:.8f}\n Ask:  {:.8f}\n Sprd: {:.8f}".format(
            bid, last, ask, spread))
    lib.bprint("\n Rate:  {:.8f}\n Perc:  {:.8f}\n Total: {:.8f}".format(
        baseRate, perc, rate))

# The market is done in 10^-8 btc so we need to round our rate to that to get proper fractional calculations
fl_rate = round(float(rate) * 1e8) / 1e8
lib.bprint(
    "\nComputed\n Rate  {:.8f}\n Quant {:.8f}\n USD   {:.3f} (btc={:.2f})".
    format(fl_rate, float(quantity),
           float(quantity) * approx_btc_usd, approx_btc_usd))

balanceMap = lib.returnCompleteBalances()
row = balanceMap[currency]

print("\nBalance:\n BTC   {:>13}\n {:6}{:13.8f}".format(
    row['btcValue'], currency,
    float(row['onOrders']) + float(row['available'])))

quantity += .499 * lib.satoshi
amount_to_trade = quantity / fl_rate
lib.bprint("\n{}\n   {:12.8f}\n * {:12.8f} btc\n = {:12.8f} btc".format(
    action.upper(), amount_to_trade, fl_rate, quantity))

if quantity == 0:
    sys.exit(-1)

wait = 2
Exemple #4
0
#!/usr/bin/python3
import sys
import lib
from operator import itemgetter, attrgetter
import argparse
import json

parser = argparse.ArgumentParser()
parser.add_argument('-l', "--list", action='store_true', help="Show just the currencies")
parser.add_argument('-g', "--gt", help="Minimum balance filter")
parser.add_argument('-j', "--json", action='store_true', help="Show a json compatible list")
parser.add_argument('-f', "--force", action='store_true', help="Force update")
args = parser.parse_args()

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:
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
                ['mvmed', '{:>7}', '{:7.3f}'], ['mvsrt', '{:>7}', '{:7.3f}'],
                ['24h', '{:>7}', '{:7.2f}'], ['buy', '{:>9}', '{:9.5f}'],
                ['price', '{:>9}', '{:9.5f}'], ['last', '{:>10}', '{}'],
                ['sell', '{:>9}', '{:9.5f}'], ['bprof', '{:>7}', '{:7.2f}'],
                ['bal', '{:>8}', '{:8.3f}'], ['prof', '{:>8}', '{:8.3f}']]

while True:

    last_update = time.time()
    if ix % tradeUpdate == 0:
        all_trades = lib.tradeHistory('all', forceUpdate=True)
        last_portfolio = time.strftime("%Y-%m-%d %H:%M:%S")

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

        for k, v in all_trades.items():
            all_trades[k] = {'full': v, 'last': lib.ignorePriorExits(v)}

    all_prices = lib.returnTicker(forceUpdate=True)
    last_ticker = time.strftime("%Y-%m-%d %H:%M:%S")
    if not all_prices_last:
        all_prices_last = [all_prices] * 3
        all_prices_last_list = [all_prices]

    rows = []