开发者

error on getting dataframe defined in other object i.e. TypeError: 'DataFrame' object is not callable

i am new to python and trying to create some code for my understanding. i am getting error for getting tick_data in another object.

following is my code where i defined dataframe

    class MarketDataLoader():
    
    def __init__(self,symbols,cashPerTrade,broker_config: 'BrokerConfig'):
      self._tick_data = None
      #few other init var

   @property
   def tick_data(self) -> 'pandas.DataFrame':
        return self._tick_data
    
    def process_tick_data(self, data, dataframe):
        # some processing for tick data and assign value to tick data
   
    def process_and_resample_tick_data(self):
        self._api.subscribe_market_data(self._symbols, (self.process_tick_data,))
 

when process_and_resample_tick_data method got called it starts streaming to process_tick_data method

then in trade executor class


class TradeExecutor():

    def __init__(self,market_data: 'MarketDataLoader',trade_config:'TradeConfig',broker_config:'BrokerConfig'):
        print("Init Trade execute")
        self._market_data = market_data
        self._trade_config = trade_config
        self._broker_config =broker_config

    def start_trade(self):
        logger.info("starting trade from Trade Executor for ",self._trade_config.symbols,
                    " cash for trade ",self._trade_config.cash_per_trade)
        while True:  # 开发者_开发问答repeat until we get all historical bars
            time.sleep(10)
            print("trade time ",self._market_data)
#error on following line of code
            tick_frame = self._market_data.tick_data()

i am getting error on tick_frame = self._market_data.tick_data() i am not sure how to resolve following error

tick_frame = self._market_data.tick_data()
TypeError: 'DataFrame' object is not callable
python-BaseException


You're trying to call a method declared as a property.

When we use the @property decorator we treat the method as an attribute. For example, suppose we have the following class:

class JBug(object):
    def __init__(self):
        name = 'Junie'

    @property
    def hello(self):
        return "Hello, my name is %s" % name

To get the desired behavior we do not call hello, but treat it as an attribute:

>>> J = JBug()
>>> print(J.hello)
Hello, my name is Junie
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜