本文整理汇总了Python中ystockquote.get_price函数的典型用法代码示例。如果您正苦于以下问题:Python get_price函数的具体用法?Python get_price怎么用?Python get_price使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_price函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printStocks
def printStocks(sL) : # Prints the stocks
for x in sL: # A for each loop
lcd.clear() # Clears the LCD
print x + " " + ystockquote.get_price(x) # Gets the price of x and prints it to console
lcd.message(x + " " + ystockquote.get_price(x)) # Gets the price and shows it on the lcd
print ystockquote.get_change(x) # Gets the price change and prints it to the console
lcd.message(ystockquote.get_change(x)) # Gets the price change and shows it on the lcd
sleep(10) # Sleeps so it user can read the info
示例2: oil
def oil():
# crude oil
crude = ystockquote.get_price('CLJ14.NYM')
print crude
# heating oil
heat = ystockquote.get_price('HOH14.NYM')
print heat
if float(crude) < 98:
body = "Low price alert! Crude: " + crude + " Heat: " + heat
messager(body)
print body
return
示例3: buy_stock_conditionals
def buy_stock_conditionals(data, portfolio, monthly, request):
price = ystockquote.get_price(str(data))
number_shares = math.trunc(float(monthly) / float(price))
if portfolio:
for items in portfolio:
empty_stock_add_shares(data, items, number_shares)
else:
price = ystockquote.get_price(str(data))
cost = float(price) * float(number_shares)
real_cost = decimal.Decimal(cost)
PersonalStockPortfolio.objects.create(name="primary", owner=request.user, stock_one_name=str(data),
stock_one_shares=number_shares, cost=real_cost)
data = {data: number_shares}
return data
示例4: update_price
def update_price(dict):
'''
Updates portfolio with new prices
'''
print 'Updating portfolio...'
for key in dict:
dict[key][4] = ystockquote.get_price(dict[key][1])
示例5: __init__
def __init__(self, ticker):
self.ticker = ticker
params = getParams(ticker)
self.mean = params[0][0]
self.var = params[0][1]
self.vol = params[1]
self.price = get_price(self.ticker)
示例6: get_stock_cost
def get_stock_cost(data, number_shares, items):
price = ystockquote.get_price(str(data))
cost = float(price) * float(number_shares)
real_cost = decimal.Decimal(cost)
items.cost += real_cost
items.save()
return real_cost
示例7: run
def run(self):
"""
Main loop
"""
properties = {"app_id": self.app_id}
while True:
# Loop over the tickers and lookup the stock price and volume
for ticker in self.tickers:
measurements = []
price = ystockquote.get_price(ticker)
volume = ystockquote.get_volume(ticker)
timestamp = int(time.time())
if volume == 'N/A' or price == 'N/A':
sys.stderr.write('Could not find ticker \"{0}\", skipping'.format(ticker))
else:
print("ticker: {0}, price: {1}, volume: {2}".format(ticker, price, volume))
measurements.append(Measurement(metric='STOCK_PRICE',
value=price,
source=ticker,
properties=properties))
measurements.append(Measurement(metric='STOCK_VOLUME',
value=volume,
source=ticker,
properties=properties))
self.send_measurements(measurements)
time.sleep(self.interval)
示例8: buyStockIfPossible
def buyStockIfPossible(self):
for k,v in self.stocks.items():
cost = float(ystockquote.get_price(k));
if(cost < self.capital):
count = int(self.capital / cost);
self.stocks[k] = v + count;
self.capital -= cost * count;
示例9: export
def export(self, xlsx_file, s_flag):
wb = Workbook()
ws = wb.create_sheet(0)
ws.title = "Guru 13Fs"
print "Writing {0}...".format(xlsx_file)
headers = ["Gurus", "Date", "Symbol", "Action", "Average", "Minimum", "Volume", "Portfolio Impact"]
if s_flag:
headers.append("Current Share Price")
col = 0
for header in headers:
header_cell = ws.cell(row = 0, column = col)
header_cell.value = header
if header == "Gurus":
ws.merge_cells(start_row = 0, start_column = 0, end_row = 0, end_column = 2)
col += 2
col += 1
db = self.client.gurudb
gurus = db.gurus
cursor = gurus.find()
share_prices = dict()
guruRow = 1
for guru in cursor:
tickers = guru['tickers']
for ticker in tickers:
history = ticker['transactionHistory']
transactions = history['transactions']
symbol = ticker['ticker']
if share_prices.get(symbol) == None and s_flag:
share_prices[symbol] = ystockquote.get_price(symbol)
print "Retrieved {0} at ${1} for {2}".format(symbol, share_prices[symbol], guru['name'])
for transaction in transactions:
guru_cell = ws.cell(row = guruRow, column = 0)
guru_cell.value = guru['name']
ws.merge_cells(start_row = guruRow, start_column = 0, end_row = guruRow, end_column = 2)
symbol_cell = ws.cell(row = guruRow, column = self.SYMBOL_CELL)
symbol_cell.value = symbol
impact_cell = ws.cell(row = guruRow, column = self.IMPACT_START_CELL)
impact_cell.value = "{0}%".format(ticker['percent'])
transaction_cell = ws.cell(row = guruRow, column = self.DATE_CELL)
transaction_cell.value = transaction['date']
action_cell = ws.cell(row = guruRow, column = self.ACTION_CELL)
action_cell.value = transaction['entryType']
average_cell = ws.cell(row = guruRow, column = self.AVERAGE_CELL)
# convert from int to decimal. stored in mongo this way for percision reasons
average_cell.value = float(transaction['avg']) * 0.01
minimum_cell = ws.cell(row = guruRow, column = self.MINIMUM_CELL)
minimum_cell.value = float(transaction['min']) * 0.01
volume_cell = ws.cell(row = guruRow, column = self.VOLUME_CELL)
volume_cell.value = transaction['numberOfShares']
if s_flag:
current_share_price_cell = ws.cell(row = guruRow, column = self.CURRENT_SHARE_PRICE_START_CELL)
current_share_price_cell.value = share_prices.get(symbol)
guruRow += 1
wb.save(xlsx_file)
print "Wrote {0}".format(xlsx_file)
return
示例10: check
def check(symbol, position=False):
days = 20
quotes = prices(symbol, days)
_raising = raising(symbol)
_price = float(ystockquote.get_price(symbol))
_over_mavg = over_mavg(_price, quotes)
_min = min(quotes)
#print "%s min %s, now %s" % (symbol, _min, _price)
if(position):
color = "red"
else:
color = "orange"
if(_raising and
_over_mavg):
print "<div style=color:green>Raising and over mavg: BUY %s</div>" % symbol
return
if(not _over_mavg):
print "<div style=color:%s>Not over mavg: SELL %s</div>" % (color, symbol)
return
if(_price <= _min):
print "<div style=color:orange>Under 20 day min: SELL %s</div>" % (color, symbol)
return
print "<div>No matching signal for %s</div>" % symbol
示例11: post_stock_price
def post_stock_price(symbol, apikey, devicename):
'''
Retrieve the stock price for the given ticker symbol ("T" for AT&T) and
post it in the correct M2X data stream.
'''
client = M2XClient(key=apikey)
# Find the correct device if it exists, if not create it.
try:
device = [d for d in client.devices(q=devicename) if d.name == devicename][0]
except IndexError:
device = client.create_device(name=devicename,
description="Stockreport Example Device",
visibility="private")
# Get the stream if it exists, if not create the stream.
try:
stream = device.stream(symbol)
except HTTPError:
stream = device.create_stream(symbol)
device.update_stream(symbol, unit={'label': 'Dollars', 'symbol': '$'})
postime = datetime.now()
stock_price = ystockquote.get_price(symbol).encode('utf-8')
stream.add_value(stock_price, postime)
示例12: buy
def buy(self, ticker, amount):
buy_price = y.get_price(ticker)
buy_date = datetime.today()
pos = Position(ticker, buy_date, buy_price, amount)
self.open_positions.append(pos)
buy = Decimal(buy_price.strip(' "')) * Decimal(amount)
self.cash = int(self.cash - buy)
示例13: priceMe
def priceMe(tick):
price = 0
try:
price = float(ystockquote.get_price(tick))
except:
return price
return price
示例14: get_current_price
def get_current_price(symbol):
"""
Get the latest price!
:param symbol:
:return:
"""
return float(ystockquote.get_price(symbol))
示例15: __init__
def __init__(self, ticker):
self.ticker = ticker
self.price = round(float(ystock.get_price(ticker)), 2)
self.ma_5 = None
self.ma_10 = None
self.ma_20 = None
self.ma_50 = None
self._calculate_moving_averages()