#to get processed. #We'll track our order and the order book to see if our order has gone through. #Or, if the buy price has changed, we'll cancel our order and put in another # at the new price. while (funds >= 0.01): print("Attempting to place order for $%.2f" % funds) #grab the order book book = auth.getProductOrderBook(level=1) #find our buy price best_buy, _ = book.getBestPrices() #create an order size = funds / best_buy size = nu.floor_size(size) prms = gpr.LimitOrderParams(best_buy, size, side='buy') prms.price = min(best_buy, max_price) print("Placing buy order: %s" % prms) order = auth.buy(prms) if (order.isError): print("...error placing order: %s" % order) sys.exit(4) else: print("...order placed: %s" % order) #now, loop until the status changes in #an important way (either we're done, or #we need to update the order)
#let's check that we have enough USD to place this order auth = gcl.AuthClient() usd_acct = auth.getAccounts()['USD'] usd_cost = nu.interp_float_str(args.volume, usd_acct.available) if (usd_acct.available < usd_cost): print("Insufficient USD in account.") print("Balance: $%.2f" % usd_acct.balance) print("Available: $%.2f" % usd_acct.available) sys.exit(1) size = usd_cost / args.price size = nu.floor_size(size) print("Total cost: $%.2f" % usd_cost) print("Total value if all bought: %f ETH" % size) params = gpr.LimitOrderParams(args.price, size, side='buy') print("Placing order: %s" % params) order = auth.buy(params) if (order.isError): print("... error placing order: %s" % order) else: print("... order placed: %s" % order) print("Order ID: %s" % order.id)
weights = weights / float(np.sum(weights)) if(args.price_hilo == "low"): weights = np.fliplr([weights])[0] volumes = weights*args.total_amount prices = np.asarray([np.round(x,2) for x in prices]) volumes = np.asarray([nu.floor_size(x) for x in volumes]) print("Total value if all sold: $%.2f" % np.sum(prices*volumes)) orders = [] for price,size in zip(prices, volumes): params = gpr.LimitOrderParams(price, size, side='sell') print("Placing order: %s" % params) order = auth.sell(params) if(order.isError): #error placing order #cancel all previous orders print("... error placing order: %s" % order) sys.exit(3) for o in orders: print("Canceling %s" % o.id) auth.cancelOrder(o.id) time.sleep(0.25)