def calculate_premium_fiat(): usdkrw = Currency('USDKRW') curr = float(usdkrw.get_ask()) btcusd = self.polo_bot.btcusd print("\tBTC premeium KRW/USD : ", str((self.krx_bot.btckrw_buy_price / (curr * btcusd))), 'with btcusd =', btcusd)
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
# 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())
# 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
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
def getchange(fromto='USDCNY'): change = Currency(fromto) bid = change.get_bid() ask = change.get_ask() rate = change.get_rate() return rate