Skip to content

Commit

Permalink
Keep EUR as default pivot, allow to pivot on any currency
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Apr 4, 2019
1 parent 1ff0995 commit e09d6f3
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions arbitrage/fiatconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,25 @@ class FiatConverter:
rate_exchange_url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"

def __init__(self):
"""USD is used as pivot"""
self.__dict__ = self.__shared_state
self.rates = {
"USD": 1,
"EUR": 0.77,
"CNY": 6.15,
"SEK": 6.6,
}
self.rates = {}
self.update_delay = 60 * 60 * 6 # every 6 hours
self.last_update = 0
self.bank_fee = 0.007 # TODO: bank fee
self.handler = XmlHandler()

def make_USD_pivot(self, rates):
USDEUR = 1.0 / rates['USD']
rates['EUR'] = USDEUR
def change_pivot(self, rates, pivot):
PVTEUR = 1.0 / rates[pivot]
for k in rates:
rates[k] = rates[k] * USDEUR
rates[k] = rates[k] * PVTEUR
return rates

def update_pairs(self):
url = self.rate_exchange_url
res = urllib.request.urlopen(url)
xml.sax.parseString(res.read().decode('utf8'), self.handler)
self.rates = self.make_USD_pivot(self.handler.rates)
xml.sax.parseString(res.read().decode("utf8"), self.handler)
self.rates = self.handler.rates
self.rates["EUR"] = 1

def update(self):
timediff = time.time() - self.last_update
Expand All @@ -71,7 +65,7 @@ def convert(self, price, code_from, code_to):

if __name__ == "__main__":
fc = FiatConverter()
print(fc.convert(12., "USD", "EUR"))
print(fc.convert(12., "EUR", "USD"))
print(fc.convert(fc.convert(12., "EUR", "USD"), "USD", "EUR"))
print(fc.convert(12.0, "USD", "EUR"))
print(fc.convert(12.0, "EUR", "USD"))
print(fc.convert(fc.convert(12.0, "EUR", "USD"), "USD", "EUR"))
print(fc.rates)

0 comments on commit e09d6f3

Please sign in to comment.