示例#1
0
class Exchange(object):
    def __init__(self):  #, influxdb_client):
        self.fxrio = Fixerio()
        self.exchange_data = {}
        self._name = 'Exchange'
        self.baselist = {'CNY', 'USD', 'KRW'}
        self.exchange_data = {}
        for index in self.baselist:
            self.exchange_data[index] = None
        logger.info('Exchange module init')

    @property
    def name(self):
        return self._name

    def query(self, callback_func=None):
        for index in self.baselist:
            res = self.fxrio.latest(base=index)
            self.parse_exchange(index, res)
        if callback_func is not None:
            callback_func(self.exchange_data)

    def parse_exchange(self, base, data):
        #data = json.loads(jsondata)
        data_dict = {}
        for key in data['rates']:
            if key in self.baselist:
                data_dict[key] = data['rates'][key]
        self.exchange_data[base] = data_dict
示例#2
0
class Exchange(object):
    def __init__(self):  #, influxdb_client):
        self.fxrio = Fixerio()
        self.exchange_data = {}
        #self.client=influxdb_client
        #self._request_timeout = int(config.REQUEST_TIMEOUT)
        #self._price = 0.0
        self._name = 'Exchange'
        self.baselist = {'CNY', 'USD', 'KRW'}
        self.exchange_data = {}
        for index in self.baselist:
            self.exchange_data[index] = None

    @property
    def name(self):
        return self._name

    def query(self, callback_func=None):
        for index in self.baselist:
            res = self.fxrio.latest(base=index)
            self.parse_exchange(index, res)
        print(self.exchange_data)
        if callback_func is not None:
            callback_func(self.exchange_data)

    def parse_exchange(self, base, data):
        #data = json.loads(jsondata)
        data_dict = {}
        for key in data['rates']:
            if key in self.baselist:
                data_dict[key] = data['rates'][key]
        self.exchange_data[base] = data_dict
示例#3
0
def currencies(wrapper_kwargs, scraper):

    # Get data
    f = Fixerio(base='USD')
    upd = {'meta': {'currencies': f.latest().get('rates')}}

    # Save data
    return upd
示例#4
0
class ExchangeData:
    """Get the latest data and update the states."""
    def __init__(self, target_currency, api_key):
        """Initialize the data object."""
        self.api_key = api_key
        self.rate = None
        self.target_currency = target_currency
        self.exchange = Fixerio(symbols=[self.target_currency],
                                access_key=self.api_key)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
示例#5
0
class ExchangeData:
    """Get the latest data and update the states."""

    def __init__(self, target_currency, api_key):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.api_key = api_key
        self.rate = None
        self.target_currency = target_currency
        self.exchange = Fixerio(
            symbols=[self.target_currency], access_key=self.api_key)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
示例#6
0
class ExchangeData(object):
    """Get the latest data and update the states."""
    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(base=self.base_currency,
                                symbols=[self.target_currency],
                                secure=True)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
示例#7
0
class ExchangeData(object):
    """Get the latest data and update the states."""

    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(
            base=self.base_currency, symbols=[self.target_currency],
            secure=True)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
def convert_currency(base, to, amount):
    """Convert between two cryptocurrencies.

    base     str: code of base currency have to be supported by bitstamp (btc, ltc, xrp).
    to       str: code of currency into which we want to exchange have to be supported by
                  bitstamp (usd, eur) or Europen Bank
    amount float: The amount of money
    """
    assert base.lower() in ["ltc", "btc", "xrp"]

    if base.lower() in ["ltc", "xrp"] and to.lower() == "btc":
        rate = float(json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
                base=base.lower(), to=to.lower())).text)['last'])
    elif to.lower() not in ["usd", "eur"]:  # to currency is not supported by bitstamp
        response = json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
            base=base.lower(), to="usd")).text)
        fixerio = Fixerio(base="USD")  # HAVE TO BE ON SEPERATE LINE
        rate = fixerio.latest()["rates"][to.upper()] * float(response["last"])
    else:
        rate = float(json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
                base=base.lower(), to=to.lower())).text)["last"])

    return amount * rate
示例#9
0
    'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR',
    'LRD', 'LSL', 'LTL', 'LVL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK',
    'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD',
    'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP',
    'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD',
    'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'STD', 'SVC',
    'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD',
    'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST',
    'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMK', 'ZWL'
]
convertFrom = str(sys.argv[1])
ConvertTo = 'EGP'
if convertFrom in symbols:
    fxrio = Fixerio(access_key='4901a054956048d6cdbd8a55db64709b')
    Rates = fxrio.latest(symbols=[
        ConvertTo, convertFrom
    ])  #the function always returns decitonry #the base always EUR
    isConvertedTo_Rate = Rates['rates'][ConvertTo]
    ConvertedFrom_Rate = Rates['rates'][convertFrom]
    CovertedFrom_Rate_referedToBase = 1 / ConvertedFrom_Rate
    finalRate = CovertedFrom_Rate_referedToBase * isConvertedTo_Rate
    print("1 " + convertFrom + " = " + str(finalRate) + " " + ConvertTo)
    #Update the DB
    sql = "INSERT INTO RATES(rate) VALUES (%f) WHERE currency='%s'" % (
        finalRate, convertFrom)
    cur.execute(sql)
else:
    print("Wrong currency symbol!!")

#setup the DB in docker image
#write a test cases
示例#10
0
def get_usd_inr():
    current = Fixerio(base='USD', symbols=['USD', 'INR'])
    return current.latest()
示例#11
0
from fixerio import Fixerio
import pandas as pd

fxrio = Fixerio(access_key='3401cd052e4ac3a55a8a9ea215b1ea8d')
ok = fxrio.latest()
currency = pd.DataFrame(ok)
currency.to_csv('currency.csv')
import math
import re

from fixerio import Fixerio
from measurement.measures import Volume

fxrio = Fixerio(base='USD')
conversion = fxrio.latest()


def my_va_transform(s):
    """Function to transform brand
    * make lower
    * do specific regex replacements
    * remove product types ex: 'bourbon', 'whiskey'
    * sort the words in the brand
    """
    s = s.lower()

    replacements = {
        "^gentleman jack whiskey$": "jack daniel's gentleman jack",
        "^pritchard": "prichard",
        "^balcones baby blue corn whiskey$": "balcones baby blue",
        "^canadian club rye whisky$": "canadian club",
        "^catoctin creek roundstone rye whisky$":
        "catoctin creek roundstone rye",
        "^e h taylor jr. straight rye$": "colonel e.h. taylor straight rye",
        "^e h taylor seasoned wood$": "colonel e.h. taylor seasoned wood",
        "^james e. pepper 1776 rye": "james e. pepper 1776 straight rye",
        "^lock stock & barrel 16 yr straight rye whiskey$":
        "lock stock and barrel 16 straight rye",