Example #1
0
 def __init__(self, name):
     self.name = name
     if Currency(self.name).get_rate() is None:
         raise ValueError(name + " is not a valid currency.")
     self.bid = Currency(self.name).get_bid()
     self.ask = Currency(self.name).get_ask()
     self.rate = Currency(self.name).get_rate()
     self.datetime = Currency(self.name).get_trade_datetime()
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()
Example #3
0
def main():
    """ Reads in a CSV file specifying the portfolio of stocks
    and their respective ratios within the portfolio."""
    stocks = {}
    with open(STOCK_RATIO_FILE) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader:
            ticker, fraction = row[0].strip(), float(row[1].strip())
            stocks[ticker] = {}
            share = Share(ticker)
            scurr = share.get_currency()
            if scurr != CURRENCY:
                xchrate = float(Currency(scurr + CURRENCY).get_rate())
            else:
                xchrate = 1.0
            price = float(share.get_price()) * xchrate
            stocks[ticker]['price'] = price
            stocks[ticker]['in_currency'] = CURRENCY
            stocks[ticker]['target_ratio'] = fraction
            stocks[ticker]['name'] = share.get_name()
            stocks[ticker]['target_number'] = np.round(fraction * TOTAL_CASH /
                                                       price)

    print(json.dumps(stocks, indent=2))

    total_value = 0
    for stock in stocks:
        s = stocks[stock]
        total_value += s['price'] * s['target_number']

    print('Total Portfolio Value:')
    print(total_value)
Example #4
0
File: Arby.py Project: wai1496/Arby
 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)
Example #5
0
def chf():
    global cad_chf, chf_cad, aud_chf, chf_aud, hkd_chf, chf_hkd, inr_chf, chf_inr, sgd_chf, chf_sgd

    cad_chf = float(Currency('CADCHF').get_rate())
    chf_cad = 1 / cad_chf

    aud_chf = float(Currency('AUDCHF').get_rate())
    chf_aud = 1 / aud_chf

    hkd_chf = float(Currency('HKDCHF').get_rate())
    chf_hkd = 1 / hkd_chf

    inr_chf = float(Currency('INRCHF').get_rate())
    chf_inr = 1 / inr_chf

    sgd_chf = float(Currency('SGDCHF').get_rate())
    chf_sgd = 1 / sgd_chf
Example #6
0
def cad():
    global aud_cad, cad_aud, hkd_cad, cad_hkd, inr_cad, cad_inr, sgd_cad, cad_sgd, sgd_jpy, jpy_sgd

    aud_cad = float(Currency('AUDCAD').get_rate())
    cad_aud = 1 / aud_cad

    hkd_cad = float(Currency('HKDCAD').get_rate())
    cad_hkd = 1 / hkd_cad

    inr_cad = float(Currency('INRCAD').get_rate())
    cad_inr = 1 / inr_cad

    sgd_cad = float(Currency('SGDCAD').get_rate())
    cad_sgd = 1 / sgd_cad

    sgd_jpy = float(Currency('SGDJPY').get_rate())
    jpy_sgd = 1 / sgd_jpy
Example #7
0
def aud():
    global hkd_aud, aud_hkd, inr_aud, aud_inr, sgd_aud, aud_sgd, inr_gbp, gbp_inr, sgd_gbp, gbp_sgd

    hkd_aud = float(Currency('HKDAUD').get_rate())
    aud_hkd = 1 / hkd_aud

    inr_aud = float(Currency('INRAUD').get_rate())
    aud_inr = 1 / inr_aud

    sgd_aud = float(Currency('SGDAUD').get_rate())
    aud_sgd = 1 / sgd_aud

    inr_gbp = float(Currency('INRGBP').get_rate())
    gbp_inr = 1 / inr_gbp

    sgd_gbp = float(Currency('SGDGBP').get_rate())
    gbp_sgd = 1 / sgd_gbp
Example #8
0
def hkd():
    global inr_hkd, hkd_inr, sgd_hkd, hkd_sgd, hkd_eur, eur_hkd, inr_eur, eur_inr, sgd_eur, eur_sgd

    inr_hkd = float(Currency('INRHKD').get_rate())
    hkd_inr = 1 / inr_hkd

    sgd_hkd = float(Currency('SGDHKD').get_rate())
    hkd_sgd = 1 / sgd_hkd

    hkd_eur = float(Currency('HKDEUR').get_rate())
    eur_hkd = 1 / hkd_eur

    inr_eur = float(Currency('INREUR').get_rate())
    eur_inr = 1 / inr_eur

    sgd_eur = float(Currency('SGDEUR').get_rate())
    eur_sgd = 1 / sgd_eur
Example #9
0
def inr():
    global sgd_inr, inr_sgd, aud_usd, usd_aud, hkd_usd, usd_hkd, inr_usd, usd_inr, sgd_usd, usd_sgd

    sgd_inr = float(Currency('SGDINR').get_rate())
    inr_sgd = 1 / sgd_inr

    aud_usd = float(Currency('AUDUSD').get_rate())
    usd_aud = 1 / aud_usd

    hkd_usd = float(Currency('HKDUSD').get_rate())
    usd_hkd = 1 / hkd_usd

    inr_usd = float(Currency('INRUSD').get_rate())
    usd_inr = 1 / inr_usd

    sgd_usd = float(Currency('SGDUSD').get_rate())
    usd_sgd = 1 / sgd_usd
Example #10
0
def usd():
    global usd_eur, eur_usd, usd_jpy, jpy_usd, chf_usd, usd_chf, cad_usd, usd_cad, gbp_usd, usd_gbp

    eur_usd = float(Currency('EURUSD').get_rate())
    usd_eur = 1 / eur_usd

    jpy_usd = float(Currency('JPYUSD').get_rate())
    usd_jpy = 1 / jpy_usd

    gbp_usd = float(Currency('GBPUSD').get_rate())
    usd_gbp = 1 / gbp_usd

    chf_usd = float(Currency('CHFUSD').get_rate())
    usd_chf = 1 / chf_usd

    cad_usd = float(Currency('CADUSD').get_rate())
    usd_cad = 1 / cad_usd
Example #11
0
def eur():
    global jpy_eur, eur_jpy, gbp_eur, eur_gbp, chf_eur, eur_chf, cad_eur, eur_cad, aud_eur, eur_aud

    jpy_eur = float(Currency('JPYEUR').get_rate())
    eur_jpy = 1 / jpy_eur

    gbp_eur = float(Currency('GBPEUR').get_rate())
    eur_gbp = 1 / gbp_eur

    chf_eur = float(Currency('CHFEUR').get_rate())
    eur_chf = 1 / chf_eur

    cad_eur = float(Currency('CADEUR').get_rate())
    eur_cad = 1 / cad_eur

    aud_eur = float(Currency('AUDEUR').get_rate())
    eur_aud = 1 / aud_eur
Example #12
0
def jpy():
    global chf_jpy, jpy_chf, cad_jpy, jpy_cad, aud_jpy, jpy_aud, hkd_jpy, jpy_hkd, inr_jpy, jpy_inr

    chf_jpy = float(Currency('CHFJPY').get_rate())
    jpy_chf = 1 / chf_jpy

    cad_jpy = float(Currency('CADJPY').get_rate())
    jpy_cad = 1 / cad_jpy

    aud_jpy = float(Currency('AUDJPY').get_rate())
    jpy_aud = 1 / aud_jpy

    hkd_jpy = float(Currency('HKDJPY').get_rate())
    jpy_hkd = 1 / hkd_jpy

    inr_jpy = float(Currency('INRJPY').get_rate())
    jpy_inr = 1 / inr_jpy
Example #13
0
def gbp():
    global jpy_gbp, gbp_jpy, chf_gbp, gbp_chf, cad_gbp, gbp_cad, aud_gbp, gbp_aud, hkd_gbp, gbp_hkd

    jpy_gbp = float(Currency('JPYGBP').get_rate())
    gbp_jpy = 1 / jpy_gbp

    chf_gbp = float(Currency('CHFGBP').get_rate())
    gbp_chf = 1 / chf_gbp

    cad_gbp = float(Currency('CADGBP').get_rate())
    gbp_cad = 1 / cad_gbp

    aud_gbp = float(Currency('AUDGBP').get_rate())
    gbp_aud = 1 / aud_gbp

    hkd_gbp = float(Currency('HKDGBP').get_rate())
    gbp_hkd = 1 / hkd_gbp
Example #14
0
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
Example #15
0
 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
Example #16
0
def data_extraction(interval, length):
    x = []
    y = []
    eur_sek = Currency('EURSEK')
    for i in range (length):
        eur_sek.refresh()
        timestamp = datetime.datetime.now()
        rate = eur_sek.get_bid()
        print('Time: ',timestamp)
        print ('EUR-SEK: ',rate)
        print ('')
        x.append(timestamp)
        y.append(rate)
        time.sleep(interval)
    data = pd.DataFrame(x, columns=['Date'])
    data['Rate'] = y
    return data
Example #17
0
    def logPrice(self):
        prices = {}
        try:
            price = Share(name)
            type = "sh"
        except:
            price = Currency(name)
            type = "cu"
        outfile = open(str(name + '_pricelog.json'), 'a')
        starttime = time()

        if (type == 'sh'):
            price.refresh()
            dumps({name: {int(time() - starttime): price.get_price()}})

        if (type == 'cu'):
            price.refresh()
            dumps({name: {int(time() - starttime): price.get_price()}})
Example #18
0
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])
Example #19
0
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
Example #20
0
 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()
Example #21
0
 def setUp(self):
     self.eur_pln = Currency('EURPLN')
Example #22
0
from yahoo_finance import Currency
eur_sek = Currency('EURSEK')
eur_sek.refresh()
print(eur_sek.get_bid())
Example #23
0
def getExchangeRate(ccyName):
    ccy = Currency(ccyName)
    return ccy.get_rate()
Example #24
0
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
Example #25
0
from yahoo_finance import Currency

file = open("Currency_update.txt", 'r')
x = file.readlines()

for y in x:
    L = map(str, y.split())
    res = ''
    for z in L[:-1]:
        res += z + ' '
    print '%30s %s' % (res, L[-1])

first_currency = raw_input("enter first currency: ")
second_currency = raw_input("enter second currency: ")
conversion = first_currency + second_currency
eur_pln = Currency(conversion)
print eur_pln.get_bid()
Example #26
0
def get_data(symbol):
    return Currency(symbol).get_rate()
Example #27
0
def getchange(fromto='USDCNY'):
    change = Currency(fromto)
    bid = change.get_bid()
    ask = change.get_ask()
    rate = change.get_rate()
    return rate
Example #28
0
#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()
Example #29
0
from yahoo_finance import Currency
eur_pln = Currency('EURPLN')
print (eur_pln.get_bid())
Example #30
0
 def get(self):
     return float(Currency('USDRUB').get_bid())