Skip to content

Instantly share code, notes, and snippets.

View McKlayne's full-sized avatar
🎯
Focusing

McKlayne Marshall McKlayne

🎯
Focusing
View GitHub Profile
def get_coingecko_data(crypto_ids, crypto_abbreviations):
# define the base url and another piece that will be added later
base = 'https://api.coingecko.com/api/v3/simple/price?ids='
vs_currencies_string= '&vs_currencies='
# determine the number of ids in the list. This will help us know how many commas to add to the url
id_remaining = len(crypto_ids)
# loop through each coin and append its id to the url. Decrease id_remaining each iteration, add a comma to the url if it is needed
for coin in crypto_ids:
def define_edges(crypto_ids, crypto_abbreviations, crypto_data):
# initialize the graph and an empty list for edges
graph = nx.DiGraph()
edges = []
# define all edges and add to graph
for coin1 in crypto_ids:
for coin2 in crypto_ids:
if coin1 != coin2:
# find the index of coin1 and coin2 in the ids list. Use those values to get the abbreviations
def arbitrage_scan(graph):
arb_checks = []
for c1, c2 in combinations(graph.nodes, 2):
# print('paths from ', c1, 'to ', c2)
for path in nx.all_simple_paths(graph, c1, c2):
path_weight1 = 1
for i in range(len(path) - 1):
# print(g[path[i]][path[i+1]]['weight'])
from io import BytesIO
import requests
import time
import pandas as pd
def earnings_calendar_api(api_key, horizon, symbol=None):
if symbol is not None:
url = f'{BASE_URL}function=EARNINGS_CALENDAR&symbol={symbol}&horizon={horizon}&apikey={api_key}'
response = requests.get(url)
else:
from io import BytesIO
import requests
import time
import pandas as pd
def earnings_history_api(api_key, symbol):
assert symbol is not None
symbol = symbol.strip().upper()
url = f"{BASE_URL}function=EARNINGS&symbol={symbol}&apikey={api_key}"
@McKlayne
McKlayne / ma_app.py
Last active February 12, 2022 22:38
#import packages
import streamlit as st
import os
import alpaca_trade_api as tradeapi
import pandas as pd
import matplotlib.pyplot as plt
import requests
import math
from termcolor import colored as cl
import numpy as np
@McKlayne
McKlayne / top_mover_database_lambda.py
Created August 15, 2021 02:19
top_mover_database_lambda.py
import json
import pandas as pd
from datetime import datetime
import pytz
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
os.environ["APCA_API_BASE_URL"] = "https://paper-api.alpaca.markets"
api = tradeapi.REST('{YOUR_ALPACA_API_KEY}','{YOUR_ALPACA_KEY_SECRET}', api_version='v2')
for ticker in top_movers.ticker.head(10):
try:
# Submit a market order to buy an amount of each ticker that was pulled from the top mover list
api.submit_order(
symbol=ticker,
qty=1,
side='buy',
import requests
endpoint = 'https://paper-api.alpaca.markets/v2/orders'
order = {
"symbol":symbol,
"notional":amount,
"side":side,
"type":"market",
"time_in_force":"day"
}
def fractional_shares_order(symbol, side, notional, amount, api_key, api_secret, endpoint):
"""
A function to programatically purchase fractional shares leveraging the alpaca api
Parameters
----------
symbol : str, required
side: str, 'buy' or "sell"
notional: boolean, if True = notional, if False = fractional of a qty
amount: str, If notional is true, a dollar amount. If notional is false, a fraction of a qty