excalidraw flow and basic rust ws

This commit is contained in:
2026-04-30 17:56:57 +00:00
parent 1ac0909c21
commit 7d579faa82
7 changed files with 2859 additions and 29 deletions

View File

@@ -12,6 +12,8 @@ import multiprocessing as mp
import threading
from typing import Any
'''
TO DO:
- Insert config changes into database for analysis later / general tracking
@@ -20,7 +22,6 @@ TO DO:
LOCAL_ORDERS: list = []
### Database ###
VK_POS_ASTER: str = 'fr_aster_user_positions'
VK_IN: str = 'fr_engine_orders_input'
VK_OUT: str = 'fr_engine_orders_output'
VAL_KEY: valkey.Valkey = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)
@@ -29,23 +30,30 @@ VAL_KEY: valkey.Valkey = valkey.Valkey(host='localhost', port=6379, db=0, decode
load_dotenv()
LOG_FILEPATH: str = f'{os.getenv("LOGS_PATH")}/Fund_Rate_Engine_Orders.log'
# async def work_order(order: dict) -> dict:
# LOCAL_ORDERS.append(order)
# while LOCAL_ORDERS:
# print(f'working order...{order}')
# time.sleep(5)
# print(f'{order}...order posted/replaced/etc')
# VAL_KEY.set(name=VK_OUT, value=json.dumps(order))
# return order
### Main Listener for Order Requests (e.g. from Algo Engine) ###
def receive_orders():
global LOCAL_ORDERS
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
VK_PUBSUB.subscribe(VK_IN)
for message in VK_PUBSUB.listen():
loop_start = time.time()
if message['type'] == 'message':
ts_arrival: int = round(number=datetime.now().timestamp()*1000)
# Receive Update Msg from PubSub
data: dict = json.loads(s=message['data'])
print(data)
LOCAL_ORDERS.append(data)
print(f'__ Rec Orders: Loop End __ - Algo Engine ms: {(time.time() - loop_start)*1000:.2f}')
### Listeners - Aster ###
def receive_position_updates_aster():
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
VK_PUBSUB.subscribe('fr_aster_user_positions')
for message in VK_PUBSUB.listen():
loop_start = time.time()
if message['type'] == 'message':
ts_arrival: int = round(number=datetime.now().timestamp()*1000)
@@ -53,26 +61,58 @@ def receive_orders():
data: dict = json.loads(s=message['data'])
print(data)
# def receive_notional_updates():
# VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
# VK_PUBSUB.subscribe(VK_IN)
# for message in VK_PUBSUB.listen():
# if message['type'] == 'message':
# ts_arrival: int = round(number=datetime.now().timestamp()*1000)
print(f'__ Aster Notional: Loop End __ - Algo Engine ms: {(time.time() - loop_start)*1000:.2f}')
def receive_order_updates_aster():
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
VK_PUBSUB.subscribe('fr_aster_user_orders')
for message in VK_PUBSUB.listen():
loop_start = time.time()
if message['type'] == 'message':
# ts_arrival: int = round(number=datetime.now().timestamp()*1000)
# # Receive Update Msg from PubSub
# data: dict = json.loads(s=message['data'])
# print(data)
# LOCAL_ORDERS.append(data)
# Receive Update Msg from PubSub
data: dict = json.loads(s=message['data'])
print(data)
print(f'__ Aster Orders: Loop End __ - Algo Engine ms: {(time.time() - loop_start)*1000:.2f}')
### Listeners - Extend ###
def receive_position_updates_extend():
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
VK_PUBSUB.subscribe('fr_extended_user_positions')
for message in VK_PUBSUB.listen():
loop_start = time.time()
if message['type'] == 'message':
ts_arrival: int = round(number=datetime.now().timestamp()*1000)
# Receive Update Msg from PubSub
data: dict = json.loads(s=message['data'])
print(data)
print(f'__ Aster Notional: Loop End __ - Algo Engine ms: {(time.time() - loop_start)*1000:.2f}')
def receive_order_updates_extend():
VK_PUBSUB: valkey.client.PubSub = VAL_KEY.pubsub()
VK_PUBSUB.subscribe('fr_extended_user_orders')
for message in VK_PUBSUB.listen():
loop_start = time.time()
if message['type'] == 'message':
# ts_arrival: int = round(number=datetime.now().timestamp()*1000)
# Receive Update Msg from PubSub
data: dict = json.loads(s=message['data'])
print(data)
print(f'__ Aster Orders: Loop End __ - Algo Engine ms: {(time.time() - loop_start)*1000:.2f}')
async def main() -> None:
global LOCAL_ORDERS
try:
thread = threading.Thread(target=receive_orders)
thread.daemon = True
# thread.start()
thread.join()
t_rec_orders = threading.Thread(target=receive_orders)
t_rec_orders.daemon = True
t_rec_orders.start()
# while True: