From 0418e6f16d2ad4c7a6fe5ead5485aec627dbc7c6 Mon Sep 17 00:00:00 2001 From: jwinterm Date: Mon, 2 Feb 2015 22:37:03 -0600 Subject: [PATCH] Initial commit --- README.md | 9 ++++ btcTicker.kv | 107 ++++++++++++++++++++++++++++++++++++++++++++++ btcTicker.py | 69 ++++++++++++++++++++++++++++++ favicon.ico | Bin 0 -> 1406 bytes getStampTicker.py | 29 +++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 README.md create mode 100644 btcTicker.kv create mode 100644 btcTicker.py create mode 100644 favicon.ico create mode 100644 getStampTicker.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..6edfdb2 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +#Overview + +This script checks the price of USD/BTC from Bitstamp by API every three seconds. +The user can input selected amounts of BTC and USD, and a chosen multiplier. +The program then multiplies the selected amounts according to: + +Multiplied USD = BTC input * last USD/BTC * chosen multiplier +Multiplied BTC = USD input / (last USD/BTC * chosen multiplier) + diff --git a/btcTicker.kv b/btcTicker.kv new file mode 100644 index 0000000..38a0626 --- /dev/null +++ b/btcTicker.kv @@ -0,0 +1,107 @@ +#:kivy 1.8.0 + +: + btc_multiplier_input: btc_multiplier_input + btc_amount_input: btc_amount_input + multiplied_usd_amount_input: multiplied_usd_amount_input + usd_amount_input: usd_amount_input + multiplied_btc_amount_input: multiplied_btc_amount_input + last_updated_text: last_updated_text + id: root_widget + orientation: "vertical" + + BigLabel: + text: "[b]BTC/USD Converter[/b]" + halign: "center" + color: 1, 1, 1, 1 + size_hint_x: 1 + font_size: 60 + + BoxLayout: + padding: 100, 0, 150, 0 + orientation: "horizontal" + BigLabel: + text: "BTC multiplier" + BigTextInput: + id: btc_multiplier_input + text: "0.95" + Label: + size_hint_y: 0.1 + + BoxLayout: + padding: 100, 0, 150, 0 + orientation: "horizontal" + BigLabel: + text: "BTC amount" + BigTextInput: + id: btc_amount_input + text: "1.0" + + BoxLayout: + padding: 100, 0, 150, 0 + orientation: "horizontal" + BigLabel: + text: "Multiplied USD amount" + BigTextInput: + id: multiplied_usd_amount_input + text: "0.0" + background_color: 1, 0.3, 0.3, 1 + + Label: + size_hint_y: 0.1 + + BoxLayout: + padding: 100, 0, 150, 0 + orientation: "horizontal" + BigLabel: + text: "USD amount" + BigTextInput: + id: usd_amount_input + text: "100.0" + + BoxLayout: + padding: 100, 0, 150, 0 + orientation: "horizontal" + BigLabel: + text: "Multiplied BTC amount" + BigTextInput: + id: multiplied_btc_amount_input + text: "0.0" + background_color: 1, 0.3, 0.3, 1 + + BigLabel: + id: last_updated_text + text: "Last updated from Bitstamp @ \nLast price (USD/BTC) was " + halign: "center" + size_hint_x: 1 + color: 1, 1, 1, 1 + + BigLabel: + text: "[color=#ff0000]*Fields highlighted in red are the ones being affected by multiplier[/color]" + halign: "center" + size_hint_x: 1 + font_size: 12 + padding: 0, 0 + size_hint_y: 0.1 + + + font_size: 24 + #padding: 20, 20 + valign: "middle" + halign: "right" + color: 0, 1, 1, 1 + #size_hint_y: 0.2 + size_hint_x: 0.4 + markup: True + + + + font_size: 24 + padding: 30, 26 + valign: "middle" + halign: "center" + #color: 0, 1, 1, 1 + #size_hint_y: 0.2 + multiline: False + size_hint_x: 0.2 + markup: True \ No newline at end of file diff --git a/btcTicker.py b/btcTicker.py new file mode 100644 index 0000000..67fec75 --- /dev/null +++ b/btcTicker.py @@ -0,0 +1,69 @@ +# !/usr/bin/python +from kivy.app import App +from kivy.config import Config +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.label import Label +from kivy.properties import ObjectProperty +from kivy.uix.textinput import TextInput +from kivy.clock import Clock + +import datetime +import time + +from getStampTicker import GetTicker + +class BigLabel(Label): + """ Big label class """ + def __init__(self, *args, **kwargs): + super(BigLabel, self).__init__(*args, **kwargs) + + +class BigTextInput(TextInput): + """ Big label class """ + def __init__(self, *args, **kwargs): + super(BigTextInput, self).__init__(*args, **kwargs) + + +class RootWidget(BoxLayout): + """Root Kivy accordion widget class""" + btc_multiplier_input = ObjectProperty() + btc_amount_input = ObjectProperty() + multiplied_btc_amount_input = ObjectProperty() + usd_amount_input = ObjectProperty() + multiplied_usd_amount_input = ObjectProperty() + last_updated_text = ObjectProperty() + + def __init__(self, **kwargs): + super(RootWidget, self).__init__(**kwargs) + self.last_BTCUSD_price = 0.0 + self.last_time_checked = 0 + Clock.schedule_once(self.checkTicker, 0.1) + Clock.schedule_interval(self.checkTicker, 3) + + def checkTicker(self, dt): + self.last_BTCUSD_price, self.last_time_checked = GetTicker() + print(self.last_BTCUSD_price, self.last_time_checked) + try: + temp_time = time.strftime('%H:%M:%S', time.localtime(self.last_time_checked)) + self.last_updated_text.text = "Last updated from Bitstamp @ [color=00ff00]{0}[/color]\nLast price (USD/BTC) was [color=ffff00]{1:0.2f}[/color] $/BTC".format(temp_time, self.last_BTCUSD_price) + self.multiplied_usd_amount_input.text = "{0:.2f}".format(float(self.btc_amount_input.text)*float(self.last_BTCUSD_price)*float(self.btc_multiplier_input.text)) + self.multiplied_btc_amount_input.text = "{0:.3f}".format(float(self.usd_amount_input.text)/(float(self.last_BTCUSD_price)*float(self.btc_multiplier_input.text))) + except: + print("updated FAILED") + + + + +class btcTickerApp(App): + def build(self): + root = RootWidget() + return root + + +if __name__ == '__main__': + Config.set('kivy', 'exit_on_escape', 0) + Config.set('kivy', 'window_icon', "./favicon.ico") + Config.set('input', 'mouse', 'mouse,disable_multitouch') + btcTickerApp().run() + + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..fd6c43d1542817ee95a5cfaf2093d95d077fb890 GIT binary patch literal 1406 zcmeHDyKli!6#i7H_NOgKZ3y^qR}WuqY+##7gDJdve_(}%_cgX z4hn?=hQlGuW;4d)G2Cu9DwPTXfdF#39Kzu+tX3;ptrq(IKJ7+E^Mz{h z4TC$ea#4Rwj?Uy78KInEG{R>V_fa8zCqy+pzvpg|LuOa2KDnOP?>rFx?#r86zPMi_ s<4DC~a