forked from pceuropa/bitcoin-exchange
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foreign.py
47 lines (36 loc) · 1.18 KB
/
foreign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# !/usr/bin/env python3
#-*- coding:utf-8 -*-
"""
Foreign exange PLN, Euro ,USDT , BTC
"""
from urllib.request import urlopen
from json import load
from argparse import ArgumentParser
from bittrex.bittrex import Ask
def rates():
url = "http://api.fixer.io/latest?base=USD"
rates = load(urlopen(url))
return float(rates["rates"]["PLN"])
def all_rates():
url = "http://api.fixer.io/latest?base=PLN"
rates = load(urlopen(url))
return rates["rates"]
if __name__ == '__main__':
currencies = all_rates()
ask = Ask('usdt-btc')
btc = ask.marketsummary()
btc = btc["Last"]
pln_usd = 1 / currencies["USD"]
pln_eur = 1 / currencies["EUR"]
btc_pln = btc * pln_usd
print("usd:", format(pln_usd, '.2f'))
print("eur:", format(pln_eur, '.2f'))
print("btc:", format(btc_pln, '.2f'))
p = ArgumentParser()
p.add_argument("amount", help="450")
args = p.parse_args()
if args.amount:
amount = args.amount
print(amount, "usd", format(float(amount) * pln_usd, '.1f'), 'PLN')
print(amount, "eur", format(float(amount) * pln_eur, '.1f'), 'PLN')
print(amount, "btc", format(float(amount) * btc, '.1f'), 'USD')