예제 #1
0
파일: STONKS.py 프로젝트: fjggmg/STONKS
def buy1():
    cash = str(r.load_phoenix_account(info='account_buying_power'))
    cash = cash.replace("{'currency_code': 'USD', 'currency_id': '1072fc76-1862-41ab-82c2-485837590762', 'amount': '","")
    cash = cash.replace("'}", "")
    cash = float(cash)
    r.order_buy_crypto_by_price('BTC', cash, 'bid_price')
    print(str(r.get_crypto_positions(info='quantity_available')))
    print("bought btc " + str(r.get_crypto_positions(info='quantity_available')))
예제 #2
0
def trailing_stop_loss():
    ticker = input(
        "Enter your desired crypto ticker to perform the trailing stop loss on.\n> "
    )
    for holding in rh.get_crypto_positions():
        if ticker.upper() == holding["currency"]["code"]:
            crypto = holding
    if crypto == None:
        print(
            "You do not own any of the specified crypto. Please place an order on Robinhood, then run this program."
        )
    else:
        amount = input("You currently own " +
                       str(crypto["cost_bases"][0]["direct_quantity"]) + " " +
                       ticker + ". Please enter your desired sell amount.\n> ")
        stopAmt = 1.0 - float(
            input(
                "Please enter the trailing stop loss percentage (as a decimal) (ex 0.25 for 25% stop loss).\n> "
            ))
        cost_basis = float(crypto["cost_bases"][0]["direct_cost_basis"]) / \
            float(crypto["cost_bases"][0]["direct_quantity"])

        # Set default strike price
        crypto_price = float(rh.crypto.get_crypto_quote(ticker)["mark_price"])
        if (crypto_price * stopAmt > cost_basis):
            strike_price = crypto_price * stopAmt
        else:
            strike_price = cost_basis * stopAmt

        counter = 60
        while True:
            try:
                crypto_price = float(
                    rh.crypto.get_crypto_quote(ticker)["mark_price"])
            except:
                counter += 1
                continue
            if (counter >= 60):
                print(str(datetime.datetime.now()) + ":")
                print("CURRENT DOGE PRICE: " + str(crypto_price))
                print("COST BASIS: " + str(cost_basis))
                print("STRIKE PRICE: " + str(strike_price) + "\n")
                counter = 0
            if crypto_price < strike_price:
                # Sell all crypto
                print("CURRENT DOGE PRICE: " + str(crypto_price))
                print("COST BASIS: " + str(cost_basis))
                print("STRIKE PRICE: " + str(strike_price))
                print("SELLING " + amount + " " + ticker.upper())
                # rh.order_sell_crypto_by_quantity(crypto["quantity"])
                break
            # Increase cost basis if price goes up
            elif crypto_price > cost_basis:
                cost_basis = crypto_price
                strike_price = cost_basis * stopAmt
            counter += 1
            sleep(1)
예제 #3
0
파일: STONKS.py 프로젝트: fjggmg/STONKS
def sell1():
    total = str(r.get_crypto_positions(info='quantity_available'))
    total = total.replace("['", "")
    total = total.replace("']", "")
    r.order_sell_crypto_by_quantity('BTC', total)
    cash = str(r.load_phoenix_account(info='account_buying_power'))
    cash = cash.replace("{'currency_code': 'USD', 'currency_id': '1072fc76-1862-41ab-82c2-485837590762', 'amount': '", "")
    cash = cash.replace("'}", "")
    print("sold btc for " + cash)
예제 #4
0
 def test_crypto_positions(self):
     positions = r.get_crypto_positions(info=None)
     first = positions[0]
     assert (first['account_id'] == self.account)
     assert ('account_id' in first)
     assert ('cost_bases' in first)
     assert ('created_at' in first)
     assert ('currency' in first)
     assert ('id' in first)
     assert ('quantity' in first)
     assert ('quantity_available' in first)
     assert ('quantity_held_for_buy' in first)
     assert ('quantity_held_for_sell' in first)
     assert ('updated_at' in first)
예제 #5
0
    def getHoldings(self, ticker):
        # this contains the amount we currently own by id and code
        # quantity_available may be better
        quantity = 0.0
        try:
            result = r.get_crypto_positions()
            for t in range(0, len(result)):
                symbol = result[t]['currency']['code']
                if (symbol == ticker):
                    quantity = result[t]['quantity']
        except:
            print("Got exception while getting holdings from RobinHood.")
            quantity = -1.0

        return float(quantity)
예제 #6
0
파일: STONKS.py 프로젝트: fjggmg/STONKS
def logic(total1):
    x = []
    buywatch = False
    sellwatch = False

    while len(x) < 50:
        #f = open("files.txt", "r")
        #cash = float(f.readline())
        #qty = float(f.readline())
        #f.close()
        cash = str(r.load_phoenix_account(info='account_buying_power'))
        cash = cash.replace("{'currency_code': 'USD', 'currency_id': '1072fc76-1862-41ab-82c2-485837590762', 'amount': '", "")
        cash = cash.replace("'}", "")
        cash = float(cash)

        qty = str(r.get_crypto_positions(info='quantity_available'))
        qty = total.replace("['", "")
        qty = total.replace("']", "")
        qty = float(qty)


        y = float(r.get_crypto_quote('BTC', info='bid_price'))
        print(y)
        x.append(y)

        z = len(x) - 1
        dif = round(((x[0]-x[z])/x[z])*100, 5)
        print(dif)


        if dif > .001 and sellwatch == False and cash != 0:
            buywatch = True


        if buywatch:
            if x[z] > x[z - 1] > x[z - 2]:
                buy1()
                sellwatch = True
                buywatch = False
        if qty != 0:
            if x[z] < x[z - 1] < x[z - 2]:
                sell1()
                sellwatch = False
        time.sleep(1)
예제 #7
0
def get_holdings():
    positions = r.get_crypto_positions()
    for pos in positions:
        if pos["currency"]["code"] == "BTC":
            return float(pos["quantity"])
    return 0.0
예제 #8
0
    return LAST14RSI, LAST14SO, LAST14WR


def fixTime(x):
    x = datetime.fromisoformat(x[:-1])
    x.strftime('%Y-%m-%d %H:%M:%S')
    return x





if __name__ == '__main__':
    login = rh.login('username', 'password')
    my_crypto = rh.get_crypto_positions()

    ETHDATA = rh.crypto.get_crypto_historicals('ETH', '5minute', 'day')

    mostRecentTime = fixTime(ETHDATA[-1]['begins_at'])

    for i in range(14,len(ETHDATA)):
        indicators = getLAST14(ETHDATA[i-14:i])
        nextClose = round(float(ETHDATA[i]['close_price']),2)
        currentClose = round(float(ETHDATA[i-1]['close_price']),2)
        pctChange = round((nextClose - currentClose)/currentClose,4)
        time = fixTime(ETHDATA[i]['begins_at'])
        vals = (currentClose, nextClose)
        print(time, vals, pctChange, indicators)

    print('Most recent data point:',mostRecentTime)
예제 #9
0
파일: STONKS.py 프로젝트: fjggmg/STONKS
        share = share.replace(" ", "")
    print(total)
    f.close()
    d.close()




getticks()
buyer()
while (True):
    tracker()
x=0
while (x==1):

    total = str(r.get_crypto_positions(info='quantity_available'))
    total = total.replace("['", "")
    total = total.replace("']", "")
    cash = str(r.load_phoenix_account(info='account_buying_power'))
    cash = cash.replace("{'currency_code': 'USD', 'currency_id': '1072fc76-1862-41ab-82c2-485837590762', 'amount': '", "")
    cash = cash.replace("'}", "")
    print(cash)
    print(total)
    logic(total)

    print(current)



#print(cryptocompare.get_price('BTC',curr='USD',full=False))
#r.order_buy_crypto_by_price('BTC',1.0)