Skip to content

Commit

Permalink
add historical shares into db
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jun 9, 2024
1 parent 44a64c3 commit 457db2a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
10 changes: 5 additions & 5 deletions app/create_stock_db.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import aiohttp
import asyncio
import sqlite3
import certifi
import json
import ujson
import pandas as pd
import os
from tqdm import tqdm
import re
import pandas as pd
from datetime import datetime
from ta.utils import *
from ta.volatility import *
from ta.momentum import *
from ta.trend import *
from ta.volume import *
import subprocess
import time
import warnings

from dotenv import load_dotenv
Expand Down Expand Up @@ -118,7 +114,8 @@ async def save_fundamental_data(self, session, symbol):
f"https://financialmodelingprep.com/api/v3/ratios/{symbol}?period=quarter&apikey={api_key}",
f"https://financialmodelingprep.com/api/v3/historical-price-full/stock_split/{symbol}?apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/stock_peers?symbol={symbol}&apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/institutional-ownership/institutional-holders/symbol-ownership-percent?date=2023-09-30&symbol={symbol}&page=0&apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/institutional-ownership/institutional-holders/symbol-ownership-percent?date=2024-03-31&symbol={symbol}&page=0&apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/historical/shares_float?symbol={symbol}&apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/revenue-product-segmentation?symbol={symbol}&structure=flat&period=annual&apikey={api_key}",
f"https://financialmodelingprep.com/api/v4/revenue-geographic-segmentation?symbol={symbol}&structure=flat&apikey={api_key}",
f"https://financialmodelingprep.com/api/v3/analyst-estimates/{symbol}?apikey={api_key}",
Expand Down Expand Up @@ -315,6 +312,9 @@ async def save_fundamental_data(self, session, symbol):
elif "institutional-ownership/institutional-holders" in url:
# Handle list response, save as JSON object
fundamental_data['shareholders'] = ujson.dumps(parsed_data)
elif "historical/shares_float" in url:
# Handle list response, save as JSON object
fundamental_data['historicalShares'] = ujson.dumps(parsed_data)
elif "revenue-product-segmentation" in url:
# Handle list response, save as JSON object
fundamental_data['revenue_product_segmentation'] = ujson.dumps(parsed_data)
Expand Down
15 changes: 2 additions & 13 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
import numpy as np
from fastapi import FastAPI,Depends,HTTPException, status
from typing import List, Dict, Union, Set
from typing import List, Dict, Set
from fastapi.middleware.cors import CORSMiddleware

from fastapi.openapi.docs import get_swagger_ui_html
Expand All @@ -10,23 +10,16 @@
import secrets
from benzinga import financial_data

from GetStartEndDate import GetStartEndDate

import ssl
import io
import gzip
from fastapi.responses import StreamingResponse

from collections import defaultdict
from datetime import date, datetime, timedelta, time
import json
import ujson
import pandas as pd
import sqlite3
from pydantic import BaseModel
#from arima import arima
import re
import asyncio
import aiohttp
#import time
import pandas as pd
Expand Down Expand Up @@ -115,10 +108,6 @@
load_dotenv()

pb = PocketBase('http://127.0.0.1:8090')
pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL')
pb_password = os.getenv('POCKETBASE_PASSWORD')

admin_data = pb.admins.auth_with_password(pb_admin_email, pb_password)

api_key = os.getenv('FMP_API_KEY')
benzinga_key = os.getenv('BENZINGA_API_KEY')
Expand Down Expand Up @@ -2573,7 +2562,7 @@ async def get_wiim(data:TickerData):
res = []

redis_client.set(cache_key, ujson.dumps(res))
redis_client.expire(cache_key, 60*60*2) # Set cache expiration time to 1 day
redis_client.expire(cache_key, 60*60*2)
return res

@app.get("/rss-feed-wiim")
Expand Down
1 change: 1 addition & 0 deletions fastify/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let serverRunning = false;

const fastify = require('fastify')({})
const cors = require('@fastify/cors');

//Load API KEYS
require('dotenv').config({ path: '../app/.env' });
const fmpAPIKey = process.env.FMP_API_KEY;
Expand Down
6 changes: 3 additions & 3 deletions fastify/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"axios": "^1.6.2",
"blob-util": "^2.0.2",
"cheerio": "^1.0.0-rc.12",
"fastify": "^4.26.0",
"dotenv": "^16.4.5",
"fastify": "^4.26.0",
"got": "^11.8.3",
"https": "^1.0.0",
"mixpanel": "^0.18.0",
Expand All @@ -24,4 +24,3 @@
"nodemon": "^3.0.1"
}
}

0 comments on commit 457db2a

Please sign in to comment.