Skip to content

Commit de9ecd7

Browse files
committed
connect to datasource working
1 parent ef26c16 commit de9ecd7

File tree

3 files changed

+131
-108
lines changed

3 files changed

+131
-108
lines changed

src/clojure/core.clj

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
1-
(ns clj-dde.core
2-
[:import
3-
[com.pretty_tools.dde.client DDEClientConversation]
4-
[java.util Date]])
5-
6-
(System/getProperty "java.library.path")
7-
8-
(Date.)
9-
10-
11-
;; instantiate a DDEClientConversation
12-
13-
(def conversation (DDEClientConversation.))
14-
15-
16-
;; ** DDEClientConversation member functions:
17-
18-
(.connect conversation "excel" "sheet1")
19-
20-
(.disconnect conversation)
21-
22-
(.execute conversation "some-string")
23-
24-
(.execute conversation some-byte)
25-
26-
(.poke conversation "some-item" "some-data")
27-
28-
(.poke conversation "some-item" byte-data some-clipboardformat)
29-
30-
(.request conversation "some-item")
31-
32-
(.startAdvice conversation "some-item")
33-
34-
(.stopAdvice conversation "some-item")
35-
36-
(.getService conversation)
37-
38-
(.getTopic conversation)
39-
40-
(.getTimeout conversation)
41-
42-
(.setTimeout conversation)
43-
44-
(.getEventListener conversation)
45-
46-
(.setEventListener conversation an-event-listener)
47-
48-
(.checkConversation conversation)
49-
50-
(.fireEventOnDisconnect conversation)
51-
52-
(.fireEventOnAdvData conversation)
53-
54-
55-
; #(com.pretty_tools.dde.client.DDEClientConversation. %)
56-
57-
; (.. conversation connect setTimeout 2000)
58-
; (.. conversation connect "Excel" "Sheet1")
59-
60-
61-
#_(defn get-a-conversation
62-
[]
63-
(DDEClientConversation. com.pretty_tools.dde.client.DDEClientConversation))
64-
65-
1+
(ns clj-dde.core
2+
[:import
3+
[com.pretty_tools.dde.client.DDEClientConversation]
4+
[com.pretty_tools.dde.client.DDEClientEventListener]
5+
[com.pretty_tools.dde ClipboardFormat]
6+
[com.pretty_tools.dde DDEException]
7+
[com.pretty_tools.dde DDEMLException]
8+
[java.util Date]])
9+
10+
(System/getProperty "java.library.path")
11+
12+
(Date.)
13+
14+
15+
;; instantiate a DDEClientConversation
16+
17+
;; ** DDEClientConversation member functions:
18+
19+
; (.connect conversation "excel" "sheet1")
20+
; (.request conversation "R1C1")
21+
; (.poke conversation "R1C1", "new val")
22+
23+
(def mt4-conv (DDEClientConversation.))
24+
25+
(.connect mt4-conv "MT4" "BID")
26+
27+
(.startAdvice mt4-conv "EURUSD")
28+
29+
; (.setEventListener mt4-link (DDEClientEventListener))
30+
31+
; void onItemChanged(String topic, String item, String data);
32+
33+
(defn ELOnItemChanged
34+
[]
35+
(reify DDEClientEventListener
36+
(onItemChanged [this topic item data]
37+
(str "onItemChanged: " topic " , " item " , " data " )"))))
38+
39+
(defn ELOnDisconnect
40+
[]
41+
(reify DDEClientEventListener
42+
(onDisconnect [this]
43+
(str "onDisconnect called."))))
44+
45+
(.setEventListener mt4-conv (ELOnItemChanged))
46+
47+
(ELOnItemChanged)
48+
49+
50+
(str "the" "string" "gets")
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+

src/clojure/sandbox.clj

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(.disconnect conversation)
2+
3+
(.execute conversation "some-string")
4+
5+
(.execute conversation some-byte)
6+
7+
(.poke conversation "some-item" "some-data")
8+
9+
(.poke conversation "some-item" byte-data some-clipboardformat)
10+
11+
(.request conversation "some-item")
12+
13+
(.startAdvice conversation "some-item")
14+
15+
(.stopAdvice conversation "some-item")
16+
17+
(.getService conversation)
18+
19+
(.getTopic conversation)
20+
21+
(.getTimeout conversation)
22+
23+
(.setTimeout conversation)
24+
25+
(.getEventListener conversation)
26+
27+
(.setEventListener conversation an-event-listener)
28+
29+
(.checkConversation conversation)
30+
31+
(.fireEventOnDisconnect conversation)
32+
33+
(.fireEventOnAdvData conversation)
34+
35+
36+
; #(com.pretty_tools.dde.client.DDEClientConversation. %)
37+
38+
; (.. conversation connect setTimeout 2000)
39+
; (.. conversation connect "Excel" "Sheet1")
40+
41+
42+
#_(defn get-a-conversation
43+
[]
44+
(DDEClientConversation. com.pretty_tools.dde.client.DDEClientConversation))

src/examples/MyNotes.txt

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,23 @@
1-
** MyNotes.txt **
2-
3-
4-
To connect to two MT4 instances:
5-
6-
this one is free and you don't have to install, just run it.
7-
8-
get it from: http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm
9-
10-
If you open the terminal.exe file in the MT4 root directory with the HEX editor and do a search for MT4 you will find 7 instances. Simply change MT4 to MT1 and the DDE server name will change to MT1. In Excel you just use ='MT1'|BID!EURUSD for example. I can not take credit for this as it was passed to me thru another conversation, but I think it is ok to share.
11-
12-
13-
14-
15-
;; Make Excel a DDE Server
16-
17-
=Excel|[stock.xls]Sheet1!'r2c2'
18-
19-
20-
21-
22-
23-
24-
;; sample program:
25-
26-
DDEClient client;
27-
Conversation conv = null;
28-
byte[] data=null;
29-
client = DDEClient.getInstance();
30-
try {
31-
conv = client.connect("MT4", "BID");
32-
System.out.println("Connected to MT4");
33-
String Topic= conv.getTopic();
34-
data=conv.request("EURUSD", 5000);
35-
String sEURUSD = new String(data);
36-
System.out.println("EURUSD value: " + sEURUSD);
37-
} catch(DDEException e) {
38-
System.out.println(e);
39-
} finally {
40-
// disconnect in a finally clause
41-
try {conv.close();} catch (Exception e) {}
42-
}
43-
client.close();
1+
** MyNotes.txt **
2+
3+
4+
To connect to two MT4 instances:
5+
6+
this one is free and you don't have to install, just run it.
7+
8+
get it from: http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm
9+
10+
If you open the terminal.exe file in the MT4 root directory with the HEX editor and do a search for MT4 you will find 7 instances. Simply change MT4 to MT1 and the DDE server name will change to MT1. In Excel you just use ='MT1'|BID!EURUSD for example. I can not take credit for this as it was passed to me thru another conversation, but I think it is ok to share.
11+
12+
13+
14+
15+
;; Make Excel a DDE Server
16+
17+
=Excel|[stock.xls]Sheet1!'r2c2'
18+
19+
20+
21+
https://github.com/cemerick/clojure-type-selection-flowchart
22+
23+

0 commit comments

Comments
 (0)