我是新的python和试图创建一些代码为我的理解。我得到错误的获取tick_data
在另一个对象。
下面是我的代码,其中我定义了 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,))
当调用process_and_resample_tick_data
方法时,它开始流到process_tick_data
方法
那么在交易执行者阶层
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()
我在tick_frame = self._market_data.tick_data()
上遇到错误我不确定如何解决以下错误
tick_frame = self._market_data.tick_data()
TypeError: 'DataFrame' object is not callable
python-BaseException
1条答案
按热度按时间2izufjch1#
您尝试呼叫宣告为属性的方法。
当我们使用
@property
装饰器时,我们把方法当作一个属性。为了获得所需的行为,我们不调用
hello
,而是将其视为一个属性: