Exemple #1
0
def get_price_expr(tick,d):
	if isinstance(d,datetime.date):
		res = yfinance.get_historical(tick,d)
		print 'result: ',res
		return res 
	else:
		return yfinance.get_price(tick)
Exemple #2
0
def sell_stock(ticker,amount,type,cash):
	"""
	ticker: stock symbol
	amount: quantity
	type: 'SHARES' or 'DOLLARS'
	this is also used for selling short
	"""
	value = yfinance.get_price(ticker)

	if type == 'DOLLARS':
		amount //= value # you can only sell amount many shares

	cash[-1] += value*amount 
	return (-amount,value) # you sold it dingus!
Exemple #3
0
def buy_stock(ticker,amount,type,cash):
	"""
	ticker: stock ticker
	amount: quantity
	type: 'SHARES' or 'DOLLARS'
	"""
	value = yfinance.get_price(ticker)
	value = float(value)
	amount = int(amount)
	
	if type == 'DOLLARS':
		amount //= value
	if (amount*value) < cash[-1]:
		print 'you bought: ', value*amount 
		cash[-1] -= value*amount
		return (amount,value)
	return (1,1)
Exemple #4
0
def get_price(ticker,d):
	if d == 'realtime':
		return yfinance.get_price(ticker)
	print 'updating price'
	return yfinance.get_historical(ticker, d)
Exemple #5
0
	def validate_ticker(self,ticker):
		""" validates a ticker symbol by trying a request to Yahoo
		"""
		if ticker == "" or yfinance.get_price(ticker) == '0.00':
			return False
		return True