我在谷歌上搜索了"typeerror:'int'对象不可调用",但仍然不知道该怎么做。找不到重叠名称



我在谷歌上搜索了错误"typeerror:'int'object is not callable'表示变量和方法/函数名称中的名称相同。但我找不到相同的名字。伙计们能帮我吗?非常感谢。

此外,该代码由其他程序调用。另一个程序调用sendorder(action,price,qty,limit,stop(来发送订单。

谢谢,兄弟

错误消息:Davidde MacBook Pro:Github davidleao$/usr/local/bin/python3/Users/davidleao/Documents/code/Github/MyProject/SB.py追踪(最近一次通话(:文件"/Users/davidleao/Documents/code/Github/MyProject/SB.py";,第63行,insendorder(action、Limit、quantity、TakePProfit、StopLoss(文件"/Users/davidleao/Documents/code/Github/MyProject/SendBracketOrder.py";,第137行,发送顺序app.run((文件"/Users/davidleao/Documents/code/Github/MyProject/ibabi/client.py";,线路239,运行中self.decoder.explect(字段(文件"/Users/davidliao/Documents/code/Github/MyProject/ibabi/decoder.py";,第1278行,解释中self.interpretWithSignature(字段,handleInfo(文件"/Users/davidliao/Documents/code/Github/MyProject/ibabi/decoder.py";,第1259行,插入WithSignature方法(*args(文件"/Users/davidleao/Documents/code/Github/MyProject/SendBracketOrder.py";,第27行,在nextValidId中self.start((文件"/Users/davidleao/Documents/code/Github/MyProject/SendBracketOrder.py";,第68行,起始括号=自身。BracketOrder(self.nextOrderId((,self.signal,self.qty,self.entryprice,self.tp,self.sl(TypeError:"int"对象不可调用错误:-1 504未连接Davidde MacBook Pro:Github davidlio$

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
from ibapi.ticktype import TickTypeEnum
from threading import Timer
class TestApp(EWrapper,EClient):
def __init__(self,action,price,qty,limit,stop):
EClient.__init__(self,self)
self.action=action
self.price=price
self.qty=qty
self.tp=limit
self.sl=stop
return
def error(self,reqId,errorCode,errorString):
print('Error: ',reqId,' ',errorCode,' ',errorString)
return
def nextValidId(self,orderId):
self.nextOrderId=orderId
self.start()
return
def orderStatus(self,orderId,status,filled,remaining,avgFillPrice,permId,parenttId,lastFillPrice,clientId,whyHeld,mktCapPrice):
print('OrderStatus. Id: ',orderId,', Status: ',status,', Filled: ',filled,', Remaining: ',remaining,', LastFillPrice: ',lastFillPrice)
return

def openOrder(self,orderId,contract,order,orderState):
print('OpenOrder. ID:',orderId,contract.symbol,contract.secType,'@',contract.exchange,':',order.action,order.orderType,order.totalQuantity, orderState.status)
return

def execDetails(self,reqId,contract,execution):
print('ExecDetails. ',reqId,contract.symbol,contract.secType,contract.currency,execution.execId,execution.orderId,execution.shares,execution.lastLiquidity)
return
def updatePortfolio(self,contract:Contract,position:float,marketPrice:float,marketValue:float,averageCost:float,unrealizedPNL:float,realizedPNL:float,accountName:str):
print('UpdatePortfolio.','Symbol:',contract.symbol,'SecType:',contract.secType,'Exchange:',contract.exchange,'Position:',position,'MarketPrice:',marketPrice,'MarketValue:',marketValue,'AverageCost:',averageCost,'UnrealizedPNL:',unrealizedPNL,'RealizedPNL:',realizedPNL,'AccountName:',accountName)
return
def start(self):
#EURUSD sell 10000 0
#{{ticker}} {{strategy.order.action}} {{strategy.order.contracts}} {{strategy.position_size}}
# print('data is ',self.data)
# self.data=self.data.split()
# self.data = [x.upper() for x in self.data]
# action=self.data[1]
# print('Action:',action)
# quantity=int(self.data[2])
# print('Quantity:',quantity)
#position=int(self.data[3])
# print('Position:',position)
# Contract
contract = Contract()
contract.symbol = "EUR"
contract.secType = "CFD" 
contract.currency = "USD"
contract.exchange = "SMART" 
# Order
bracket = self.BracketOrder(self.nextOrderId(), self.action, self.qty,self.price, self.tp, self.sl)
for o in bracket:
self.placeOrder(o.orderId, contract, o)
self.nextOrderId() # need to advance this we’ll skip one extra oid, it’s fine
#Update Portfolio
self.reqAccountUpdates(True,"") 
return

def stop(self):
self.reqAccountUpdates(False,"")
self.done=True
self.disconnect()
return
@staticmethod
def BracketOrder(
self,
parentOrderId:int, 
action:str, 
quantity:float, 
limitPrice:float, 
takeProfitLimitPrice:float, 
stopLossPrice:float
):
#This will be our main or “parent” order
parent = Order()
parent.orderId = parentOrderId
parent.action = action
parent.orderType = 'LMT'
parent.totalQuantity = quantity
parent.lmtPrice = limitPrice
#The parent and children orders will need this attribute set to False to prevent accidental executions.
#The LAST CHILD will have it set to True, 
parent.transmit = False
takeProfit = Order()
takeProfit.orderId = parent.orderId + 1
takeProfit.action = 'SELL' if action == 'BUY' else 'BUY'
takeProfit.orderType = 'LMT'
takeProfit.totalQuantity = quantity
takeProfit.lmtPrice = takeProfitLimitPrice
takeProfit.parentId = parentOrderId
takeProfit.transmit = False
stopLoss = Order()
stopLoss.orderId = parent.orderId + 2
stopLoss.action = 'SELL' if action == 'BUY' else 'BUY'
stopLoss.orderType = 'STP'
#Stop trigger price
stopLoss.auxPrice = stopLossPrice
stopLoss.totalQuantity = quantity
stopLoss.parentId = parentOrderId
#In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to True 
#to activate all its predecessors
stopLoss.transmit = True
bracketOrder = [parent, takeProfit, stopLoss]
return bracketOrder
def sendorder(action,price,qty,limit,stop):
app=TestApp(action,price,qty,limit,stop)
app.nextOrderId=0
app.connect('127.0.0.1',4002,0)
# Call stop() after 3 seconds to disconnect the program
Timer(3,app.stop).start()

app.run()
if __name__=="__main__":
sendorder()

但我以前的程序运行良好。。。。。

'''
This is for webhook listener to call to send order to IB.
'''
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
from ibapi.ticktype import TickTypeEnum
from threading import Timer
class TestApp(EWrapper,EClient):
def __init__(self,data):
EClient.__init__(self,self)
self.data=data
def error(self,reqId,errorCode,errorString):
print('Error: ',reqId,' ',errorCode,' ',errorString)
def nextValidId(self,orderId):
self.nextOrderId=orderId
self.start()
def orderStatus(self,orderId,status,filled,remaining,avgFillPrice,permId,parenttId,lastFillPrice,clientId,whyHeld,mktCapPrice):
print('OrderStatus. Id: ',orderId,', Status: ',status,', Filled: ',filled,', Remaining: ',remaining,', LastFillPrice: ',lastFillPrice)

def openOrder(self,orderId,contract,order,orderState):
print('OpenOrder. ID:',orderId,contract.symbol,contract.secType,'@',contract.exchange,':',order.action,order.orderType,order.totalQuantity, orderState.status)

def execDetails(self,reqId,contract,execution):
print('ExecDetails. ',reqId,contract.symbol,contract.secType,contract.currency,execution.execId,execution.orderId,execution.shares,execution.lastLiquidity)
def updatePortfolio(self,contract:Contract,position:float,marketPrice:float,marketValue:float,averageCost:float,unrealizedPNL:float,realizedPNL:float,accountName:str):
print('UpdatePortfolio.','Symbol:',contract.symbol,'SecType:',contract.secType,'Exchange:',contract.exchange,'Position:',position,'MarketPrice:',marketPrice,'MarketValue:',marketValue,'AverageCost:',averageCost,'UnrealizedPNL:',unrealizedPNL,'RealizedPNL:',realizedPNL,'AccountName:',accountName)
def start(self):

#EURUSD sell 10000 0
#{{ticker}} {{strategy.order.action}} {{strategy.order.contracts}} {{strategy.position_size}}
print('data is ',self.data)
self.data=self.data.split()
self.data = [x.upper() for x in self.data]
action=self.data[1]
print('Action:',action)
quantity=int(self.data[2])
print('Quantity:',quantity)
#position=int(self.data[3])
# print('Position:',position)
contract = Contract()
contract.symbol = "EUR"
contract.secType = "CFD" 
contract.currency = "USD"
contract.exchange = "SMART" 
order=Order()
order.action=action
order.totalQuantity=quantity
order.orderType="MKT"
self.placeOrder(self.nextOrderId,contract,order)
#Update Portfolio
self.reqAccountUpdates(True,"") 


def stop(self):
self.reqAccountUpdates(False,"")
self.done=True
self.disconnect()
def sendorder(data):
app=TestApp(data)
app.nextOrderId=0
app.connect('127.0.0.1',4002,0)
# Call stop() after 3 seconds to disconnect the program
Timer(3,app.stop).start()

app.run()
if __name__=="__main__":
main()

定义TestApp类时,将nextOrderId定义为该类上的方法。

TestApp.start中,您可以调用此方法:

for o in bracket:
self.placeOrder(o.orderId, contract, o)
self.nextOrderId()

然而

sendorder中设置app.nextOrderId = 0

因此,您正在用一个整数覆盖该方法,当代码试图运行self.nextOrderId()时,它试图将该整数作为一个方法调用,这是没有意义的,因此出现了错误typeerror: 'int' object is not callable

最新更新