def buy_crypto(symbol, amount): print(f'\nBuying {symbol} crypto coins') print('------------------------------------') try: bot_trader.order_buy_crypto_by_price(symbol=symbol, amountInDollars=amount) except Exception as holdings_err: exception_log(holdings_err) print('------------------------------------\n')
def buy(condition): global bought global entery global starting_amount global swing_low bp = 250 #bp = buying_power() - (buying_power()* 0.012) attempts = 0 #max_attempts = 10 max_attempts = round(buying_power() / bp) buy_order = robin_stocks.order_buy_crypto_by_price(ticker, bp, jsonify=False) while (buy_order.status_code != 200 and attempts < max_attempts): buy_order = robin_stocks.order_buy_crypto_by_price(ticker, bp, jsonify=False) attempts += 1 print("buy pending") time.sleep(1) if (attempts == max_attempts): if (crypto_position(ticker) > 6): bought = True entery = get_crypto_entery(ticker) * (current_market_price / crypto_position(ticker)) starting_amount = get_crypto_entery(ticker) document("BUY", condition, entery) swing_low = ti.min(close_price_historicals, 12)[-1] else: robin_stocks.cancel_all_crypto_orders() bought = False document("BUY", "FAILED", 0) else: if (crypto_position(ticker) > 6): bought = True entery = get_crypto_entery(ticker) * (current_market_price / crypto_position(ticker)) starting_amount = get_crypto_entery(ticker) document("BUY", condition, entery) swing_low = ti.min(close_price_historicals, 12)[-1] else: robin_stocks.cancel_all_crypto_orders() bought = False document("BUY", "FAILED", 0)
def on_status(self, status): if from_creator(status): tweet = status.text if "doge" in tweet: print(r.order_buy_crypto_by_price('DOGE', 20)) return True return True
def buy(symbol,dollars): print("Buying $"+str(dollars)+" worth of "+ symbol+"...") if(symbol != "DOGE"): trade = r.order_buy_crypto_by_price(symbol, dollars,'ask_price','gtc') else: trade = r.order_buy_crypto_by_quantity(symbol, int(dollars/ask(symbol)), 'ask_price', 'gtc') print(trade) # comment out when done testing return trade['id']
def buyBitcoinOnRobinhood(self): if default_config.robinhood_dca_usd_amount <= 0: Logger.info("Skip Robinhood DCA because the dca amount is no larger than 0") return username = self.secrets["robinhood_user"] passwd = self.secrets["robinhood_password"] totp = self.secrets["robinhood_totp"] login = robin_stocks.login(username, passwd, mfa_code=pyotp.TOTP(totp).now()) Logger.info(f"{login['detail']}\n") dca_amount = default_config.robinhood_dca_usd_amount buy_order = robin_stocks.order_buy_crypto_by_price("BTC", dca_amount) Logger.info(f"{buy_order}\n") self.db_manager.saveRobinhoodBuyTransaction( date=buy_order["created_at"], price=round(float(buy_order["price"]), 2), size=buy_order["quantity"], )
def order_buy_crypto_by_price(self, symbol, amountInDollars): self = r.order_buy_crypto_by_price(symbol, amountInDollars)
def buy_crypto(symbol, amount): ui.success(f'Ordering ${amount} of {symbol}....\n') result = rh.order_buy_crypto_by_price(symbol, amount) ui.chec_ref(result)
fiveMinPrice= currentPriceApiCall() currentPrice= currentPriceApiCall() #Formula to find out the percent change over the hour compare = 100 * (currentPrice - fiveMinPrice) / fiveMinPrice buycount=0 print ("Starting Bank Value:",bank) print ("Starting BitcoinUSD Value:",bitcoinUSD) #Algo while True: if compare > .2: #getting variables from buy to use in spend spend,bank=buy() if spend > .16: #buying the crypto with 10% of bank acc r.order_buy_crypto_by_price('BTC',spend) compare1=compare buycount+=1 bitcoinUSD+=1 print ("Bitcoin Bought USD amount", spend) print ("Amount of buys made",buycount) spend=0 #updating the call if bitcoinUSD > 0: currentPrice= currentPriceApiCall() compare = 100 * (currentPrice - fiveMinPrice) / fiveMinPrice while bitcoinUSD > 0: #looping here while bitcoin more thna 0 to only do one trade at a time if compare < -1 sell() bitcoinUSD=0
def buyCrypto(): try: rs.order_buy_crypto_by_price('DOGE',1) except: print("Order did not go through")