주식 자동매매 시스템

파이썬을 이용한 주식 자동매매 시스템

이미지
파이썬을 이용한 주식 자동매매 시스템 INDEX 환경구축 키움증권 API - 연결테스트 키움증권 API - 계좌정보 조회 키움증권 API - 주문 키움증권 API - 종목정보 가져오기 포트폴리오 - 종목, 업종별 자산 포트폴리오 한국투자증권 API API reference 키움 OpenAPI+ 개발가이드 한국투자증권 OpenAPI 다운로드 및 가이드 Design https://www.design-seeds.com/in-nature/succulents/cacti-color-2/ https://create.piktochart.com/dashboard

SPRING 프로젝트 만들기

GitHub:setting

  • Building Workspace
    • Create Web Project
    • Create new project > Dynamic Web Project
    • Add Spring Project Nature
    • Spring > add Spring project Nature 
  • Maven Dependency
    • pom.xml
    • <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>ozo</groupId>
       <artifactId>ozo</artifactId>
       <version>0.0.1-SNAPSHOT</version>
       <packaging>war</packaging>
       <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
         <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
          <configuration>
           <release>9</release>
          </configuration>
         </plugin>
         <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.0.0</version>
          <configuration>
           <warSourceDirectory>web</warSourceDirectory>
          </configuration>
         </plugin>
        </plugins>
       </build>
       </project>
      
    •  properies 추가
    • maven에서 관리할 library들의 version 명시
      <properties>
       <java-version>1.8</java-version>
       <org.springframework-version>4.2.5.RELEASE</org.springframework-version>
       <org.aspectj-version>1.6.5</org.aspectj-version>
       <org.slf4j-version>1.7.18</org.slf4j-version>
      </properties>
    • 사용할 library <dependencies> 에 추가 
    • maven > update project


  • Oracle Database 연동 환경 Setting
  • oracle은 무료가 아니라서 ojdbc6.lib WEB_INF/lib 에 넣어줘야 됌
  • web.xml
  • <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>ozo</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    
     <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/config/spring-view.xml</param-value>
      </init-param>
     </servlet>
     <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>*.do</url-pattern>
     </servlet-mapping>
    
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
    
     <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/spring.xml</param-value>
     </context-param>
    
     <filter>
      <filter-name>enc</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
       <param-name>encoding</param-name>
       <param-value>EUC-KR</param-value>
      </init-param>
     </filter>
    
     <filter-mapping>
      <filter-name>enc</filter-name>
      <url-pattern>/*</url-pattern>
     </filter-mapping>
    
     <listener>
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
     </listener>
     <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/config/log4j.properties</param-value>
     </context-param>
    
    </web-app>
  • spring.xml
  • <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:context="http://www.springframework.org/schema/context" 
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx" 
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           ">
    
      <bean id="exeptionResolver" 
      class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
       <property name="exceptionMappings">
        <props>
         <prop key="org.springframework.dao.DuplicateKeyException">
          error
         </prop>
        </props>
       </property>
      </bean>
    </beans>
    
  • spring-view.xml
  • <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:context="http://www.springframework.org/schema/context" 
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx" 
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           ">
     <context:component-scan base-package="com.*"/>
     <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
     <tx:annotation-driven transaction-manager="txManager"/> 
     
      <!-- ViewResolver -->
      <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix" value="/view/"/>
       <property name="suffix" value=".jsp"/>
       <property name="order" value="0"/>
      </bean>
      <!-- 다국어 처리 -->  
      <bean id="messageSource" 
      class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basenames">
        <list>
         <value>messages/messages</value>
        </list>
       </property>
      </bean> 
      <!-- File Upload -->
      <bean id="multipartResolver"
         class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         <property name="maxUploadSize" value="500000000"/>
     </bean>   
         <!-- 1. Database Setting -->
      <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
       <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
       <property name="url" value="jdbc:oracle:thin:@70.12.114.149:1521:xe"/>
       <property name="username" value="system"/>
       <property name="password" value="111111"/>
      </bean>
      <!-- 2. Transaction Setting -->
      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <property name="dataSource" ref="dataSource"/>
      </bean>  
      <!-- 3. MyBatis Setting -->
      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
       <property name="dataSource" ref="dataSource"/>
       <property name="configLocation" value="classpath:com/config/mybatis.xml"/>
      </bean>
      <!-- 4. Spring Mybatis Connect -->
      <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
       <constructor-arg ref="sqlSessionFactory"/>
      </bean>
      <!-- 5. Mapper Setting -->
      <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       <property name="basePackage" value="com.hw.mapper"/>
      </bean>
    </beans>
    
    • View Resolver
    • : view resolver 
      ( jsp 이름만 return 하면, 앞뒤에 /web../... 붙여주는역할)
      ViewResolver : File Upload : Database 연동
      (Mybatis : jdbc 연동할 때 반복되는 connection, rs 소스 줄일 수 있음)
    • 다국어 처리


이 블로그의 인기 게시물

Linux에서 CSV파일 사용방법

R에서 외부 데이터 이용하기 (Excel, csv)

[R 함수] aggregate, apply 사용 방법