Exemple #1
0
def check_price(nick,ticker,default_price):
        checkprice = StockMarket()
        checkprice.open_db(file_Name)
        check = StockTrade()
        check.open_db(saved_stocks)
        try:
                curprice = checkprice.get_balance(ticker)
                checked = check.get_prices(ticker)
        except:
                
                checkprice.add_stock(ticker,default_price)
                curprice = checkprice.get_balance(ticker)
                checked = check.get_prices(ticker)
        ticker = color(bold(ticker + ":"),colors.RED)
        curprice = color(str(curprice),colors.RED)
        
        phrase = ('%s ɷ %s' %(ticker,curprice))
        runs = 0
        for x in (checked):
            if nick == checked[runs][0]:
                name = color(checked[runs][0],colors.RED)
            else:
                name = checked[runs][0][:3]
            owned = (bold(" |") + " %s %s @ %s " % (name.title(), checked[runs][2], checked[runs][1]))
            phrase += owned
            runs = runs + 1

        return phrase
Exemple #2
0
def market_Things(bot, trigger):
    market = StockMarket()
    market.open_db(file_Name)
    deleteStocks = StockTrade()
    deleteStocks.open_db(saved_stocks)
                           
    ###Checks to see if all stocks exist. If not, add it at 5 GC
    for x in stocks:
        try:
            market.get_balance(x)
        except:
            market.add_stock(x,default_price)

    ###While-loop to update stock prices every minute.
    while True:
            #stocklist = []
            for x in stocks:
                
                current_price = (market.get_balance(x))
                if current_price > 499:
                        change = choice(change_500)
                elif current_price > 99:
                        change = choice(change_100)
                elif current_price > 49:
                        change = choice(change_50)
                elif current_price > 29:
                        change = choice(change_30)

                else:
                        change = choice(change_amount)
                #print ('Current Price: %s | New Price: %s' %(current_price,current_price+change))
                current_price = current_price + change
                
                if current_price < 1:
                    market.update_price(x,default_price)
                    deleteStocks.delist_stock(x)
                
                    bot.say('%s has crashed.' % (x))

                elif current_price == 1:
                    bot.say('%s is at ɷ 1 and runs the risk of crashing' % (x))
                    market.update_price(x,current_price)
                
                else:
                    market.update_price(x,current_price)
                #stocklist.append(current_price)
            #print stocklist
            market.commit_changes()
            time.sleep(60)