├── .gitignore ├── LICENSE ├── README.md ├── bit_notify ├── __init__.py ├── notifier.py └── sms │ ├── __init__.py │ └── sms_client.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 hthompson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bit-notify 2 | SMS notifier for bittrex 3 | 4 | ## Installation 5 | ``` 6 | $ pip install bit-notify 7 | ``` 8 | 9 | ### Install from source 10 | ``` 11 | $ git clone https://github.com/hthompson6/bit-notify.git 12 | $ cd bit-notify 13 | $ python setup.py install -e . 14 | ``` 15 | 16 | ## Usage 17 | Please note that this service relies on Twilio. To sign up for Twilio please 18 | visit https://www.twilio.com/try-twilio. 19 | 20 | ```python 21 | api_key = 'my_bittrex_api_key' 22 | api_sign = 'my_bittrex_api_secret' 23 | account_sid = 'my_twilio_account_sid' 24 | auth_token = 'my_twilio_auth_token' 25 | sender = '' 26 | reciever = '' 27 | 28 | notify = Notifier(api_key, api_sign, account_sid, auth_token, sender, reciever) 29 | notify.start() 30 | 31 | notify.kill_thread() 32 | ``` 33 | 34 | ### Advanced Usage 35 | Notifications occur when the percent change over a 24hr span of time 36 | lies outside of the given threshold. (Updates to this percentage are 37 | checked every 30 minutes.) 38 | 39 | The default is as follows: **-100% < %change < 100%** 40 | 41 | To alter the threshold simply modify the class instantiation: 42 | ```python 43 | notify = Notifier(api_key, api_sign, account_sid, auth_token, 44 | sender, reciever, lower_bound=-15, upper_bound=50) 45 | notify.start() 46 | ``` 47 | -------------------------------------------------------------------------------- /bit_notify/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hthompson6/bit-notify/60e6ab9a4946f0663cbce652b6381f92608577d3/bit_notify/__init__.py -------------------------------------------------------------------------------- /bit_notify/notifier.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2017 Hunter Thompson 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import time 24 | from threading import Thread 25 | 26 | from bit_bind.api.bind import BittrexAPIBind 27 | from sms.sms_client import SMSClient 28 | 29 | class Notifier(Thread): 30 | 31 | def __init__(self, api_key, api_sign, account_sid, auth_token, 32 | sender, reciever, lower_bound=-100, upper_bound=100): 33 | 34 | self.bit_api = BittrexAPIBind(api_key, api_sign) 35 | self.client = SMSClient(account_sid, auth_token, sender, reciever) 36 | self.lower_bound = lower_bound 37 | self.upper_bound = upper_bound 38 | self.KILLFLAG = 0 39 | 40 | super(Notifier, self).__init__() 41 | 42 | def _compute_percentage(self, currency_base, currency_market): 43 | prevDay, last = self.bit_api.get_market_summary(currency_base, 44 | currency_market) 45 | 46 | return (float((last-prevDay))/float(prevDay)) * 100 47 | 48 | def push_notification(self, updates): 49 | msg = "" 50 | for update in updates: 51 | msg += ('{}\n').format(updates) 52 | 53 | self.client.message_create(msg) 54 | 55 | def kill_thread(self): 56 | self.KILLFLAG = 1 57 | 58 | def run(self): 59 | while not self.KILLFLAG: 60 | wallet = self.bit_api.get_balances() 61 | updates = [] 62 | for currency in wallet: 63 | percentage = self._compute_percentage('btc', 64 | currency.get('Currency').lower()) 65 | if percentage < self.lower_bound: 66 | msg = ('{}-{} has fallen by {}').format('btc', currency.get('Currency').lower(), percentage) 67 | updates.append(msg) 68 | elif percentage > self.upper_bound: 69 | msg = ('{}-{} has risen by {}').format('btc', currency.get('Currency').lower(), percentage) 70 | updates.append(msg) 71 | if updates: 72 | self.push_notification(updates) 73 | 74 | time.sleep(180) 75 | -------------------------------------------------------------------------------- /bit_notify/sms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hthompson6/bit-notify/60e6ab9a4946f0663cbce652b6381f92608577d3/bit_notify/sms/__init__.py -------------------------------------------------------------------------------- /bit_notify/sms/sms_client.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2017 Hunter Thompson 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | #SOFTWARE. 22 | 23 | from twilio.rest import Client 24 | 25 | class SMSClient(object): 26 | 27 | def __init__(self, account_sid, auth_token, sender, reciever): 28 | self.account_sid = account_sid 29 | self.auth_token = auth_token 30 | self.sender = sender 31 | self.reciever = reciever 32 | 33 | def _get_client(self): 34 | return Client(self.account_sid, self.auth_token) 35 | 36 | def message_create(self, body): 37 | client = self._get_client() 38 | client.messages.create( 39 | to=str(self.sender), 40 | from_=str(self.reciever), 41 | body=body) 42 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | twilio>=6.4.2 2 | bit-bind>=0.0.1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # flake8: noqa 3 | 4 | from setuptools import setup, find_packages 5 | 6 | setup( 7 | name = "bit-notify", 8 | version = "0.1.2", 9 | packages = find_packages(), 10 | 11 | author = "Hunter Thompson", 12 | author_email = "thompson.grey.hunter@gmail.com", 13 | description = "Bittrex SMS Notifier", 14 | license = "MIT", 15 | keywords = "sms bittrex", 16 | url = "https://github.com/hthompson6/bit-notifier", 17 | 18 | long_description = open('README.md').read(), 19 | classifiers = [ 20 | 'Programming Language :: Python', 21 | 'Programming Language :: Python :: 2.7', 22 | 'Operating System :: OS Independent', 23 | 'License :: OSI Approved :: MIT License', 24 | 'Development Status :: 3 - Alpha', 25 | ], 26 | install_requires=['twilio>=6.4.2','bit-bind>=0.1.0'] 27 | ) 28 | --------------------------------------------------------------------------------