Skip to content

Commit

Permalink
update dark pool flow
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jul 23, 2024
1 parent 39c1e93 commit 01c187a
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions app/cron_dark_pool_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from datetime import datetime, timedelta

from datetime import timedelta
from GetStartEndDate import GetStartEndDate
from concurrent.futures import ThreadPoolExecutor, TimeoutError
import intrinio_sdk as intrinio
Expand All @@ -21,10 +21,11 @@ def save_json(data):
ujson.dump(data, file)


identifier = 'GME'
source = 'cta_a_delayed'
#start_date, end_date = GetStartEndDate().run()
start_date = ''
end_date = ''
start_date, end_date = GetStartEndDate().run()
start_date = start_date.strftime("%Y-%m-%d")
end_date = end_date.strftime("%Y-%m-%d")
start_time = ''
end_time = ''
timezone = 'UTC'
Expand All @@ -36,31 +37,30 @@ def save_json(data):

def get_data():
data = []
#count = 0
next_page = ''
try:
response = intrinio.SecurityApi().get_security_trades(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)
data = response.trades
except Exception as e:
print(e)

'''
count = 0
while True:
if count == 0:
next_page = ''
try:
response = intrinio.SecurityApi().get_security_trades(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)
data += response.trades
print(data)
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 = [
entry.__dict__ for entry in response.trades
if int(entry._price * entry._total_volume) >= 2E9
]

data.extend(filtered_entries)
next_page = response.next_page
if not next_page or count == 0:

if not next_page:
break
count +=1
print(f'Current length {len(data)}')

except Exception as e:
print(e)
break
'''

return data

def run():
Expand All @@ -73,11 +73,10 @@ def run():
symbol_name_map = {row[0]: row[1] for row in stocks}
stock_symbols = list(symbol_name_map.keys())
data = get_data()
print(data)

# Convert each SecurityTrades object to a dictionary
data_dicts = [entry.__dict__ for entry in data]
# Filter the data
filtered_data = [entry for entry in data_dicts if entry['_symbol'] in stock_symbols]
filtered_data = [entry for entry in data if entry['_symbol'] in stock_symbols]
res = [
{
'symbol': entry['_symbol'],
Expand All @@ -90,7 +89,6 @@ def run():
for entry in filtered_data
]

print(res)

if len(res) > 0:
save_json(res)
Expand All @@ -101,7 +99,7 @@ def run():
future = executor.submit(run)
try:
# Wait for the result with a timeout of 300 seconds (5 minutes)
future.result(timeout=10)
future.result(timeout=1000)
except TimeoutError:
print("The operation timed out.")
except Exception as e:
Expand Down

0 comments on commit 01c187a

Please sign in to comment.