def get_currency_rate(t0, t1=None): ''' ''' t0 = t0.upper() if not t1: ticker = Currency(t0) return ticker.get_rate() else: t1 = t1.upper() ticker = Currency(t0 + t1) return ticker.get_rate()
def get_rate(args_dict): amt = args_dict['amt'] b_curr = args_dict['b_curr'] d_curr = args_dict['d_curr'] c = args_dict['currency'] n = args_dict['name'] # check whether we need to find ISO 4217 codes if c or n: currency_options = (c, n) names = b_curr, d_curr b_curr, d_curr = parse_args(currency_options, names) ISO_str = b_curr + d_curr # Yahoo Finance API call currency = Currency(ISO_str) trade_time = currency.get_trade_datetime() current_rate = float(currency.get_rate()) value = amt * current_rate # modify args dictionary with data needed for display args_dict['b_curr_updated'] = b_curr args_dict['d_curr_updated'] = d_curr args_dict['value'] = value args_dict['current_rate'] = current_rate args_dict['trade_time'] = trade_time return args_dict
def _getValue(symbol): ret = {} cur = Currency(symbol) ret['rate'] = cur.get_rate() if ret['rate']: time = datetime.datetime.strptime(cur.get_trade_datetime(), '%Y-%m-%d %H:%M:%S %Z%z') ret['tradeDateTime'] = int(time.timestamp()) return ret return None
def get_curr_prices(currs): data = [] for c in currs: curr_data = {} curr = Currency(c) curr_data['symbol'] = c curr_data['price'] = round(float(curr.get_rate()), 2) data.append(curr_data) return data
def get_rate(ticker): rate = 0 while rate == 0: try: ccy_pair = Currency(ticker) ccy_pair.refresh() rate = ccy_pair.get_rate() except Exception, e: pass
def get_rate(ticker): logging.debug('get_rate %s' % ticker) rate = 0 trade_time = 0 while rate == 0: try: ccy_pair = Currency(ticker) ccy_pair.refresh() rate = ccy_pair.get_rate() #trade_time = str(ccy_pair.get_trade_datetime()) trade_time = datetime.datetime.now().time() except HTTPError as e: logging.debug('HTTP Error') except Exception as e: logging.exception(e) raise e return rate, trade_time
def Run(): currencies = [['EURCHF',1.05,1.20], ['EURUSD',1.05,1.25], ['CHFUSD',0.98,1.08], ] for curr in currencies: print curr eur_pln = Currency(curr[0]) #print eur_pln.get_bid() #print eur_pln.get_ask() conv_rate = float(eur_pln.get_rate()) print conv_rate line ='' if conv_rate<curr[1]: line ='Should consider switching currency: %0.2f for %s' %(conv_rate,curr[0]) if conv_rate>curr[2]: line ='Should consider switching currency: %0.2f for %s' %(conv_rate,curr[0])
class TestCurrency(TestCase): def setUp(self): self.eur_pln = Currency('EURPLN') def test_eurpln(self): # assert these are float-like float(self.eur_pln.get_bid()) float(self.eur_pln.get_ask()) float(self.eur_pln.get_rate()) def test_eurpln_date(self): eur_pln = Currency('EURPLN') try: datetime.datetime.strptime(eur_pln.get_trade_datetime(), "%Y-%m-%d %H:%M:%S %Z%z") except ValueError as v: if "bad directive" in str(v): raise SkipTest("datetime format checking requires the %z directive.") else: raise
class TestCurrency(TestCase): def setUp(self): self.eur_pln = Currency('EURPLN') def test_eurpln(self): # assert these are float-like float(self.eur_pln.get_bid()) float(self.eur_pln.get_ask()) float(self.eur_pln.get_rate()) def test_eurpln_date(self): eur_pln = Currency('EURPLN') try: datetime.datetime.strptime(eur_pln.get_trade_datetime(), "%Y-%m-%d %H:%M:%S %Z%z") except ValueError as v: if "bad directive" in str(v): raise SkipTest( "datetime format checking requires the %z directive.") else: raise
#General Public License for more details. import matplotlib.pyplot as plt import matplotlib.animation as animation import matplotlib.dates as mdates import datetime from yahoo_finance import Currency fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) currencies = Currency('usdeur') spot = 1 xar = [] yar = [] ymin = float(currencies.get_rate()) - 0.0005 ymax = ymin + 0.0010 def animate(i): global xar, yar, ymin, ymax #gets the course currencies.refresh() y = currencies.get_rate() x = datetime.datetime.now() #makes the y axis larger if needed if float(y) > ymax: ymax = float(y) + 0.0005 if float(y) < ymin:
# Fix bug: https://github.com/ranaroussi/fix-yahoo-finance (The future, I think that the bug is solved) # pip install fix_yahoo_finance --upgrade --no-cache-dir print("+++++pandas_datareader+++++") from pandas_datareader import data as pdr import fix_yahoo_finance as yf # <== that's all it takes :-) # For Stock of Thailand, the symbol must be followed with '.BK' # download dataframe ptt = pdr.get_data_yahoo("PTT.BK", start="2017-01-01", end="2017-04-30") print(ptt.tail()) print() # Forth example # How to install yahoo_finance package # Reference: https://pypi.python.org/pypi/yahoo-finance # pip install yahoo_finance from yahoo_finance import Share yahoo = Share("YHOO") print("\n++++YHOO stock++++") print (yahoo.get_open()) print (yahoo.get_price()) print (yahoo.get_trade_datetime()) from yahoo_finance import Currency eur_pln = Currency('EURPLN') print("\n++++Currency of EURPLN++++") print (eur_pln.get_bid()) print (eur_pln.get_ask()) print (eur_pln.get_rate()) print (eur_pln.get_trade_datetime())
#!/usr/bin/env python3 # Documentation at https://pypi.python.org/pypi/yahoo-finance from yahoo_finance import Share share_apple = Share("AAPL") print(share_apple.get_name()) print(share_apple.get_price()) print(share_apple.get_trade_datetime()) print(share_apple.get_currency()) print(share_apple.get_200day_moving_avg()) share_apple.refresh() print(share_apple.get_price()) print("---") from yahoo_finance import Currency btc_in_eur = Currency("BTCEUR") print(btc_in_eur.get_rate()) print(btc_in_eur.get_trade_datetime()) btc_in_eur.refresh() print(btc_in_eur.get_rate())
import matplotlib.pyplot as plt import matplotlib.animation as animation import matplotlib.dates as mdates import datetime from yahoo_finance import Currency fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) currencies = Currency('usdeur') spot = 1 xar=[] yar=[] ymin = float(currencies.get_rate())-0.0005 ymax = ymin + 0.0010 def animate(i): global xar, yar, ymin, ymax #gets the course currencies.refresh() y = currencies.get_rate() x = datetime.datetime.now() #makes the y axis larger if needed if float(y) > ymax: ymax = float(y)+0.0005 if float(y) < ymin: ymin = float(y) - 0.0005
#from pandas_datareader import data as web from yahoo_finance import Currency #import pandas.io.data as web from tabulate import tabulate from datetime import datetime as dt start_dt = '2011-01-01' end_dt = dt.today().strftime("%Y-%m-%d") jpy = Currency('EURUSD') print jpy.get_rate()
def getchange(fromto='USDCNY'): change = Currency(fromto) bid = change.get_bid() ask = change.get_ask() rate = change.get_rate() return rate
def get_rate(self, source_code, dest_code): previous_locale = locale.getlocale() locale.setlocale(locale.LC_ALL, 'C') currency = Currency(source_code + dest_code) locale.setlocale(locale.LC_ALL, previous_locale) return currency.get_rate()
from yahoo_finance import Share yahoo = Share('YHOO') yahoo.get_open() yahoo.get_price() yahoo.get_trade_datetime() yahoo.refresh() #Refresh data from market yahoo.get_historical('2014-04-25', '2014-04-29') from yahoo_finance import Currency eur_pln = Currency('EURPLN') eur_pln.get_bid() eur_pln.get_ask() eur_pln.get_rate() eur_pln.get_trade_datetime() eur_pln.refresh() #reading google finance data import pandas_datareader.data as web import datetime start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2013, 1, 27) f = web.DataReader("F", 'google', start, end) f.ix['2010-01-04'] #reading yahoo finance data #not working import pandas_datareader.data as web
def getExchangeRate(ccyName): ccy = Currency(ccyName) return ccy.get_rate()
while True: current_price = share.get_price( ) # Call the get_price method to get stock price cu_price = float( current_price ) # Declare variable cu_price to convert stock price to floating point value. float(share_price) # Convert the price you paid to a floating value too. if cu_price >= share_price: # If share price is more than or equal to what you paid, switch on green led on third strip. sb.shares.lights.green.on() else: # Otherwise switch on the red led: sb.shares.lights.red.on() sb.shares.lights.green.off() share.refresh() exchange_price = currency_pair.get_rate( ) # Call the get_rate method to get current exchange rate. xr_price = float( exchange_price ) # Declare variable xr_price to convert exchange rate to floating point value. float( currency_price ) # Convert the price you paid for the currency to a floating value too. if xr_price >= currency_price: # If exchange rate is more than or equal to what you paid, switch on green led on fourth strip. sb.xr.lights.green.on() sb.xr.lights.red.off() else: # Otherwise switch on the red led: sb.xr.lights.red.on() sb.xr.lights.green.off() share.refresh() sleep(3)
# get_year_high() # get_year_low() # get_50day_moving_avg() # get_200day_moving_avg() # get_price_earnings_ratio() # get_price_earnings_growth_ratio() # get_price_sales() # get_price_book() # get_short_ratio() # get_trade_datetime() # get_historical(start_date, end_date) # get_info() # refresh() from yahoo_finance import Currency eur_pln = Currency('EURPLN') print eur_pln.get_bid() print eur_pln.get_ask() print eur_pln.get_rate() print eur_pln.get_trade_datetime() eur_pln.refresh() print eur_pln.get_rate() print eur_pln.get_trade_datetime() # get_bid() # get_ask() # get_rate() # get_trade_datetime() # refresh()
data = data = quandl.get(tickers,start_date=start, end_date=end) data.tail(1).T s=data[["CHRIS/SHFE_AU1 - Close","YAHOO/INDEX_HUI - Adjusted Close","CHRIS/CME_GC1 - Last"]] s.apply(lambda x: (x - np.mean(x)) / (np.max(x) - np.min(x)), axis=0).ix['2014':].plot(color=tableau20) #============================================================================== # #============================================================================== import pandas_datareader.data as web df = web.DataReader("EURUSD=x", 'yahoo', start, end) from yahoo_finance import Currency fx = Currency('EURUSD') fx.get_bid() fx.get_ask() fx.get_rate() fx.get_trade_datetime() fx.get_historical('2014-04-25', '2014-04-29') fx.data_set