Exemplo n.º 1
0
def sell(bot, trigger):
    name = trigger.nick
    try:
        shares = int(trigger.group(3))
        ticker = str(trigger.group(4).upper())
        
    except:
        try:
            shares = int(trigger.group(4))
            ticker = str(trigger.group(3).upper())
            
        except:
            bot.say('Enter which stock you\'d like to sell, and how many shares.')
            return
    if ticker not in stocks:
        bot.say('%s is not a valid stock.' % (ticker))
        return


    market = StockMarket()
    market.open_db(file_Name)
    price = market.get_balance(ticker)
    price_total = market.get_balance(ticker) * shares
    
    trade = StockTrade()
    trade.open_db(saved_stocks)
    try:
        trade.sell_stocks(name,ticker,int(shares),int(price))
        bot.say('Selling %s shares of %s for ɷ %s' %(shares,ticker,price_total))
        gravecoin.credit_user(name,price_total)

    except ValueError:
        bot.say('You don\'t have %s shares of %s.' % (shares,ticker))
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
0
def buy(bot, trigger):
    name = trigger.nick
    try:
        shares = int(trigger.group(3))
        ticker = str(trigger.group(4).upper())
        
    except:
        try:
            shares = int(trigger.group(4))
            ticker = str(trigger.group(3).upper())
            
        except:
            bot.say('Enter which stock you\'d like to buy, and how many shares.')
            return
    
    if shares < 0:
        bot.say('Enter a valid amount of stocks')
        return
    if ticker not in stocks:
        bot.say('%s is not a valid stock.' % (ticker))
        return


    market = StockMarket()
    market.open_db(file_Name)
    price = market.get_balance(ticker)
    if price < 1:
            bot.say('Stock has crashed. Please wait until it is restored')
            return


    price_total = market.get_balance(ticker) * shares
    their_balance = gravecoin.check_balance(name)
    if int(price_total) > int(their_balance):
        max_shares = (int(their_balance) / int(price))
        bot.say('The price for %s shares of %s is ɷ %s. You only have ɷ %s. At most you can buy %s shares' % (shares,ticker,price_total,their_balance,max_shares))
        return
    bot.say('Buying %s shares of %s for ɷ %s ' %(shares,ticker,price_total))
    trade = StockTrade()
    try:
        trade.open_db(saved_stocks)
        trade.buy_stocks(name,ticker,shares,price)
        gravecoin.debit_user(name,price_total)
    except:
        bot.say('Something broken, you have probably not been charged. Probably')