This file contains 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 cv2 | |
import numpy as np | |
# definitions | |
video_source = 0 | |
video_full = 1 | |
video_message_limit = 60 | |
camera_width = 720 | |
camera_height = 480 | |
camera_fps = 1 |
This file contains 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 requests | |
import airportsdata | |
from geopy.distance import geodesic | |
from datetime import datetime, timedelta | |
from FlightRadar24 import FlightRadar24API | |
TELEGRAM_URL = 'https://api.telegram.org' | |
TELEGRAM_BOT_ID = 'bot5603010001:III_xNHA14A9xznXjjcUD98GXT-A5zAAxzX' # Your bot | |
TELEGRAM_CHAT_ID = '-1008101011052' # Your airport reminder channel |
This file contains 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
geopy | |
airportsdata | |
FlightRadarAPI |
This file contains 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
# Main function | |
def myrmidon_trader_go(request): | |
twitter_auth = tweepy.OAuthHandler(TWITTER_API_KEY, TWITTER_API_SECRET) | |
twitter_api = tweepy.API(twitter_auth) | |
api = tradeapi.REST(TRADER_API_KEY, TRADER_API_SECRET, TRADER_API_URL) | |
account = api.get_account() | |
clock = api.get_clock() | |
if bool(account) == True: |
This file contains 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
# TRADING | |
def trade(api, stock, operation, shares_to_trade, take_profit, stop_loss): | |
api.submit_order(symbol = stock, qty = shares_to_trade, side = operation, type = 'market', | |
order_class = 'bracket', time_in_force = 'day', | |
take_profit = {'limit_price': take_profit}, | |
stop_loss = {'stop_price': stop_loss}) | |
message = f'\n\t*{stock}*, qty _{shares_to_trade}_ \n\t\twere {operation}' | |
send_message(f'{TRADER_ID}: we entered the market with:' + message) | |
return True |
This file contains 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
# ANALYSIS | |
def twitter_analysis(twitter_api, stock): | |
sentiment = {} | |
tweets = tweepy.Cursor(twitter_api.search, q=stock, lang='en').items(TWITTER_TWEETS_COUNT) | |
negative = [] | |
positive = [] | |
neutral = [] |
This file contains 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
# SCREENER | |
def screen_stock(stock): | |
data = {} | |
try: | |
df = yf.download(stock, period = SCREENER_PERIOD, interval = SCREENER_INTERVAL) | |
if (len(df) > 0): | |
df['rsi'] = ta.rsi(df['Close'], timeperiod=14) | |
bbands2 = ta.bbands(df['Close'], length = 20, std=2.2) | |
bbands3 = ta.bbands(df['Close'], length = 20, std=2.3) | |
df['L2'] = bbands2['BBL_20_2.2'] |
This file contains 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
# Send message to Telegram channel | |
def send_message(message): | |
response = req.post( | |
f'{TELEGRAM_URL}/{TELEGRAM_BOT_ID}/sendMessage?chat_id={TELEGRAM_CHAT_ID}&parse_mode=Markdown&text={message}') | |
return response |
This file contains 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
# SETTINGS | |
TRADER_ID = 'Myrmidon trading bot' | |
TRADER_API_KEY = '[API key]' | |
TRADER_API_SECRET = '[API secret]' | |
TRADER_API_URL = 'https://paper-api.alpaca.markets' | |
TELEGRAM_URL = 'https://api.telegram.org' | |
TELEGRAM_BOT_ID = 'bot0000000000:AAA_gNNN00B0xxxDaaaUD00HHH-Y0wAAmhA' # Myrmidon trading bot | |
TELEGRAM_CHAT_ID = '-1002003005001' # Myrmidon trading bot channel |
This file contains 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
!pip install alpaca_trade_api | |
!pip install yfinance | |
!pip install pandas_ta | |
!pip install tweepy==3.10.0 | |
!pip install nltk |
NewerOlder