-
Notifications
You must be signed in to change notification settings - Fork 17
/
get_stock_dde.py
44 lines (37 loc) · 1.4 KB
/
get_stock_dde.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import PyWinDDE
import datetime
import sys
import time
#f1 = open("data/stock_02.csv","a")
f2= open("data/stock_03.csv","a")
def recTickData(value,item):
out_string = "%s;%s"%(value,datetime.datetime.now())
print out_string
f1.write(out_string + "\n")
def recNextTickData(value,item):
out_string = "%s;%s"%(value,datetime.datetime.now())
print out_string
f2.write(out_string + "\n")
while True:
try:
dde = PyWinDDE.DDEClient("XQKGIAP","Quote")
break
except:
e = sys.exc_info()[0]
print "Error: %s, try to connect 10 mins later."%e
time.sleep(600)
print "Connect to DDE server again..."
print "Connected to DDE server, start listening..."
# 股票/期貨代號,名稱,時間,買進,賣出,成交,單量,總量,高點,低點,開盤
#dde.advise("FIMTX02.TF-ID,Name,Time,Bid,Ask,Price,Volume,TotalVolume,High,Low,Open",callback = recTickData)
dde.advise("FIMTX03.TF-ID,Name,Time,Bid,Ask,Price,Volume,TotalVolume,High,Low,Open",callback = recNextTickData)
PyWinDDE.WinMSGLoop()
#Test cases
#dde.advise("0050.TW-ID,Name,Time,Bid,Ask,Price,PriceChange,PriceChangeRatio,Amplitude,AvgPrice")
#dde.advise("TSE.TW-PreClose",callback = recTickData)
#dde.advise("FITX03.TF-PreClose",callback = recTickData)
#dde = PyWinDDE.DDEClient("HTS","KS")
#dde = PyWinDDE.DDEClient("CATDDE","FUTOPT<FO>TXFB6 ")
#dde.advise("CurPrice,TickVol,Diff,DiffRate,Open,High,Low")
#dde.advise("CurPrice")