bugfixing
This commit is contained in:
parent
fc9850067c
commit
060d69fb1b
@ -54,7 +54,7 @@ async def get_bid_ask_quote_of_stocks(ticker_list):
|
||||
if response.status == 200:
|
||||
return await response.json()
|
||||
else:
|
||||
return {}
|
||||
return []
|
||||
|
||||
async def save_quote_as_json(symbol, data):
|
||||
with open(f"json/quote/{symbol}.json", 'w') as file:
|
||||
@ -71,6 +71,9 @@ async def save_pre_post_quote_as_json(symbol, data):
|
||||
with open(f"json/pre-post-quote/{symbol}.json", 'w') as file:
|
||||
dt = datetime.fromtimestamp(data['timestamp']/1000, ny_timezone)
|
||||
formatted_date = dt.strftime("%b %d, %Y, %I:%M %p %Z")
|
||||
|
||||
#Bugfixing: pre-filter to fight against FMP bug that shows -30% drop sometimes in the premarket
|
||||
if abs(changes_percentage) <= 15:
|
||||
res = {'symbol': symbol, 'price': round(data['price'],2), 'changesPercentage': changes_percentage, 'time': formatted_date}
|
||||
file.write(orjson.dumps(res).decode())
|
||||
except Exception as e:
|
||||
@ -82,10 +85,20 @@ async def save_bid_ask_as_json(symbol, data):
|
||||
with open(f"json/quote/{symbol}.json", 'r') as file:
|
||||
quote_data = orjson.loads(file.read())
|
||||
|
||||
# Update quote data with new price, ask, bid, changesPercentage, and timestamp
|
||||
ask_price = round(data['askPrice'], 2)
|
||||
bid_price = round(data['bidPrice'], 2)
|
||||
|
||||
#Bugfixing: pre-filter to fight against FMP bug that shows -30% drop sometimes in the premarket
|
||||
|
||||
mean_price = (ask_price+bid_price)/2
|
||||
current_price = quote_data['price']
|
||||
|
||||
changes_percentage = (mean_price/current_price -1 ) *100
|
||||
|
||||
if abs(changes_percentage) <= 15:
|
||||
quote_data.update({
|
||||
'ask': round(data['askPrice'], 2), # Add ask price
|
||||
'bid': round(data['bidPrice'], 2), # Add bid price
|
||||
'ask': ask_price, # Add ask price
|
||||
'bid': bid_price, # Add bid price
|
||||
})
|
||||
|
||||
# Save the updated quote data back to the same JSON file
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user