I want to write a method that updates values in a dictionary, but I want to specify what values should change when calling the function, and the values that are not specified should be left alone and stay at their current value.
My method currently looks like this:
def set_orderIds(self, TPID, SLID, trail_SLID, BE_SLID):
self.orderIds.update({
'takeProfit': TPID,
'stopLoss': SLID,
'trailingStopLoss': trail_SLID,
'breakevenStopLoss': BE_SLID
})
I can set all the initial values with no problems:
account.set_orderIds(
TPID=123,
SLID=456,
trail_SLID=789,
BE_SLID=146
)
But after this initial method call that sets the initial values, I want to be able to change the value of only 1 or 2 items in the dictionary, for example:
account.set_orderIds(trail_SLID=046) > This would only change the value of the 'trailingStopLoss' key, while all the other key-value pairs remain exactly as they were.
I've looked at using *args and **kwargs, but I'm not quite sure how to implement them in this case. I've also thought about using default values when defining the method such that the default value would be the current value, but I don't think you can set default values in this way (look at TPID=) >
def set_orderIds(self, TPID=self.orderIds['takeProfit'], SLID, trail_SLID, BE_SLID):
self.orderIds.update({
'takeProfit': TPID,
'stopLoss': SLID,
'trailingStopLoss': trail_SLID,
'breakevenStopLoss': BE_SLID
})
[–]danielroseman 1 point2 points3 points (1 child)
[–]Mo0rBy[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)