Skip to content

Instantly share code, notes, and snippets.

View McKlayne's full-sized avatar
🎯
Focusing

McKlayne Marshall McKlayne

🎯
Focusing
View GitHub Profile
import pandas as pd
import matplotlib.pyplot as plt
import pytz
import datetime as dt
from datetime import date
import streamlit as st
#st.set_option('deprecation.showPyplotGlobalUse', False)
import numpy as np
import os
import alpaca_trade_api as tradeapi
import os
import alpaca_trade_api as tradeapi
import requests
api_key = 'your_api_key'
api_secret = 'your_api_secret'
os.environ["APCA_API_BASE_URL"] = "https://paper-api.alpaca.markets"
api = tradeapi.REST(api_key, api_secret, api_version='v2') # or use ENV Vars shown below
#portfolio of stocks
symbols = ['FB','AMZN','AAPL','NFLX','GOOG']
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
import requests
endpoint = 'https://paper-api.alpaca.markets/v2/orders'
order = {
"symbol":symbol,
"notional":amount,
"side":side,
"type":"market",
"time_in_force":"day"
}
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',
@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
@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
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}"
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:
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'])