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')
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())
api = utils.get_api() time_until_cancel_processing_order_minutes = 5 satoshi_50k = 0.0005 ks = initialize_keltner_strat() ps = initialize_percent_strat() hs = initialize_hodl_strat() rs = initialize_reddit_strat() hl = initialize_buy_low_sell_high_strat() rands = initialize_random_strat() utils.print_and_write_to_logfile("\n** Beginning run at " + utils.get_date_time() + " **\n") # Main Driver while True: try: total_bitcoin = utils.get_total_bitcoin(api) # run_keltner_strat() # run_percent_strat() # run_hodl_strat() # run_buy_low_sell_high_strat() # run_random_strat() # orders_query = api.get_open_orders("")