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
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: |
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
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 |
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
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']) |
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
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: |
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
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}" |
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 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 |
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 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 |
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
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', |