def test_get_all_alignment(self):
     """ Compare bulk 'all_info' values to individual values.
     Currently broken due to misalignment from invalid CSV in
     fields: f6, k3, and maybe j2, a5, b6.
     """
     symbol = 'GOOG'
     all_info = ystockquote.get_all(symbol)
     self.assertIsInstance(all_info, dict)
     self.assertEquals(
         all_info['previous_close'],
         ystockquote.get_previous_close(symbol))
     self.assertEquals(
         all_info['volume'],
         ystockquote.get_volume(symbol))
     self.assertEquals(
         all_info['bid_realtime'],
         ystockquote.get_bid_realtime(symbol))
     self.assertEquals(
         all_info['ask_realtime'],
         ystockquote.get_ask_realtime(symbol))
     self.assertEquals(
         all_info['last_trade_price'],
         ystockquote.get_last_trade_price(symbol))
     self.assertEquals(
         all_info['today_open'],
         ystockquote.get_today_open(symbol))
     self.assertEquals(
         all_info['todays_high'],
         ystockquote.get_todays_high(symbol))
     self.assertEquals(
         all_info['last_trade_date'],
         ystockquote.get_last_trade_date(symbol))
 def test_get_all_alignment_new(self):
     """ Compare bulk 'all_info' values to individual values.
     Currently broken due to misalignment from invalid CSV in
     fields: f6, k3, and maybe j2, a5, b6.
     """
     symbol = 'GOOG'
     all_info = quote_properties.get_all(symbol)
     self.assertIsInstance(all_info, dict)
     self.assertEquals(
         all_info['PreviousClose'],
         ystockquote.get_previous_close(symbol))
     self.assertEquals(
         all_info['Volume'],
         ystockquote.get_volume(symbol))
     self.assertEquals(
         all_info['BidRealtime'],
         ystockquote.get_bid_realtime(symbol))
     self.assertEquals(
         all_info['AskRealtime'],
         ystockquote.get_ask_realtime(symbol))
     self.assertEquals(
         all_info['LastTradePriceOnly'],
         ystockquote.get_last_trade_price(symbol))
     self.assertEquals(
         all_info['Open'],
         ystockquote.get_today_open(symbol))
     self.assertEquals(
         all_info['DaysHigh'],
         ystockquote.get_todays_high(symbol))
     self.assertEquals(
         all_info['LastTradeDate'],
         ystockquote.get_last_trade_date(symbol))
def lookup():
    symbol = request.args.get('symbol')

    name = re.sub('["]', '', ystockquote.get_company_name(symbol))
    price = ystockquote.get_last_trade_price(symbol)
    change = ystockquote.get_change_percent_change(symbol)
    change_realtime, dash, change_percent = change.split()
    change_realtime = re.sub('["]', '', change_realtime)
    change_percent = re.sub('["]', '', change_percent)

    if change_realtime > 0:
        status = 'gain'
    else:
        status = 'loss'

    today = datetime.today()
    offset = 10
    week = datetime.now() - timedelta(days=offset)
    history = ystockquote.get_historical_prices(symbol, week.strftime('%Y-%m-%d'), today.strftime('%Y-%m-%d'))

    return json.dumps({ 'symbol': symbol, 'name': name, 'price': price, 'change_realtime': change_realtime, 'change_percent': change_percent, 'status': status, 'history': history })
    pass
Exemple #4
0
def stock(bot, trigger):
        if not trigger.group(2):
                bot.reply('Type .stock followed by the stock you wish to lookup.')
        else:
                chosenOne = trigger.group(2)
                change = ystockquote.get_change(chosenOne)
                change = change.split("\n")[0]
                price = ystockquote.get_last_trade_price(chosenOne)
                price = price.split("\n")[0]
                allOf = "Current Price: $" + price + " ... " + change
                bot.reply(allOf)
                
                if not trigger.group(4):
                        return
                else:
                        shares = trigger.group(4)
                        shares = int(shares)
                        change = float(change)
                        if change > 0:
                                winOrLose = "up $"
                        else:
                                winOrLose = "down $"
                        bot.reply("At " + str(shares) + " shares, you are currently " + winOrLose + str(change*shares) + " today.")
Exemple #5
0
def pridobi_zadnjo_ceno(oznaka):
    return float(ystockquote.get_last_trade_price(oznaka))
Exemple #6
0
import  ystockquote

fstock=open('shanghai_stock.txt','r')
str=fstock.read()
fstock.close();
stocks=str.split('.ss')
stock_num=len(stocks)-1
stock_num = 10

price=[]
for i in range (0,stock_num):
	str_stock="%s.ss" % (stocks[i])
	price.append(eval(ystockquote.get_last_trade_price(str_stock)))
	print(price[i])

sorted(price)
print(price)
Exemple #7
0
import  ystockquote

for i in range (0,1000):
    stock_number=i
    str_number= "6%05d.ss" % (stock_number)
    print(str_number)
    print(ystockquote.get_last_trade_price(str_number))
Exemple #8
0
def sms_response():
    # Twilio SMS data is received as a form, and the form's data is accessed
    # via various attributes ("Body" for message body, etc.)
    from_ = request.form["From"]
    incoming = request.form["Body"].upper().split()

    # The Twilio response object allows return messages to be sent
    resp = twiml.Response()

    # Determine the request type and respond accordingly
    # (SYMBOL) "SUBSCRIBE" -> Add (SYMBOL, PHONE#) to the database.
    if len(incoming) == 2 and incoming[1] == "SUBSCRIBE":
        symbol = incoming[0]

        tracker = Tracker.query.filter_by(phone_number=from_, symbol=symbol).first()

        # Check for preexisting tracker before attempting add, respond
        # accordingly
        if not tracker:
            db.session.add(Tracker(phone_number=from_, symbol=symbol))
            db.session.commit()

            resp.message(strings.subscription_response.format(symbol=symbol))

        else:
            resp.message(strings.already_subscribed.format(symbol=symbol))

    # (SYMBOL) "UNSUBSCRIBE" -> Remove (SYMBOL, PHONE#) from the database
    elif len(incoming) == 2 and incoming[1] == "UNSUBSCRIBE":
        symbol = incoming[0]

        tracker = Tracker.query.filter_by(phone_number=from_, symbol=symbol).first()

        # Check for preexisting tracker before attempting delete, respond
        # accordingly
        if not tracker:
            resp.message(strings.not_subscribed.format(symbol=symbol))
        else:
            db.session.delete(tracker)
            db.session.commit()

            resp.message(strings.unsubscribed.format(symbol=symbol))

    # (SYMBOL) ... "EXPAND" -> Send expanded (SYMBOL) information for each symbol
    elif incoming[-1] == "EXPAND":
        for symbol in incoming[:-1]:

            info = get_all_symbol(symbol)

            outgoing = strings.expanded_response.format(
                        symbol=symbol,
                        last_trade_price=info["last_trade_price"],
                        opening_price=info["today_open"],
                        closing_price=info["previous_close"],
                        price_high=info["todays_high"],
                        price_low=info["todays_low"],
                        last_trade_time=info["last_trade_time"]
                    )

            resp.message(outgoing)

    # (SYMBOL) ... -> Send (SYMBOL) stock price for each symbol
    # Symbols should be white-space delimited (e.g. SYMBOL SYMBOL ...)
    else:
        outgoing = []

        # Build list of stock prices and join as newline delimited string
        for symbol in incoming:
            price = get_last_trade_price(symbol)
            outgoing.append(strings.symbol_response.format(symbol=symbol, price=price))

        resp.message(",\n".join(outgoing))

    return str(resp)
Exemple #9
0
def symbol(symbol):

    last_trade_price = ystockquote.get_last_trade_price(symbol)

    return json.dumps({'last_trade_price': last_trade_price})
    pass
Exemple #10
0
def get_market_value(stock_symbol, stock_quantity):
    stock_price = ysq.get_last_trade_price(stock_symbol)
#    stock_quantity = 232.430
    stock_value = float(stock_price) * stock_quantity
    return stock_value
Exemple #11
0
end = current_datetime - datetime.timedelta(days=1)
# 30 days ago from today
start = current_datetime - datetime.timedelta(days=30)

# fetch the historical data from yahoo
data = ystockquote.get_historical_prices('^' + SYMBOL,
                                         start.strftime("%Y-%m-%d"),
                                         end.strftime("%Y-%m-%d"))
all_data = ystockquote.get_all('^' + SYMBOL)

# validate that we have enough historical data to continue
if len(data) < days_back:
    print 'Not enough historical data available to continue (need at least 15 days of market data)'
    sys.exit(1)

current = ystockquote.get_last_trade_price('^' + SYMBOL)
open = float(all_data['today_open'])
high = float(all_data['todays_high'])
low = all_data['todays_low']

# if the current price is higher than the open and today is a new 15-day low,
# then this is a SELL indicator
if (isCurrentHigherThanOpen(current, open) & isNewLow(low, data)):
    #print 'today is a 15-day low (' + str(low) + ') & the current price (' + str(current) + ') is higher than the open (' + str(open) + ')'
    sell = True

# if the current price is lower than the open and today is a new 15-day high,
# then this is a BUY indicator
if (isCurrentLowerThanOpen(current, open) & isNewHigh(high, data)):
    #print 'today is a 15-day high (' + str(high) + ') & the current price (' + str(current) + ') is lower than the open (' + str(open) + ')'
    buy = True
Exemple #12
0
 def stock(self):
     """Function that display different stocke's values """
     for i in self.trying:
         i.Destroy()
     self.trying = []
     # values to get from the actual stock exchange
     text2 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('AC.PA')),
                           pos=(50, 50))
     text3 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('AIR.PA')),
                           pos=(350, 50))
     text4 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('EN.PA')),
                           pos=(650, 50))
     text5 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('CAP.PA')),
                           pos=(50, 290))
     text6 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('UG.PA')),
                           pos=(350, 290))
     text7 = wx.StaticText(self.BoxStock,
                           -1,
                           str(ystockquote.get_last_trade_price('ORA.PA')),
                           pos=(650, 290))
     text2.SetForegroundColour(wx.Colour(0, 0, 0))
     text3.SetForegroundColour(wx.Colour(0, 0, 0))
     text4.SetForegroundColour(wx.Colour(0, 0, 0))
     text5.SetForegroundColour(wx.Colour(0, 0, 0))
     text6.SetForegroundColour(wx.Colour(0, 0, 0))
     text7.SetForegroundColour(wx.Colour(0, 0, 0))
     font = wx.Font(18, wx.DECORATIVE, wx.NORMAL, wx.NORMAL)
     text2.SetFont(font)
     text3.SetFont(font)
     text4.SetFont(font)
     text5.SetFont(font)
     text6.SetFont(font)
     text7.SetFont(font)
     stockValue2 = self.trying.append(text2)
     stockValue3 = self.trying.append(text3)
     stockValue4 = self.trying.append(text4)
     stockValue5 = self.trying.append(text5)
     stockValue6 = self.trying.append(text6)
     stockValue7 = self.trying.append(text7)
     #getting the change figure of each value to display the right evolution
     for j in self.getChange:
         j.Destroy()
     self.getChange = []
     test2 = ystockquote.get_change('AC.PA')
     value2 = wx.StaticText(self.BoxStock, -1, test2, pos=(150, 50))
     changeValue2 = self.getChange.append(value2)
     test3 = str(ystockquote.get_change('AIR.PA'))
     value3 = wx.StaticText(self.BoxStock, -1, test3, pos=(450, 50))
     changeValue3 = self.getChange.append(value3)
     test4 = str(ystockquote.get_change('EN.PA'))
     value4 = wx.StaticText(self.BoxStock, -1, test4, pos=(750, 50))
     changeValue4 = self.getChange.append(value4)
     test5 = ystockquote.get_change('CAP.PA')
     value5 = wx.StaticText(self.BoxStock, -1, test5, pos=(150, 290))
     changeValue5 = self.getChange.append(value5)
     test6 = str(ystockquote.get_change('UG.PA'))
     value6 = wx.StaticText(self.BoxStock, -1, test6, pos=(450, 290))
     changeValue6 = self.getChange.append(value6)
     test7 = str(ystockquote.get_change('ORA.PA'))
     value7 = wx.StaticText(self.BoxStock, -1, test7, pos=(750, 290))
     changeValue7 = self.getChange.append(value7)
     #changing the color of labels depending on the change
     if test2.find('-') != -1:
         value2.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test2.find('+') != -1:
         value2.SetForegroundColour(wx.Colour(0, 150, 0))
     if test3.find('-') != -1:
         value3.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test3.find('+') != -1:
         value3.SetForegroundColour(wx.Colour(0, 150, 0))
     if test4.find('-') != -1:
         value4.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test4.find('+') != -1:
         value4.SetForegroundColour(wx.Colour(0, 150, 0))
     if test5.find('-') != -1:
         value5.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test5.find('+') != -1:
         value5.SetForegroundColour(wx.Colour(0, 150, 0))
     if test6.find('-') != -1:
         value6.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test6.find('+') != -1:
         value6.SetForegroundColour(wx.Colour(0, 150, 0))
     if test7.find('-') != -1:
         value7.SetForegroundColour(wx.Colour(255, 0, 0))
     elif test7.find('+') != -1:
         value7.SetForegroundColour(wx.Colour(0, 150, 0))
     value2.SetFont(font)
     value3.SetFont(font)
     value4.SetFont(font)
     value5.SetFont(font)
     value6.SetFont(font)
     value7.SetFont(font)
     wx.CallLater(5000, self.stock)
Exemple #13
0
"""
# yesterday's date
end = current_datetime - datetime.timedelta(days=1)
# 30 days ago from today
start = current_datetime - datetime.timedelta(days=30)

# fetch the historical data from yahoo
data = ystockquote.get_historical_prices('^' + SYMBOL, start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))
all_data = ystockquote.get_all('^' + SYMBOL)

# validate that we have enough historical data to continue
if len(data) < days_back:
    print 'Not enough historical data available to continue (need at least 15 days of market data)'
    sys.exit(1)

current = ystockquote.get_last_trade_price('^' + SYMBOL)
open = float(all_data['today_open'])
high = float(all_data['todays_high'])
low = all_data['todays_low']

# if the current price is higher than the open and today is a new 15-day low,
# then this is a SELL indicator
if (isCurrentHigherThanOpen(current, open) & isNewLow(low, data)):
    #print 'today is a 15-day low (' + str(low) + ') & the current price (' + str(current) + ') is higher than the open (' + str(open) + ')'
    sell = True

# if the current price is lower than the open and today is a new 15-day high,
# then this is a BUY indicator
if (isCurrentLowerThanOpen(current, open) & isNewHigh(high, data)):
    #print 'today is a 15-day high (' + str(high) + ') & the current price (' + str(current) + ') is lower than the open (' + str(open) + ')'
    buy = True