ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 파이썬+사이보스플러스
    주식/시스템트레이딩 2016.10.28 19:29

    제가 설치한 순서를 남겨 놓습니다. ^^;
    소스는 https://wikidocs.net/3406

    환경
    윈도우10(64비트) , 아나콘다(파이썬 3.5 32비트) , PyCharm , SQLite 32비트(DB) , 
    사이보스플러스


    아나콘다 https://www.continuum.io/downloads (파이썬 3.5 32비트) 
    파이참(PyCharm) https://www.jetbrains.com/pycharm/download (커뮤니티 설치)
    SQLite http://sqlitebrowser.org (32비트)


    CP(사이보스플러스)와 파이참 모두 관리자 권한으로 실행.

    subDS.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
    ######################################################################################################
    ########## fileName: subDS.py
    ######################################################################################################
     
    from pandas import DataFrame
    import win32com.client
    import win32com
     
    ### stockChart ###
    def subStockChart(m_Code, m_NumHist):                                   ### 1
    #def subStockChart(m_Code, m_FromDate, m_ToDate):                           ### 2
        stockChart = win32com.client.Dispatch("CpSysDib.StockChart")
        stockChart.SetInputValue(0, m_Code)    # 종목 코드
        stockChart.SetInputValue(1, ord('2'))    # 요청 구분 (개수로 요청)  ### 1
        #stockChart.SetInputValue(1, ord('1'))    # 요청 구분 (날짜로 요청)      ### 2
        #stockChart.SetInputValue(2, m_ToDate)  # 시작일자                       ### 2
        #stockChart.SetInputValue(3, m_FromDate)    # 끝일자                     ### 2
        stockChart.SetInputValue(4, m_NumHist)     # 요청개수                ### 1
        stockChart.SetInputValue(5, [0,2,3,4,5]) # 날짜, 시가, 고가, 저가, 종가
        stockChart.SetInputValue(6, ord('D'))    # 차트 구분 (일)
     
        ## 데이터 호출
        stockChart.BlockRequest()
        num = stockChart.GetHeaderValue(3)
        data=[]
        for i in range(num):
            tempData ={}
            tempData['Date']=(stockChart.GetDataValue(0,i))
            tempData['Open']=float(format(stockChart.GetDataValue(1,i), '.2f')) # 선물값이 오류수정
            tempData['High']=float(format(stockChart.GetDataValue(2,i), '.2f'))
            tempData['Low']=float(format(stockChart.GetDataValue(3,i), '.2f'))
            tempData['Close']=float(format(stockChart.GetDataValue(4,i), '.2f'))
            data.append(tempData)
     
        ## dataframe으로 전환
        resultDf = DataFrame(data, columns=['Date''Open''High''Low''Close'])
        return resultDf
     
    cs

    practice_1_5_1_02.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    ####################################################################################################
    ### file Name: practice_1_5_1_02.py
    ####################################################################################################
     
    import sqlite3 as sq
    import pandas.io.sql as pd_sql
    from pandas import DataFrame
    from subDS import subStockChart # 위에 작성한 subStockChart 불러오기
     
    if __name__ == "__main__":
        ### DB 연결
        conn = sq.connect("testPython.db")
        cur = conn.cursor()
        ### 자료가져오기
        code ='A005930' # 삼성전자 종목코드
        numHist =100 # 과거 100일치 데이터
        df=subStockChart(code, numHist)
        print(df)
        tableName = 't_' + code
        pd_sql.to_sql(df, tableName, conn, if_exists='append', index=False)
        conn.close()
    cs




    댓글 0

Designed by Tistory.

티스토리 툴바