示例#1
0
def main():
    nasdaq = StockMarket("NASDAQ", ["AAPL", "CSCO", "MSFT", "GOOG"])
    newyork = StockMarket("NYSE", ["IBM", "HPQ", "BP"])
    viewer = Viewer()
    viewer.markets = {nasdaq, newyork}
    viewer.symbols = {"IBM", "AAPL", "MSFT"}
    viewer.start()
示例#2
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))
示例#3
0
def main():
    nasdaq = StockMarket("NASDAQ", ["AAPL", "CSCO", "MSFT", "GOOG"])
    newyork = StockMarket("NYSE", ["IBM", "HPQ", "BP"])

    agg = Aggregator()
    agg.add_market(nasdaq)
    agg.add_symbols(nasdaq.symbols)
    agg.add_market(newyork)
    agg.add_symbols(newyork.symbols)
    print("aggregated symbols:", agg.symbols)

    view = Viewer()
    view.aggregator(agg, ["IBM", "AAPL", "MSFT"])
    view.print_quotes()
示例#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')
示例#5
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
示例#6
0
文件: main.py 项目: adityax10/Pyro4
def main():
    nasdaq=StockMarket("NASDAQ", ["AAPL", "CSCO", "MSFT", "GOOG"])
    newyork=StockMarket("NYSE", ["IBM", "HPQ", "BP"])

    agg=Aggregator()
    agg.add_symbols(nasdaq.symbols())
    agg.add_symbols(newyork.symbols())
    print("aggregated symbols:", agg.available_symbols())

    nasdaq.listener(agg)
    newyork.listener(agg)

    view=Viewer()
    agg.view(view, ["IBM", "AAPL", "MSFT"])
    print("")
    while True:
        nasdaq.generate()
        newyork.generate()
        time.sleep(0.5)
示例#7
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)
示例#8
0
文件: main.py 项目: benkahle/snake3d
def main():
    nasdaq=StockMarket('NASDAQ',['AAPL','CSCO','MSFT','GOOG'])
    newyork=StockMarket('NYSE',['IBM','HPQ','BP'])

    agg = Aggregator()
    agg.add_symbols(nasdaq.symbols())
    agg.add_symbols(newyork.symbols())
    print("aggregated symbols: ", agg.available_symbols())

    nasdaq.listener(agg)
    newyork.listener(agg)

    view=Viewer()
    agg.view(view, ['IBM','AAPL','MSFT'])
    print("")
    while True:
        nasdaq.generate()
        newyork.generate()
        time.sleep(0.5)
示例#9
0
def run_stock_market():
    market = StockMarket(q)
    th = threading.Thread(target=market.listen_for_orders, args=(th_stop, ))
    th.start()