Delta close not showing in SubscribeLiveTrendBarReq
Delta close not showing in SubscribeLiveTrendBarReq
08 Mar 2023, 15:51
Hey, I'm trying to use this code to get the trend bar information so i can have live bar closes so my indicator can be updated.
The problem i'm facing is that the response i'm getting doesnt show delta.close. I could use the delta.open of the next bar but its not ideal as sometimes the close of the previous bar isnt the same as the open of the current bar.
credentialsFile = open("credentials-dev.json")
credentials = json.load(credentialsFile)
host = EndPoints.PROTOBUF_LIVE_HOST if credentials["HostType"].lower() == "live" else EndPoints.PROTOBUF_DEMO_HOST
client = Client(host, EndPoints.PROTOBUF_PORT, TcpProtocol)
symbolName = "GBPUSD"
def sendProtoOASubscribeLiveTrendbarReq(result):
request = ProtoOASubscribeLiveTrendbarReq()
request.symbolId = 2
request.ctidTraderAccountId = credentials["AccountId"]
request.period = ProtoOATrendbarPeriod.M1
deferred = client.send(request)
deferred.addErrback(onError)
def sendProtoOASubscribeSpotsReq(result):
symbols = Protobuf.extract(result)
global symbolName
symbolsFilterResult = list(filter(lambda symbol: symbol.symbolName == symbolName, symbols.symbol))
if len(symbolsFilterResult) == 0:
raise Exception(f"There is symbol that matches to your defined symbol name: {symbolName}")
elif len(symbolsFilterResult) > 1:
raise Exception(f"More than one symbol matched with your defined symbol name: {symbolName}, match result: {symbolsFilterResult}")
symbol = symbolsFilterResult[0]
symbolId = symbol.symbolId
timeInSeconds = 2
subscribeToSpotTimestamp = False
clientMsgId = None
request = ProtoOASubscribeSpotsReq()
request.ctidTraderAccountId = credentials["AccountId"]
request.symbolId.append(int(symbolId))
request.subscribeToSpotTimestamp = subscribeToSpotTimestamp if type(subscribeToSpotTimestamp) is bool else bool(subscribeToSpotTimestamp)
deferred = client.send(request, clientMsgId = clientMsgId)
deferred.addCallbacks(sendProtoOASubscribeLiveTrendbarReq, onError)
#deferred.addErrback(onError)
#reactor.callLater(int(timeInSeconds), sendProtoOAUnsubscribeSpotsReq, symbolId)
def accountAuthResponseCallback(result):
print("\nAccount authenticated")
request = ProtoOASymbolsListReq()
request.ctidTraderAccountId = credentials["AccountId"]
request.includeArchivedSymbols = False
deferred = client.send(request)
deferred.addCallbacks(sendProtoOASubscribeSpotsReq, onError)
def applicationAuthResponseCallback(result):
print("\nApplication authenticated")
request = ProtoOAAccountAuthReq()
request.ctidTraderAccountId = credentials["AccountId"]
request.accessToken = credentials["AccessToken"]
deferred = client.send(request)
deferred.addCallbacks(accountAuthResponseCallback, onError)
def onError(client, failure): # Call back for errors
print("\nMessage Error: ", failure)
def disconnected(client, reason): # Callback for client disconnection
print("\nDisconnected: ", reason)
def onMessageReceived(client, message): # Callback for receiving all messages
if message.payloadType in [ ProtoHeartbeatEvent().payloadType, ProtoOAAccountAuthRes().payloadType, ProtoOAApplicationAuthRes().payloadType, ProtoOASymbolsListRes().payloadType, ProtoOAGetTrendbarsRes().payloadType]:
return
m = Protobuf.extract(message)
with open('test.txt','a') as file:
file.write(str(m))
def connected(client): # Callback for client connection
print("\nConnected")
request = ProtoOAApplicationAuthReq()
request.clientId = credentials["ClientId"]
request.clientSecret = credentials["Secret"]
deferred = client.send(request)
deferred.addCallbacks(applicationAuthResponseCallback, onError)
# Setting optional client callbacks
client.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)
# Starting the client service
client.startService()
# Run Twisted reactor, we imported it earlier
reactor.run()
And what i'm getting as response is this
ctidTraderAccountId: 22367191
symbolId: 2
bid: 118347
ask: 118349
trendbar {
volume: 234
period: M1
low: 118321
deltaOpen: 6
deltaHigh: 42
utcTimestampInMinutes: 27971363
}
Is there any way to show delta.close? Thanks in advance.
PanagiotisChar
09 Mar 2023, 09:06
Hi there,
Close is always equal to the bid price. So delta is always 0.
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar