Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not make DDE connection using python. win32ui appears not working

Tags:

dde

I am new to Python (version 2.7). I have been using for a long time some excel workbooks that uses DDE function to capture "real-time market data" - that is served by one Market Data Provider ("Matriks", if matters).

In a bit to simplify my overall process flow, I decided to bypass this excel workbook thing for data capture, and instead, I decided to use python codes to perform the same task.

The problem is that, 1) I get "error: The server could not be created" when I run the code (provided below) using Pythonwin.

2) and I get "ImportError: This must be an MFC application - try 'import win32ui' first" when I run this very simple code using IDLE.

(and of course, I downloaded and run win32ui.)

Any help is appreciated.

# DDE code
# excel equivalent of this code is: =MTX|DATA!EURUSD.SON
import win32ui
import dde

s=dde.CreateServer()
s.Create("MTX")
c=dde.CreateConversation(s)
c.ConnectTo("DATA","SON")
c.Connected()
c.Request("EURUSD")

# returns
# Traceback (most recent call last):
#  File "C:\IQTrader\_script\_obj\DDEClient.py", line 12, in <module>
#   import dde
# ImportError: This must be an MFC application - try 'import win32ui' first
like image 819
Aykut Saribiyik Avatar asked Jan 17 '26 18:01

Aykut Saribiyik


2 Answers

The issue is resolved. The very basic reason for the error is the pywin module.

For those facing with the same problem: 1.Delete pythonwin and pywin32_system32 folderes entirely (presumably under C:\Python27\Lib\site-packages)

2.Check your pywin32 version; it should be 214 (not 218) for those using v2.7

3.Download pywin32-214.win32-py2.7 from appropriate resources (one is this: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ )

4.Everything should be fine.

like image 117
Aykut Saribiyik Avatar answered Jan 21 '26 09:01

Aykut Saribiyik


I had a similar problem. I had to:

  1. uninstall Python 2.7 64-bit
  2. install Python 2.7 32-bit
  3. use the pywin32 version 214
  4. Run cmd.exe as administrator so that the c.ConnectTo() connects successfully

However, I am still having the weird problem that I must have Excel open at the same time with a cell holding the value =MTX|DATA!EURUSD.SON for the python script to return a valid quote. Otherwise, I just get "N/A" as the return value.

@Aykut did you run into this issue as well?

like image 29
CCL Avatar answered Jan 21 '26 08:01

CCL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!