def reinvest(name, key, secret): api = cexioapi.api(name, key, secret) currency = 'GHS/BTC' today = datetime.datetime.today() if datetime.date(today.year, today.month, today.day) < datetime.date( 2014, 5, 26): currency = 'FHM/BTC' print("Currency: " + currency) current_orders = callAPI(api.current_orders()) data = current_orders if len(data) > 0: for order in data: orderTime = int(order['time']) threeDaysAgo = (int(time.time()) - 259200) if orderTime < threeDaysAgo: #cancel order wasSuccessful = callAPI(api.cancel_order(int(order["id"]))) print("Canceled order " + order["id"] + " (" + wasSuccessful + ")") else: print("No open orders") ticker = callAPI(api.ticker(currency)) mode = config.getReinvestmentMode() last = round(Decimal(ticker["last"]), 6) print(" Last Trade: " + str(last)) if mode == "average": average = round((Decimal(ticker["high"]) + Decimal(ticker["low"])) / 2, 6) print(" Today's Average: " + str(average)) if last <= average: attemptOrder(api, currency, last) else: print(Fore.RED + "Last trade isn't below average.") elif mode == "percent": percent = Decimal(config.getPercent()) / 100 low = round(Decimal(ticker["low"]), 6) print(" Today's low: " + str(low)) low += low * percent print(" Max purhcase threshold (" + str(percent * 100) + "%): " + str(low)) if last <= low: attemptOrder(api, currency, last) else: print("Last trade is not within " + str(percent * 100) + "% of today's low") elif mode == "any": attemptOrder(api, currency, last) else: print(Fore.RED + "Invalid mode: " + mode + " please check config file.")
def reinvest(name, key, secret): api = cexioapi.api(name,key,secret) currency = 'GHS/BTC' today = datetime.datetime.today() if datetime.date(today.year, today.month,today.day) < datetime.date(2014,5,26): currency = 'FHM/BTC' print("Currency: " + currency) current_orders = callAPI(api.current_orders()) data = current_orders if len(data)>0: for order in data: orderTime = int(order['time']) threeDaysAgo = (int(time.time()) - 259200) if orderTime < threeDaysAgo: #cancel order wasSuccessful = callAPI(api.cancel_order(int(order["id"]))) print("Canceled order " + order["id"] + " ("+wasSuccessful+")") else: print("No open orders") ticker = callAPI(api.ticker(currency)) mode = config.getReinvestmentMode() last = round(Decimal(ticker["last"]),6) print(" Last Trade: " + str(last)) if mode == "average": average = round((Decimal(ticker["high"])+Decimal(ticker["low"]))/2,6) print(" Today's Average: " + str(average)) if last <= average: attemptOrder(api,currency, last) else: print(Fore.RED + "Last trade isn't below average.") elif mode == "percent": percent = Decimal(config.getPercent())/100; low = round(Decimal(ticker["low"]),6) print(" Today's low: " + str(low)) low += low*percent print(" Max purhcase threshold (" + str(percent*100)+"%): " + str(low)) if last <= low: attemptOrder(api,currency,last) else: print("Last trade is not within " + str(percent*100) + "% of today's low") elif mode == "any": attemptOrder(api,currency,last) else: print(Fore.RED+"Invalid mode: " + mode + " please check config file.")
def reinvest(name, key, secret, currency, investments): print(Fore.RED + "Currency: " + currency) api = cexioapi.api(name,key,secret) today = datetime.datetime.today() for plan in investments: pc = plan.getAttr("currency") method = plan.getAttr("method") threshold = plan.getAttr("threshold") enabled = plan.getAttr("enabled") color = Back.RED if enabled == False else Back.GREEN print(Fore.WHITE +color+ "Currency: " + pc + " Investment Method: " + method + " Threshold: " + str(threshold) + " Enabled: " + str(enabled)) if enabled == True:#["LTC", "NMC", "BTC", "GHS"] couple = "" if pc == "LTC" and not currency == "BTC": #turn into btc first couple = "LTC/BTC" elif pc == "NMC" and (currency == "LTC" or currency == "FHM"): couple = "NMC/BTC" #turn into btc first elif pc == "GHS" and currency == "LTC": couple = "GHS/BTC" elif pc == "FHM" and currency == "GHS": #add FM* date checking to switch to GHS after the last day? #not here, but just making note continue else: couple = currency +"/"+pc print("Checking open orders for " + couple) current_orders = callAPI(api.current_orders(couple)) #print("Length of orders: " + str(len(current_orders))) if len(current_orders) > 1: for order in current_orders: orderTime = int(order["time"]) threeDaysAgo = (int(time.time()) - 259200) if orderTime < threeDaysAgo: wasSuccessful = callAPI(api.cancel_order(int(order["id"]))) print("Canceled order " + order["id"] + " ("+wasSuccessful+")") else: print("No open orders for " + couple) ticker = callAPI(api.ticker(couple)) last = ticker['last'] last = round(Decimal(last),6) print(" Last Trade: " + str(last)) print("Checking reinvestment criteria for '" + method + "'") success = False if method == "average": average = round((Decimal(ticker["high"])+Decimal(ticker["low"]))/2,6) print(" Today's Average: " + str(average)) if last <= average: success = True #attemptOrder(api,couple, last) else: print(Fore.RED + "Last trade isn't below average.") elif method == "percent": percent = Decimal(threshold)/100; low = round(Decimal(ticker["low"]),6) print(" Today's low: " + str(low)) low += low*percent print(" Max purhcase threshold (" + str(percent*100)+"%): " + str(low)) if last <= low: success = True #attemptOrder(api,couple,last) else: print("Last trade is not within " + str(percent*100) + "% of today's low") elif method == "any": success = True #attemptOrder(api,couple,last) else: success = False print(Fore.RED+"Invalid mode: " + mode + " please check config file.") if success == True: cs = couple.split("/") if( cs[0] != currency): orderType = 'sell' else: orderType = 'buy' attemptOrder(api,couple,orderType,last)
def reinvest(name, key, secret, currency, investments): print(Fore.RED + "Currency: " + currency) api = cexioapi.api(name, key, secret) today = datetime.datetime.today() for plan in investments: pc = plan.getAttr("currency") method = plan.getAttr("method") threshold = plan.getAttr("threshold") enabled = plan.getAttr("enabled") color = Back.RED if enabled == False else Back.GREEN print(Fore.WHITE + color + "Currency: " + pc + " Investment Method: " + method + " Threshold: " + str(threshold) + " Enabled: " + str(enabled)) if enabled == True: #["LTC", "NMC", "BTC", "GHS"] couple = "" if pc == "LTC" and not currency == "BTC": #turn into btc first couple = "LTC/BTC" elif pc == "NMC" and (currency == "LTC" or currency == "FHM"): couple = "NMC/BTC" #turn into btc first elif pc == "GHS" and currency == "LTC": couple = "GHS/BTC" elif pc == "FHM" and currency == "GHS": #add FM* date checking to switch to GHS after the last day? #not here, but just making note continue else: couple = currency + "/" + pc print("Checking open orders for " + couple) current_orders = callAPI(api.current_orders(couple)) #print("Length of orders: " + str(len(current_orders))) if len(current_orders) > 1: for order in current_orders: orderTime = int(order["time"]) threeDaysAgo = (int(time.time()) - 259200) if orderTime < threeDaysAgo: wasSuccessful = callAPI( api.cancel_order(int(order["id"]))) print("Canceled order " + order["id"] + " (" + wasSuccessful + ")") else: print("No open orders for " + couple) ticker = callAPI(api.ticker(couple)) last = ticker['last'] last = round(Decimal(last), 6) print(" Last Trade: " + str(last)) print("Checking reinvestment criteria for '" + method + "'") success = False if method == "average": average = round( (Decimal(ticker["high"]) + Decimal(ticker["low"])) / 2, 6) print(" Today's Average: " + str(average)) if last <= average: success = True #attemptOrder(api,couple, last) else: print(Fore.RED + "Last trade isn't below average.") elif method == "percent": percent = Decimal(threshold) / 100 low = round(Decimal(ticker["low"]), 6) print(" Today's low: " + str(low)) low += low * percent print(" Max purhcase threshold (" + str(percent * 100) + "%): " + str(low)) if last <= low: success = True #attemptOrder(api,couple,last) else: print("Last trade is not within " + str(percent * 100) + "% of today's low") elif method == "any": success = True #attemptOrder(api,couple,last) else: success = False print(Fore.RED + "Invalid mode: " + mode + " please check config file.") if success == True: cs = couple.split("/") if (cs[0] != currency): orderType = 'sell' else: orderType = 'buy' attemptOrder(api, couple, orderType, last)