Created
August 27, 2024 23:12
-
-
Save asluchevskiy/e786c33a4f2f14ea21b28bc2aa5c0621 to your computer and use it in GitHub Desktop.
caller.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
from loguru import logger | |
from datetime import datetime | |
from twilio.rest import Client | |
ACCOUNT_SID = '' | |
AUTH_TOKEN = '' | |
PHONE_FROM = '+12244124645' | |
PHONE_TO = '+000000000' | |
CURRENCY = 'ETH' | |
TRIGGER_PRICE = 2300 | |
def call(phone_from, phone_to): | |
client = Client(ACCOUNT_SID, AUTH_TOKEN) | |
call = client.calls.create( | |
url='http://demo.twilio.com/docs/voice.xml', | |
to=phone_to, | |
from_=phone_from, | |
) | |
return call.sid | |
def get_price(symbol: str): | |
json_data = requests.get(f'https://www.binance.com/api/v3/ticker/price?symbol={symbol.upper()}USDT').json() | |
return float(json_data['price']) | |
def main(): | |
call_was_made = False | |
while True: | |
try: | |
price = get_price(CURRENCY) | |
logger.info(f'{CURRENCY} price is {price}') | |
if price < TRIGGER_PRICE: | |
if not call_was_made: | |
logger.error('CALLING TO BOSS!!!!11') | |
call(PHONE_FROM, PHONE_TO) | |
call_was_made = True | |
else: | |
if call_was_made and price > TRIGGER_PRICE * 1.025: | |
call_was_made = False | |
except Exception as e: | |
logger.error(e) | |
time.sleep(30) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment