bugfixing
This commit is contained in:
parent
8b8f8dd5b5
commit
b7909036d2
@ -23,9 +23,9 @@ def save_json(data):
|
|||||||
|
|
||||||
identifier = 'GME'
|
identifier = 'GME'
|
||||||
source = 'cta_a_delayed'
|
source = 'cta_a_delayed'
|
||||||
#start_date, end_date = GetStartEndDate().run()
|
start_date, end_date = GetStartEndDate().run()
|
||||||
start_date = '2024-07-22' #start_date.strftime("%Y-%m-%d")
|
start_date = start_date.strftime("%Y-%m-%d")
|
||||||
end_date = '2024-07-22' #end_date.strftime("%Y-%m-%d")
|
end_date = end_date.strftime("%Y-%m-%d")
|
||||||
start_time = ''
|
start_time = ''
|
||||||
end_time = ''
|
end_time = ''
|
||||||
timezone = 'UTC'
|
timezone = 'UTC'
|
||||||
@ -34,20 +34,22 @@ darkpool_only = True
|
|||||||
min_size = 100
|
min_size = 100
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
|
|
||||||
def get_data():
|
def get_data():
|
||||||
data = []
|
data = []
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if count == 0:
|
if count == 0:
|
||||||
next_page = ''
|
next_page = ''
|
||||||
try:
|
try:
|
||||||
response = intrinio.SecurityApi().get_security_trades_by_symbol(identifier, source, start_date=start_date, start_time=start_time, end_date=end_date, end_time=end_time, timezone=timezone, page_size=page_size, darkpool_only=darkpool_only, min_size=min_size, next_page=next_page)
|
response = intrinio.SecurityApi().get_security_trades_by_symbol(
|
||||||
|
identifier, source, start_date=start_date, start_time=start_time,
|
||||||
|
end_date=end_date, end_time=end_time, timezone=timezone,
|
||||||
|
page_size=page_size, darkpool_only=darkpool_only, min_size=min_size,
|
||||||
|
next_page=next_page
|
||||||
|
)
|
||||||
|
|
||||||
filtered_entries = [
|
filtered_entries = [entry.__dict__ for entry in response.trades]
|
||||||
entry.__dict__ for entry in response.trades
|
|
||||||
#if int(entry._price * entry._total_volume) >= 2E9
|
|
||||||
]
|
|
||||||
|
|
||||||
data.extend(filtered_entries)
|
data.extend(filtered_entries)
|
||||||
next_page = response.next_page
|
next_page = response.next_page
|
||||||
@ -63,35 +65,48 @@ def get_data():
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
con = sqlite3.connect('stocks.db')
|
con = sqlite3.connect('stocks.db')
|
||||||
cursor = con.cursor()
|
cursor = con.cursor()
|
||||||
cursor.execute("SELECT DISTINCT symbol, name FROM stocks")
|
cursor.execute("SELECT DISTINCT symbol, name FROM stocks")
|
||||||
stocks = cursor.fetchall()
|
stocks = cursor.fetchall()
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
symbol_name_map = {row[0]: row[1] for row in stocks}
|
symbol_name_map = {row[0]: row[1] for row in stocks}
|
||||||
stock_symbols = list(symbol_name_map.keys())
|
stock_symbols = list(symbol_name_map.keys())
|
||||||
data = get_data()
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
# Filter the data
|
data = get_data()
|
||||||
filtered_data = [entry for entry in data if entry['_symbol'] in stock_symbols]
|
filtered_data = [entry for entry in data if entry['_symbol'] in stock_symbols]
|
||||||
res = [
|
|
||||||
|
|
||||||
|
filtered_data = [
|
||||||
{
|
{
|
||||||
'symbol': entry['_symbol'],
|
'symbol': entry['_symbol'],
|
||||||
'name': symbol_name_map[entry['_symbol']],
|
'name': symbol_name_map[entry['_symbol']],
|
||||||
'date': (entry['_timestamp']-timedelta(hours=4)).isoformat(),
|
'date': (entry['_timestamp']-timedelta(hours=4)).isoformat(),
|
||||||
'price': entry['_price'],
|
'price': entry['_price'],
|
||||||
'volume': entry['_total_volume'],
|
'total_volume': entry['_total_volume'],
|
||||||
'size': entry['_size']
|
'size': entry['_size']
|
||||||
}
|
}
|
||||||
for entry in filtered_data
|
for entry in filtered_data
|
||||||
]
|
]
|
||||||
|
|
||||||
|
sorted_data = sorted(filtered_data, key=lambda x: x['date'])
|
||||||
|
|
||||||
if len(res) > 0:
|
previous_total_volume = None
|
||||||
save_json(res)
|
|
||||||
|
for entry in sorted_data:
|
||||||
|
if previous_total_volume is not None:
|
||||||
|
entry["volume"] = int(entry["total_volume"]) - previous_total_volume
|
||||||
|
else:
|
||||||
|
entry["volume"] = int(entry["total_volume"]) #if you prefer to keep the first volume as is
|
||||||
|
previous_total_volume = int(entry["total_volume"])
|
||||||
|
|
||||||
|
sorted_data = sorted(sorted_data, key=lambda x: x['date'], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
|
if len(sorted_data) > 0:
|
||||||
|
save_json(sorted_data)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user