Skip to content

Instantly share code, notes, and snippets.

View whittlem's full-sized avatar

Michael Whittle whittlem

View GitHub Profile
@whittlem
whittlem / python-flask-app_init.py
Created August 19, 2021 22:19
python-flask-app_init.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello world!"
@whittlem
whittlem / Create trading datasets in Python
Created August 12, 2021 10:50
Create trading datasets in Python
from models.PyCryptoBot import PyCryptoBot
from models.exchange.coinbase_pro import PublicAPI as CPublicAPI
from models.Trading import TechnicalAnalysis
app = PyCryptoBot(exchange='coinbasepro')
api = CPublicAPI()
df = app.getHistoricalDataChained('BTC-GBP', 3600, 5)
model = TechnicalAnalysis(df)
model.addAll()
@whittlem
whittlem / s3-to-rds-mysql
Created August 9, 2021 13:48
s3-to-rds-mysql
import json
import boto3
import botocore.config
import pymysql
client = boto3.client('s3', 'eu-west-1', config=botocore.config.Config(s3={'addressing_style':'path'}))
def lambda_handler(event, context):
bucket_name = event["Records"][0]["s3"]["bucket"]["name"]
s3_file_name = event["Records"][0]["s3"]["object"]["key"]
@whittlem
whittlem / email-to-s3-bucket
Last active August 8, 2021 23:00
Email Attachment Ingestion - email-to-s3-bucket
import json
import boto3
import email
import os
from datetime import datetime
import re
def get_timestamp():
current = datetime.now()
return(str(current.year) + '-' + str(current.month) + '-' + str(current.day) + '-' + str(current.hour) + '-' + str(current.minute) + '-' + str(current.second))
def mount_gdrive():
if not os.path.isdir('/content/gdrive'):
drive.mount('/content/gdrive')
def build():
root_dir = os.environ['GDRIVE_ROOT']
project_name = os.environ['PROJECT_NAME']
tensorflow_model = os.environ['TENSORFLOW_MODEL']
os.chdir(f'/content/gdrive/MyDrive/{root_dir}/models/research')
@whittlem
whittlem / ai-obj-detect-training-functions
Last active July 12, 2021 11:03
https://whittle.medium.com - "AI Object Detection, with Lions!"
def mount_gdrive():
if not os.path.isdir('/content/gdrive'):
drive.mount('/content/gdrive')
def create_gdrive_directory_structure():
global labels
root_dir = os.environ['GDRIVE_ROOT']
project_name = os.environ['PROJECT_NAME']
tensorflow_model = os.environ['TENSORFLOW_MODEL']
""" Sample TensorFlow XML-to-TFRecord converter
usage: generate_tfrecord.py [-h] [-x XML_DIR] [-l LABELS_PATH] [-o OUTPUT_PATH] [-i IMAGE_DIR] [-c CSV_PATH]
optional arguments:
-h, --help show this help message and exit
-x XML_DIR, --xml_dir XML_DIR
Path to the folder where the input .xml files are stored.
-l LABELS_PATH, --labels_path LABELS_PATH
Path to the labels (.pbtxt) file.
@whittlem
whittlem / matplotlib.py
Last active February 13, 2021 15:17
Technical Analysis Graphs using Python Matplotlib
import requests
from datetime import datetime
import matplotlib.pyplot as plt
def cbpGetHistoricRates(market='BTC-GBP', granularity=86400, iso8601start='', iso8601end=''):
api = 'https://api.pro.coinbase.com/products/' + market + '/candles?granularity=' + \
str(granularity) + '&start=' + iso8601start + '&end=' + iso8601end
resp = requests.get(api)
if resp.status_code != 200:
@whittlem
whittlem / sma.py
Created November 17, 2020 16:55
Trading using Python — Simple Moving Average (SMA)
# https://levelup.gitconnected.com/trading-using-python-simple-moving-average-sma-8713caf0d4ee
import requests
from datetime import datetime
# granularity: 60, 300, 900, 3600, 21600, 86400
def cbpGetHistoricRates(market='BTC-GBP', granularity=86400, iso8601start='', iso8601end=''):
api = 'https://api.pro.coinbase.com/products/' + market + '/candles?granularity=' + \
# data: dictionary { 'dd/mm/yyy': price, 'dd/mm/yyyy': price, ... }
# num: range in the average calculation, normally 9 to 26
def simpleMovingAverage(data, num):
if not isinstance(data, dict):
raise Exception('Dictionary input expected')
if not isinstance(num, int):
raise Exception('Integer input expected')
if num < 5 or num > 200: