-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount_monitoring.py
More file actions
36 lines (29 loc) · 1.15 KB
/
account_monitoring.py
File metadata and controls
36 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import datetime
import threading
from risk_strategy import RiskManagement, risk_params
from credentials import ALPACA_API_KEY, ALPACA_SECRET_KEY
import alpaca_trade_api as tradeapi
api = tradeapi.REST(ALPACA_API_KEY, ALPACA_SECRET_KEY, base_url='https://paper-api.alpaca.markets')
risk_management = RiskManagement(api, risk_params)
def monitor_hourly():
while True:
risk_management.monitor_account_status()
risk_management.monitor_positions()
risk_management.report_profit_and_loss()
risk_management.update_risk_parameters()
print("Hourly monitoring completed. Pausing for 1 hour.")
time.sleep(60*60) # Pause for 1 hour
def monitor_daily():
while True:
drawdown = risk_management.calculate_drawdown()
if drawdown is not None:
print(f"Daily drawdown: {drawdown * 100}%")
print("Daily monitoring completed. Pausing for 24 hours.")
time.sleep(60*60*24) # Pause for 24 hours
# Create threads
hourly_thread = threading.Thread(target=monitor_hourly)
daily_thread = threading.Thread(target=monitor_daily)
# Start threads
hourly_thread.start()
daily_thread.start()