Пример #1
0
def Left_click(event):
    btc_rate = BtcConverter()
    year = int(input_year.get())
    month = int(input_month.get())
    day = int(input_day.get())
    period = int(input_forecast_period.get())  #forecast จากกี่วันย้อนหลัง
    refer_date = datetime(
        year, month, day - 2
    )  #Current date ใส่ -2 เนื่องจากไม่สามารถดึงราคาปัจจุบันได้ bitcoin price deley 2 day
    sum_previous_price = 0
    for i in range(period):
        date = refer_date - timedelta(days=i)
        previous_price = btc_rate.get_previous_price('THB', date)
        sum_previous_price += previous_price
    sample_moving_average = sum_previous_price / period
    result.configure(text=sample_moving_average)
Пример #2
0
class TestBitCoinForceDecimal(TestCase):
    def setUp(self):
        self.b = BtcConverter(force_decimal=True)

    def test_latest_price_valid_currency(self):
        price = self.b.get_latest_price('USD')
        self.assertEqual(type(price), Decimal)

    def test_latest_price_invalid_currency(self):
        price = self.b.get_latest_price('XYZ')
        self.assertFalse(price)

    def test_previous_price_valid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        price = self.b.get_previous_price('USD', date_obj)
        self.assertEqual(type(price), Decimal)

    def test_previous_price_invalid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        self.assertRaises(RatesNotAvailableError, self.b.get_previous_price,
                          'XYZ', date_obj)

    def test_previous_price_list_with_valid_currency(self):
        start_date = datetime.datetime.today() - datetime.timedelta(days=15)
        end_date = datetime.datetime.today()
        price_list = self.b.get_previous_price_list('USD', start_date,
                                                    end_date)
        self.assertTrue(price_list)
        self.assertEqual(type(price_list), dict)

    def test_previous_price_list_with_invalid_currency(self):
        start_date = datetime.datetime.today() - datetime.timedelta(days=15)
        end_date = datetime.datetime.today()
        price_list = self.b.get_previous_price_list('XYZ', start_date,
                                                    end_date)
        self.assertFalse(price_list)
        self.assertEqual(type(price_list), dict)

    def test_convet_to_btc_with_valid_currency(self):
        coins = self.b.convert_to_btc(Decimal('250'), 'USD')
        self.assertEqual(type(coins), Decimal)

    def test_convet_to_btc_with_invalid_currency(self):
        self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc,
                          Decimal('250'), 'XYZ')

    def test_convert_btc_to_cur_valid_currency(self):
        amount = self.b.convert_btc_to_cur(Decimal('2'), 'USD')
        self.assertEqual(type(amount), Decimal)

    def test_convert_btc_to_cur_invalid_currency(self):
        self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur,
                          Decimal('250'), 'XYZ')

    def test_convert_to_btc_on_with_valid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        coins = self.b.convert_to_btc_on(Decimal('300'), 'USD', date_obj)
        self.assertEqual(type(coins), Decimal)

    def test_convert_to_btc_on_with_invalid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc_on,
                          Decimal('250'), 'XYZ', date_obj)

    def test_convert_to_btc_on_with_valid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        amount = self.b.convert_btc_to_cur_on(Decimal('250'), 'USD', date_obj)
        self.assertEqual(type(amount), Decimal)

    def test_convert_to_btc_on_with_invalid_currency(self):
        date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
        self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur_on,
                          Decimal('3'), 'XYZ', date_obj)
Пример #3
0
from forex_python.bitcoin import BtcConverter
import datetime,decimal

avg_bitcoin = 0
sum = 0
b = BtcConverter()

usernameinput = input("username : "******"password : "******"admin" and passwordinput == "1234":
    for i in range(1, 31):
        date_obj = datetime.datetime(2020, 4, i)
        sum += b.get_previous_price('THB', date_obj)

    avg_bitcoin = sum / 30
    txt = "Bitcoin Average in Apirl 2020 is {:.2f}"
    print(txt.format(avg_bitcoin))
else:
    print("Wrong Username or Password!")
Пример #4
0
print('\n' + from_currency + " To " + to_currency, amount)
print('The current conversion rate for {} to {} is {}'.format(from_currency, to_currency, c.get_rate(from_currency, to_currency)))    #Get conversion rate from USD to INR
result = c.convert(from_currency, to_currency, amount)   #Convert the amount
print('Latest Conversion: ',result)

#Get conversion rate as of 2021-01-01
print('\nThe conversion rate from {} to {} as per 1st Jan 2021 is {}'.format(from_currency, to_currency, c.get_rate(from_currency, to_currency, date_obj)))
print('The conversion as per 1st Jan 2021: ', c.convert(from_currency, to_currency, amount, date_obj))

b = BtcConverter()
print('\n\nBitcoin Symbol: ', b.get_symbol())  # get_btc_symbol()
print('Bitcoin Latest Price in USD : ', b.get_latest_price('USD'))     #Get latest Bitcoin price.
print('Convert 10 Million USD to Bitcoin', b.convert_to_btc(10000000, 'USD'))     #Convert Amount to Bitcoins based on latest exchange price.
print('The Equivalent of 10.99 Bitcoin in USD: ',b.convert_btc_to_cur(10.99, 'USD'))         #Convert Bitcoins to valid currency amount based on lates price

print('\nBitcoin price as per 1st Jan 2021: ',b.get_previous_price('USD', date_obj)) #Get price of Bitcoin based on prevois date
print('The conversion of 10 Million Dollars to Bitcoin as of 1st Jan 2021',b.convert_to_btc_on(10000000, 'USD', date_obj))      #Convert Amount to bitcoins based on previous date prices
print('The conversion of 10.99 Bitcoin in USD as of 1st Jan 2021: ',b.convert_btc_to_cur_on(10.99, 'USD', date_obj))       #Convert Bitcoins to valid currency amount based on previous date price

start_date = datetime.datetime(2021, 2, 1, 19, 39, 36, 815417)
end_date = datetime.datetime(2021, 2, 7, 19, 39, 36, 815417)
print('\nBitcoin rates over the week in USD: ',b.get_previous_price_list('USD', start_date, end_date))         #Get list of prices list for given date range

d = CurrencyCodes()
print('\nUS Dollar Symbol:', d.get_symbol('USD'))          #Get currency symbol using currency code
print(d.get_currency_name('USD'))          #Get Currency Name using currency code

print('\nThe latest rate of USD for various currencies\n', c.get_rates('USD'))          #list all latest currency rates for "USD"
print('\nThe rate of USD for various currencies as per 1st Jan 2021\n',c.get_rates('USD', date_obj))             #List all Currency rates for “USD” on 2021-01-01
list_year = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
list_x = []
list_y = []
dic_month = {1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "August", 9: "September", 10: "October", 11: "November", 12: "December"}
b = BtcConverter()
month = 0
sum_xx = 0
sum_xy = 0
sum_x = 0
sum_y = 0
n = 0
for y in range(len(list_year)):
    for m in range(12):
        month += 1
        date_obj = datetime.datetime(list_year[y], m+1, 1, 18, 36, 28, 151012)
        list_y.append(b.get_previous_price('THB', date_obj))
        list_x.append(month)
for i in range(len(list_x)):
    sum_xy += list_x[i]*list_y[i]
    sum_x += list_x[i]
    sum_y += list_y[i]
    sum_xx += list_x[i]*list_x[i]
    n += 1
mean_x = sum_x / (i + 1)
mean_y = sum_y / (i + 1)
b_1 = (sum_xy-(sum_x*sum_y/n)) / (sum_xx-(n*mean_x*mean_x))
b_0 = mean_y - b_1*mean_x
m_bool = False
y_bool = False
while m_bool is False:
    rg_month = int(input("Please Select The Number of Month (1-12) : "))
Пример #6
0
#Project 1.1 - Bitcoin Currency Converter

#Imports
from forex_python.bitcoin import BtcConverter
from datetime import datetime

#date_obj = datetime.datetime(2021,3,9,16,40,0,815417)
current_day = int(datetime.now().strftime('%d'))

if current_day > 1:
    day = current_day - 1

date_obj = datetime.now().strftime("%Y-%m-" + str(day) + " %H:%M:%S.%f")
#2018-05-18 19:39:36.815417
date = datetime.strptime(date_obj, '%Y-%m-%d %H:%M:%S.%f')
c = BtcConverter()

#Input
amount = int(input("Enter the amount for converter: "))
currency = input("Enter the currency: ").upper()
result = c.convert_to_btc(amount, currency)

#Output
print(result)
print("\nThe price of 1 bitcoin in " + str(date) + " in " + currency +
      " was " + str(c.get_previous_price(currency, date)))
Пример #7
0
        update_prices(t)

    print("Finished updating assets")


#########################################################
# Crypto Variables and Date times
#########################################################
CRYPTO_DAILY = (datetime.now() - timedelta(2))
CRYPTO_WEEKLY = (datetime.now() - timedelta(7))
CRYPTO_MONTHLY = (datetime.now() - timedelta(30))
CRYPTO_ANNUAL = (datetime.now() - timedelta(365))

# .get_previous_price() only takes a date object
btc_price = b.get_latest_price('USD')
btc_daily_price = b.get_previous_price('USD', CRYPTO_DAILY)
btc_weekly_price = b.get_previous_price('USD', CRYPTO_WEEKLY)
btc_monthly_price = b.get_previous_price('USD', CRYPTO_MONTHLY)
btc_annual_price = b.get_previous_price('USD', CRYPTO_ANNUAL)


def update_crypto(crypto):
    """Add crypto data to database"""

    btc = Asset.query.get(crypto)

    if btc:
        btc.price = btc_price
        btc.daily_price_change = float(btc_price - btc_daily_price)
        btc.daily_perc_change = percent_change(btc_price, btc_daily_price)
        btc.weekly_perc_change = percent_change(btc_price, btc_weekly_price)
Пример #8
0
b = BtcConverter()
Mainwindow = Tk()

###Timedates###
today = datetime.date.today()
today_withtime = datetime.datetime.today()
lastweek = today - datetime.timedelta(weeks=1)
two_weeks_ago = lastweek - datetime.timedelta(weeks=1)
three_weeks_ago = two_weeks_ago - datetime.timedelta(weeks=1)
four_weeks_ago = three_weeks_ago - datetime.timedelta(weeks=1)
five_weeks_ago = four_weeks_ago - datetime.timedelta(weeks=1)

###Btc Price previous time###
today_btc_price = b.get_latest_price('USD')
today_btc_price_2 = round(today_btc_price, 2)
lastweek_btc_price = b.get_previous_price('USD', lastweek)
lastweek_btc_price_2 = round(lastweek_btc_price, 2)
twoweeksago_btc_price = b.get_previous_price('USD', two_weeks_ago)
twoweeksago_btc_price_2 = round(twoweeksago_btc_price, 2)
threeweeksago_btc_price = b.get_previous_price('USD', three_weeks_ago)
threeweeksago_btc_price_2 = round(threeweeksago_btc_price, 2)
fourweeksago_btc_price = b.get_previous_price('USD', four_weeks_ago)
fourweeksago_btc_price_2 = round(fourweeksago_btc_price, 2)
fiveweeksago_btc_price = b.get_previous_price('USD', five_weeks_ago)

###Btc Price now in main menu###
change = ((today_btc_price - lastweek_btc_price) / today_btc_price) * 100
percen = round(change, 2)
if change > 0:
    text = ' ▲ ' + str(percen) + "%"
elif change < 0:
Пример #9
0
#it's not work
from forex_python.converter import CurrencyCodes, CurrencyRates

from forex_python.bitcoin import BtcConverter

test = CurrencyCodes()
cur_symbol = test.get_symbol('INR')
cur_name = test.get_currency_name('INR')
print('The currence name is: ' + cur_name)
print('The currence symbol is: ' + cur_symbol)
print('\n' + test.get_currency_name('USD'))
print(test.get_symbol('USD'))

test1 = CurrencyRates
rate = test1.get_rate('USD', 'INR')
# print(rate)

res = test1.convert('USD','INR',10)
#print(res)
print('===================')
bitcoin = BtcConverter()
price = bitcoin.get_previous_price('INR')
print(price)