1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2026-06-03 21:00:26 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Anson 2dd67538bb add divider 2023-10-17 05:11:13 +00:00
Anson 5d1f71e19a new blogpost 2023-10-17 05:10:59 +00:00
4 changed files with 11 additions and 34 deletions
+2
View File
@@ -1,7 +1,9 @@
stages: stages:
- lint - lint
- build
- build_site - build_site
- deploy - deploy
- deploy_site
black: black:
stage: lint stage: lint
+3 -20
View File
@@ -54,12 +54,9 @@ class MarketData:
self.get_symbol_list() self.get_symbol_list()
schedule.every().day.do(self.get_symbol_list) schedule.every().day.do(self.get_symbol_list)
def get(self, endpoint, params=None, timeout=10, headers=None) -> dict: def get(self, endpoint, params: dict = {}, timeout=10) -> dict:
url = "https://api.marketdata.app/v1/" + endpoint url = "https://api.marketdata.app/v1/" + endpoint
if params is None:
params = {}
# set token param if it wasn't passed. # set token param if it wasn't passed.
params["token"] = self.MARKETDATA_TOKEN params["token"] = self.MARKETDATA_TOKEN
@@ -67,13 +64,7 @@ class MarketData:
# monitored even if someone doesn't make it through an affiliate link. # monitored even if someone doesn't make it through an affiliate link.
params["application"] = "simplestockbot" params["application"] = "simplestockbot"
if headers is None: resp = r.get(url, params=params, timeout=timeout)
headers = {}
headers = {"User-Agent": "Simple Stock Bot anson@ansonbiggs.com"} | headers
resp = r.get(url, params=params, timeout=timeout, headers=headers)
logging.error(resp.headers.items())
# Make sure API returned a proper status code # Make sure API returned a proper status code
try: try:
@@ -104,15 +95,7 @@ class MarketData:
return self.symbol_list.get(symbol.upper(), None) return self.symbol_list.get(symbol.upper(), None)
def get_symbol_list(self): def get_symbol_list(self):
# Doesn't use `self.get`` since needs are much different sec_resp = r.get("https://www.sec.gov/files/company_tickers.json")
sec_resp = r.get(
"https://www.sec.gov/files/company_tickers.json",
headers={
"User-Agent": "Simple Stock Bot anson@ansonbiggs.com",
"Accept-Encoding": "gzip, deflate",
"Host": "www.sec.gov",
},
)
sec_resp.raise_for_status() sec_resp.raise_for_status()
sec_data = sec_resp.json() sec_data = sec_resp.json()
-8
View File
@@ -9,8 +9,6 @@ from markdownify import markdownify
from common.Symbol import Coin from common.Symbol import Coin
from common.utilities import rate_limited from common.utilities import rate_limited
import time
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -36,12 +34,6 @@ class cg_Crypto:
url = "https://api.coingecko.com/api/v3" + endpoint url = "https://api.coingecko.com/api/v3" + endpoint
resp = r.get(url, params=params, timeout=timeout) resp = r.get(url, params=params, timeout=timeout)
# Make sure API returned a proper status code # Make sure API returned a proper status code
if resp.status_code == 429:
log.warning(f"CoinGecko returned 429 - Too Many Requests for endpoint: {endpoint}. Sleeping and trying again.")
time.sleep(10)
return self.get(endpoint=endpoint, params=params, timeout=timeout)
try: try:
resp.raise_for_status() resp.raise_for_status()
except r.exceptions.HTTPError as e: except r.exceptions.HTTPError as e:
+6 -6
View File
@@ -1,7 +1,7 @@
image: python:3.11 image: python:3.11
build_mkdocs: build_site:
stage: build_site stage: build
script: script:
- cd ./site - cd ./site
- pip install -r requirements.txt - pip install -r requirements.txt
@@ -10,14 +10,14 @@ build_mkdocs:
paths: paths:
- public - public
pages: deploy_site:
stage: deploy stage: deploy
script: script:
- echo "Publishing site..." - echo "Publishing site..."
dependencies: dependencies:
- build_mkdocs - build_site
artifacts: artifacts:
paths: paths:
- public - public
# rules: rules:
# - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH" - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"