commit 0418e6f16d2ad4c7a6fe5ead5485aec627dbc7c6 Author: jwinterm Date: Mon Feb 2 22:37:03 2015 -0600 Initial commit 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 0000000..fd6c43d Binary files /dev/null and b/favicon.ico differ diff --git a/getStampTicker.py b/getStampTicker.py new file mode 100644 index 0000000..07324a8 --- /dev/null +++ b/getStampTicker.py @@ -0,0 +1,29 @@ +import requests +import json + +# Set URL for bitstamp ticker info +URL = 'https://www.bitstamp.net/api/ticker/' +# Headers, because headers +headers = {'content-type': 'application/json'} + + +def GetTicker(serverURL=URL): + """Try and get last block info and return formatted text""" + # print('Attempting {0} RPC call'.format(CheckLastBlock.__name__)) + try: + resp = requests.get(serverURL, headers=headers) + output = json.loads(resp.text) + print(output) + last_price = float(output[u'last']) + time_stamp = int(output[u'timestamp']) + return last_price, time_stamp + + + except: + #Return out of sync if bitmonerod is not ready + message = "error" + return message, message + + +if __name__ == "__main__": + GetTicker() \ No newline at end of file