Last active
September 24, 2015 13:26
-
-
Save darth30joker/2a40d202a34549a3e802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from os.path import getsize | |
import struct | |
class CDate: | |
def __init__(self, year=0, month=0, day=0) | |
self.year = year | |
self.month = month | |
self.day = day | |
class CTdxDayData: | |
def __init__(self): | |
self.date = 0 | |
self.open = 0 | |
self.high = 0 | |
self.low = 0 | |
self.close = 0 | |
self.amount = 0 | |
self.vol = 0 | |
self.unknown = 0 | |
class CStockDayData: | |
def __init__(self, szStockNum): | |
self.pFileData = "" | |
tdx_path = "E:\\Program Files\\new_ztzq_v6\\Vipdoc\\" | |
szFilePath=tdx_path+ "sh\\lday\\sh" +szStockNum+ ".day" | |
if szStockNum[0] in ['0', '3']: | |
szFilePath=tdx_path+ "sz\\lday\\sz" +szStockNum+ ".day" | |
self.nFileSize = getsize(szFilePath) | |
with open(szFilePath, 'rb') as f: | |
self.pFileData = f.read() | |
def getClosePrice(self, date): | |
fClosePrice = 0 | |
szDate = "%4d%02d%02d" % (date.year, date.month, date.day) | |
nDate = int(szDate) | |
size = 32 # sizeof(CTdxDayData) | |
buf_len = | |
data = CTdxDayData() | |
for i in range(len(self.pFileData) / size) | |
p = self.pFileData[i*size:(i+1)*size] | |
data.date,data.open,data.high,data.low,data.close,data.amount,data.vol,data.unknown = struct.unpack("5if2i",p) | |
if( data.date==nDate ): | |
fClosePrice = data.close | |
break | |
return fClosePrice | |
szStockNum = raw_input("input Stock Numer: ") | |
sdd = CStockDayData(szStockNum) | |
print sdd.szStockNum | |
print sdd.pFileData[0:10] | |
close = sdd.getClosePrice(CDate(2012, 10, 10)) | |
print close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment