File tree 1 file changed +20
-4
lines changed
1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -147,10 +147,26 @@ def getcash(self):
147
147
return cash
148
148
149
149
def getvalue (self , datas = None ):
150
- # don't use self.o.get_value(). it takes time for local store to get
151
- # update from broker.
152
- self .value = float (self .o .oapi .get_account ().portfolio_value )
153
- return self .value
150
+ """
151
+ if datas then we will calculate the value of the positions if not
152
+ then the value of the entire portfolio (positions + cash)
153
+ :param datas: list of data objects
154
+ :return: float
155
+ """
156
+ if not datas :
157
+ # don't use self.o.get_value(). it takes time for local store to
158
+ # get update from broker.
159
+ self .value = float (self .o .oapi .get_account ().portfolio_value )
160
+ return self .value
161
+ else :
162
+ # let's calculate the value of the positions
163
+ total_value = 0
164
+ for d in datas :
165
+ pos = self .getposition (d )
166
+ if pos .size :
167
+ price = list (d )[0 ]
168
+ total_value += price * pos .size
169
+ return total_value
154
170
155
171
def getposition (self , data , clone = True ):
156
172
pos = self .positions [data ]
You can’t perform that action at this time.
0 commit comments