@@ -57,6 +57,7 @@ def __init__(self, trade_handler):
57
57
super ().__init__ (trade_handler )
58
58
self .parser = reqparse .RequestParser ()
59
59
self .parser .add_argument ('action' , type = str , help = 'close|start|pause' )
60
+ self .parser .add_argument ('data' , type = dict )
60
61
61
62
def get (self , id ):
62
63
return Response (response = ConfigLoader .get_json_str (self .th .get_strategy_by_id (id ).trade ),
@@ -67,7 +68,7 @@ def delete(self, id):
67
68
strategies = self .get_strategies (id )
68
69
69
70
if not strategies :
70
- return APIResult .ErrorResult (101 , msg = 'No strategies were found' )
71
+ return APIResult .ErrorResult (101 , msg = 'No strategies were found' ), 404
71
72
72
73
# for strategy in strategies:
73
74
# self.th.remove_trade_by_strategy(strategy, True)
@@ -90,12 +91,12 @@ def post(self, id=None):
90
91
action = args ['action' ]
91
92
92
93
if not action :
93
- return APIResult .ErrorResult (100 , msg = 'No "action" was provided' )
94
+ return APIResult .ErrorResult (100 , msg = 'No "action" was provided' ), 403
94
95
95
96
strategies = self .get_strategies (id )
96
97
97
98
if not strategies :
98
- return APIResult .ErrorResult (101 , msg = 'No strategies were found' )
99
+ return APIResult .ErrorResult (101 , msg = 'No strategies were found' ), 404
99
100
100
101
action = action .lower ()
101
102
@@ -108,6 +109,20 @@ def post(self, id=None):
108
109
109
110
for strategy in strategies :
110
111
strategy .paused = paused
112
+ elif action == 'add' :
113
+ ids = []
114
+ try :
115
+ trade_json = args ['data' ]
116
+ trades = ConfigLoader .load_trade_list_from_obj (trade_json )
117
+ for trade in trades :
118
+ ids .append (trade .id )
119
+ self .th .updated_trade (trade )
120
+ self .th .fire_trade_updated (trade , True )
121
+ except Exception as e :
122
+ # return Response(APIResult.ErrorResult(100, e), 500, mimetype='application/json')
123
+ return json .dumps (APIResult .ErrorResult (100 , str (e ))), 500
124
+
125
+ return APIResult .OKResult (ids ), 201
111
126
112
127
return APIResult .OKResult ()
113
128
0 commit comments