Ejemplo n.º 1
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)