[docs]classVariable:def__init__(self,data:VariableResponse,client:'WTClient',auto_refresh:bool):self._VariableResponse:VariableResponse=data#: raw response data from APIself.client:'WTClient'=client#: the WTClient object that created this instanceself.auto_refresh:bool=auto_refresh#: auto_refresh toggle inherited from WTClientself.number:str=data.number#: Variable numberself.name:str=data.name#: Variable nameself.value:Optional[str]=data.value#: Variable valueself.free_text_value:Optional[str]=data.free_text_value#: Free text value of the variableself.last_updated_at:Optional[datetime]=data.last_updated_at#: Last updated atself.bot:Optional[str]=data.bot#: Bot associated with the variableself.conditions:List[Optional[Condition]]=data.conditions#: Conditions associated with the variableifdata.botisNone:self.free_text_value:Optional[str]=data.value# Variables not associated with bots are always free text
[docs]defupdate(self,name:str=None,value:str=None)->str:""" Change this variable name or free text value Auth Required: Write Variables :param name: new name of the variable :param value: New free text value for the variable. This is only valid if the variable is a "Free Text" type that is not associated with a bot :return: message from Whispertrades API """ifnotnameandvalueisNone:raiseValueError('Either name or value are required. Name cannot be empty string.')ifvalueisnotNone:ifself.bot:raiseValueError('You can only update values of variables that are not associated with a bot.')ifself.free_text_valueisNone:# currently this is not needed as all variables without a bot associated will always be free text, but this line is kept for future possible expansionraiseValueError('You can only update free text variables.')payload={}ifname:payload['name']=str(name)ifvalueisnotNone:payload['value']=str(value)response=self.client.session.put(f"{self.client.endpoint}bots/variables/{self.number}",headers=self.client.headers,json=payload)response=BaseResponse(**orjson.loads(response.text))ifresponse.success:self.__init__(VariableResponse(**response.data),self.client,self.auto_refresh)returnresponse.messageelse:raiseAPIError(response.message)