Updating Attributes of Class as Parameters Changes: How to Keep Brokerage Account Class up-to-date?
Question: How does one keep the attributes of an instance of a class up-to-date if the
are changing moment to moment?

For example, I have defined a class describing my stock trading brokerage
account balances. I have defined a function which pings the brokerage API and
returns a JSON object with the current status of various parameters. The
status of these parameters are then set as attributes of a given instance.

    
    
    import json
    import requests
    from ConfigParser import SafeConfigParser   
    
    class Account_Balances:
        def Account_Balances_Update():
        """Pings brokerage for current status of target account"""
            #set query args
            endpoint = parser.get('endpoint', 'brokerage') + 'user/balances'
            headers = {'Authorization': parser.get('account', 'Auth'), 'Accept': parser.get('message_format', 'accept_format')}
    
            #send query
            r = requests.get(endpoint, headers = headers)
            response = json.loads(r.text)
            return response        
    
        def __init__(self):
    
            self.response = self.Account_Balances_Update()
            self.parameterA = response['balances']['parameterA']
            self.parameterB = response['balances']['parameterB']  
    

As it stands, this code sets the parameters at the moment the instance is
created but they become static.

Presumably `parameterA` and `parameterB` are changing moment to moment so I
need to keep them up-to-date for any given instance when requested. Updating
the parameters requires rerunning the `Account_Balances_Update()` function.

What is the pythonic way to keep the attribute of a given instance of a class
up to date in a fast moving environment like stock trading?


Answer: Why not just creating an update method?

    
    
    class Account_Balances:
        @staticmethod
        def fetch():
            """Pings brokerage for current status of target account"""
            #set query args
            endpoint = parser.get('endpoint', 'brokerage') + 'user/balances'
            headers = {'Authorization': parser.get('account', 'Auth'), 'Accept': parser.get('message_format', 'accept_format')}
    
            #send query
            r = requests.get(endpoint, headers = headers)
            response = json.loads(r.text)
            balances = response['balances']
    
            return balances['parameterA'], balances['parameterB']
    
        def update(self):
            self.parameterA, self.parameterB = self.fetch()
    

