Skip to content

Instantly share code, notes, and snippets.

View 2018kguo's full-sized avatar
🦎
whats up

Kevin Guo 2018kguo

🦎
whats up
View GitHub Profile
@2018kguo
2018kguo / RobinhoodEx1
Last active June 27, 2020 22:19
Get Robinhood portfolio and watchlist symbols
import robin_stocks as r
#Log in to Robinhood
#Put your username and password in a config.py file in the same directory (see sample file)
login = r.login(rh_username,rh_password)
def get_watchlist_symbols():
"""
Returns: the symbol for each stock in your watchlist as a list of strings
"""
def get_last_crossing(df, days, symbol="", direction=""):
"""Searches for a crossing between two indicators for a given stock
Args:
df(pandas.core.frame.DataFrame): Pandas dataframe with columns containing the stock's prices, both indicators, and the dates
days(int): Specifies the maximum number of days that the cross can occur by
symbol(str): Symbol of the stock we're querying. Optional, used for printing purposes
direction(str): "above" if we are searching for an upwards cross, "below" if we are searching for a downwaords cross. Optional, used for printing purposes
Returns:
1 if the short-term indicator crosses above the long-term one
0 if there is no cross between the indicators
def sell_holdings(symbol, holdings_data):
""" Place an order to sell all holdings of a stock.
Args:
symbol(str): Symbol of the stock we want to sell
holdings_data(dict): dict obtained from get_modified_holdings() method
"""
shares_owned = int(float(positions_data[symbol].get("quantity")))
r.order_sell_market(symbol, shares_owned)
print("####### Selling " + str(shares_owned) + " shares of " + symbol + " #######")
def buy_holdings(potential_buys, profile_data, holdings_data):
""" Places orders to buy holdings of stocks. This method will try to order
an appropriate amount of shares such that your holdings of the stock will
roughly match the average for the rest of your portfoilio. If the share
price is too high considering the rest of your holdings and the amount of
buying power in your account, it will not order any shares.
Args:
potential_buys(list): List of strings, the strings are the symbols of stocks we want to buy
symbol(str): Symbol of the stock we want to sell
@2018kguo
2018kguo / index.html
Created March 16, 2020 19:16
YzXLjoy
<style>
/*!
* Bootstrap v4.3.1 (https://getbootstrap.com/)
* Copyright 2011-2019 The Bootstrap Authors
* Copyright 2011-2019 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
#test1 {
width: 45vw;
}
@2018kguo
2018kguo / main.yml
Last active March 15, 2021 12:19
Workflow to deploy Gatsby site to GitHub Pages w/ Google Analytics
# This workflow to automatically build and deploy to GitHub Pages (master branch)
# when code is pushed to the dev branch
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the dev branch
push:
branches: [ dev ]
plugins: [
{
resolve: `gatsby-plugin-gtag`,
options: {
// your google analytics tracking id
trackingId: process.env.GOOGLE_ANALYTICS_ID,
// Puts tracking script in the head instead of the body
head: false,
// enable ip anonymization
anonymize: true,
@2018kguo
2018kguo / Social.mdx
Created March 15, 2021 13:38
Sample MDX file
@2018kguo
2018kguo / config.yaml
Last active April 18, 2021 19:27
Web scraper config
github:
enabled: true
repoURL: "https://github.com/pittcsc/Summer2022-Internships"
linkedIn:
enabled: true
timespan: "day"
queries:
- "software engineer intern"
- "software engineering internship"
- "software development intern"
@2018kguo
2018kguo / aiohttp.py
Created April 18, 2021 19:23
web scraper aiohttp example
async def fetchHTML(self, url: str, session: ClientSession) -> str:
resp = await session.request(method="GET", url=url)
html = await resp.text()
if(len(html) == 0):
print("Hit rate limit for LinkedIn requests")
return html
async def gatherTopLevelSearchForLocations(self) -> List[str]:
htmlList = []
async with aiohttp.ClientSession() as session: