-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
trade.py
76 lines (72 loc) · 1.96 KB
/
trade.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# two modes: "backtesting", and "paper_trading"
from meta.env_stock_trading.env_stock_papertrading import (
AlpacaPaperTrading,
)
from test import test
def trade(
start_date,
end_date,
ticker_list,
data_source,
time_interval,
technical_indicator_list,
drl_lib,
env,
model_name,
API_KEY,
API_SECRET,
API_BASE_URL,
trade_mode="backtesting",
if_vix=True,
**kwargs
):
if trade_mode == "backtesting":
# use test function for backtesting mode
test(
start_date,
end_date,
ticker_list,
data_source,
time_interval,
technical_indicator_list,
drl_lib,
env,
model_name,
if_vix=True,
**kwargs
)
elif trade_mode == "paper_trading":
# read parameters
try:
net_dim = kwargs.get("net_dimension", 2**7)
cwd = kwargs.get("cwd", "./" + str(model_name)) # current working directory
state_dim = kwargs.get("state_dim")
action_dim = kwargs.get("action_dim")
except:
raise ValueError(
"Fail to read parameters. Please check inputs for net_dim, cwd, state_dim, action_dim."
)
# initialize trading env
AlpacaPaperTrading(
ticker_list,
time_interval,
drl_lib,
model_name,
cwd,
net_dim,
state_dim,
action_dim,
API_KEY,
API_SECRET,
API_BASE_URL,
technical_indicator_list,
turbulence_thresh=30,
max_stock=1e2,
latency=None,
)
# run paper trading
AlpacaPaperTrading.run()
else:
raise ValueError(
"Invalid input! Please input either 'backtesting' or 'paper_trading'."
)