Hi Zoringer. I'm just wondering whether you ever got this to work?
I've been trying and I'm having the same issues, and I cant get Amibroker to see the server I am creating.
I took some snippets of your code and modified it a little to get the websochet data;
import websocket
import json
import pandas as pd
from datetime import datetime
import win32ui, dde
from pywin.mfc import object as O_
import time
def on_open(_wsa):
data = dict(
method='SUBSCRIBE',
id=1,
params=["btcusdt@kline_1m"]
)
_wsa.send(json.dumps(data))
def on_message(_wsa, data):
try:
df = pd.read_json(data, orient='index')
timeOfCall = (df[0]['E'])
normTimeOfCall = str(datetime.fromtimestamp(timeOfCall / 1000))
timeval= normTimeOfCall
data2 = (df[0]['k'])
df2 = pd.DataFrame(data2, index=[0])
sym= df2['s'][0]
op= (df2['o'][0])
hi= (df2['h'][0])
lo= (df2['l'][0])
cl= (df2['c'][0])
vol= (df2['v'][0])
serverCreator(timeval,sym,op,hi,lo,cl,vol)
except Exception as e:
print(f'Error on Message: {e}')
class DDETopic(O_.Object):
def __init__(self, topicName):
self.topic = dde.CreateTopic(topicName)
O_.Object.__init__(self, self.topic)
self.items = {}
def setData(self, itemName, value):
try:
self.items[itemName].SetData(value)
print(itemName+" "+value)
except KeyError:
print("error ")
if itemName not in self.items:
self.items[itemName] = dde.CreateStringItem(itemName)
self.topic.AddItem( self.items[itemName] )
self.items[itemName].SetData( str(value) )
serv_name='binance_'
ddeServer = dde.CreateServer()
ddeServer.Create(serv_name)
def serverCreator(timeval,sym,op,hi,lo,cl,vol):
t_name=sym
#or serv_name+"|"+t_name+"!"+'Open' not working
ddeTopic1 = DDETopic(t_name+'!'+'Open')
ddeTopic2 = DDETopic(t_name+'!'+'High')
ddeTopic3 = DDETopic(t_name+'!'+'Low')
ddeTopic4 = DDETopic(t_name+'!'+'Last')
ddeTopic5 = DDETopic(t_name+'!'+'Time')
ddeTopic6 = DDETopic(t_name+'!'+'Volume')
ddeServer.AddTopic(ddeTopic1)
ddeServer.AddTopic(ddeTopic2)
ddeServer.AddTopic(ddeTopic3)
ddeServer.AddTopic(ddeTopic4)
ddeServer.AddTopic(ddeTopic5)
ddeServer.AddTopic(ddeTopic6)
while True:
ddeTopic1.setData(serv_name+'|'+t_name + '!' + 'Open', op)
ddeTopic2.setData(serv_name+'|'+t_name + '!' + 'High', hi)
ddeTopic3.setData(serv_name+'|'+t_name + '!' + 'Low', lo)
ddeTopic4.setData(serv_name+'|'+t_name + '!' + 'Last', cl)
ddeTopic5.setData(serv_name+'|'+t_name + '!' + 'Time', timeval)
ddeTopic6.setData(serv_name+'|'+t_name + '!' + 'Volume', vol)
win32ui.PumpWaitingMessages(0, -1)
print('running')
time.sleep(3)
def run():
stream_name = 'some_name' # this is not important
wss = 'wss://stream.binance.com:9443/ws/%s' % stream_name
wsa = websocket.WebSocketApp(wss, on_message=on_message, on_open=on_open)
wsa.run_forever()
print("Opening Binance Websockets")
if __name__ == '__main__':
run()
I am pulling the values from the console. I've even tried concatenating the lines in setData() to include 'binance_' but it really makes no difference.

As far as I can see, I'm configuring things how it is specified in the documentation.
Did you manage to get the DDE server to work, or did you explore the ODBC/SQL solution kindly suggested by @Cougar?
I'm not very effective at coding and I'm wondering how many (more) hours I should invest in trying to learn how SQL works or whether I'm on a fools errand with this whole project.
What I'm working with for now, which at least works, is doing a REST API call once every 60 minutes. I call all of the symbols in loop (I call about 30 symbols per loop, and run about 25 loops in paralell lanuched as a background process from batch). It takes about 35 seconds to get about 750 CSV files, which I then import via ASCII using the batch importer, which takes another 30 seconds or so.
So one of my loops would be something like this;
import pandas as pd
import KlineCallLoopMaster as looper
dfUSDT=pd.read_csv("C:\Program Files\AmiBroker\Databases\Crypto\WatchLists\BinancePairsUSDT.tls",header=None)
for i in range(224,252):
sym = (dfUSDT[0][i])
looper.dataCaller(sym, "5m", 200)
print("Symbol= " + (str(sym)))
with the KlineCallLoopMaster.py as ;
from binance.spot import Spot
import pandas as pd
import logging
from datetime import datetime
def dataCaller(sym,int,lim):
cols = ['ticker', 'date', 'time', 'open', 'high', 'low', 'close', 'vol']
dfCols = pd.DataFrame(columns=cols)
dfCols.to_csv("C:\Program Files\AmiBroker\Brokers\Binance\Data\symbolcsv\klines\csvFiles\\"+sym+".Binance", index=False,header=True, mode="w")
Client = Spot(<apiKey>,<apiSecret>)
klines = Client.klines(symbol=sym, interval=int, limit=lim)
df = pd.DataFrame(klines)
date = []
for i in range(len(df)):
timestamp = (df[6][i])
normTime = str(datetime.fromtimestamp((timestamp +1) / 1000))
indSpace = normTime.find(' ')
dateVal = (normTime[:indSpace])
date.append(dateVal)
time = []
for i in range(len(df)):
timestamp = (df[6][i])
normTime = str(datetime.fromtimestamp((timestamp +1) / 1000))
indSpace = normTime.find(' ')
timeVal = (normTime[indSpace + 1:])
time.append(timeVal)
dfKlines = pd.DataFrame(df)
dfKlines['date'] = date
dfKlines['time'] = time
titled_columns = {'ticker':sym,
'date': dfKlines['date'],
'time': dfKlines['time'],
'open': df[1],
'high': df[2],
'low': df[3],
'close': df[4],
'vol': df[5]
}
dfKlines2 = pd.DataFrame(titled_columns)
dfKlines2.to_csv("C:\Program Files\AmiBroker\Brokers\Binance\Data\symbolcsv\klines\csvFiles\\"+sym+".Binance", index=False,header=False, mode="a")
(Note I'm using the candle close time, instead of the open, I think I probably need to change that. at timestamp=(df[6][i]) you would change the 6 to a 0, as Binance places the open time in the first key of the returned data.
Yeah, its ugly, but it works. Your signals are going to be a minute late each time, so you might want to think about what time frame you want to trade on.