대신증권 매수 매도
DB CAFE
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
1 주의사항[편집]
API 사용시에 문자열, 정수형, char 타입을 정확하게 지정해야 함. 파이썬에서 char타입으로 값을 넘겨주려면 ord("1") 같이 사용
2 모듈 정보[편집]
- CpTrade.CpTdUtil: 계좌 정보 획득
- CpTrade.CpTd6033: 계좌 종목 정보 조회
- CpTrade.CpTd0311: 매수, 매도
- Dscbo1.StockJpBid2: 호가 조회
- CpTrade.CpTd5341: 체결 내역 확인
3 주문 체결 실시간 처리 예제[편집]
import win32com.client
instCpTdUtil = win32com.client.Dispatch("CpTrade.CpTdUtil")
instCpTd0311 = win32com.client.Dispatch("CpTrade.CpTd0311")
instCpTdUtil.TradeInit()
accountNumber = instCpTdUtil.AccountNumber[0]
instCpTd0311.SetInputValue(0, 2)
instCpTd0311.SetInputValue(1, accountNumber)
instCpTd0311.SetInputValue(3, 'A003540')
instCpTd0311.SetInputValue(4, 10)
instCpTd0311.SetInputValue(5, 13000)
instCpTd0311.BlockRequest()
4 현재가 조회[편집]
5 실거래 매수[편집]
import sys
from PyQt5.QtWidgets import *
import win32com.client
from pywinauto import application
import time
import pandas as pd
import os
g_instCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
g_instCpStockCode = win32com.client.Dispatch("CpUtil.CpStockCode")
g_instCpTdUtil = win32com.client.Dispatch("CpTrade.CpTdUtil")
g_instCpTd0311 = win32com.client.Dispatch("CpTrade.CpTd0311")
bConnect = g_instCpCybos.IsConnect
if (bConnect == 1):
print("PLUS가 정상적으로 연결되어 있음")
else:
print("PLUS 연결시도 중")
app = application.Application()
app.start("C:\CREON\STARTER\coStarter.exe //prj:cp /id:?? /pwd:?? /pwdcert:??/autostart")
time.sleep(20)
#CpEvent: 실시간 이벤트 수신 클래스
class CpEvent:
def set_params(self, client, name, caller):
self.client = client #Cp 실시간 통신 object
self.name = name #서비스가 다른 이벤트를 구분하기 위한 이름
self.caller = caller #callback을 위해 보관
def OnReceived(self):
pbData = {}
#실시간 종목검색 감시처리
if self.name == 'cssalert':
pbData['전략ID'] = self.client.GetHeaderValue(0)
pbData['감시일련번호'] = self.client.GetHeaderValue(1)
code = pbData['code'] = self.client.GetHeaderValue(2)
pbData['종목명'] = name = g_instCpStockCode.CodeToName(code)
inoutflag = self.client.GetHeaderValue(3)
if (ord('1') == inoutflag):
pbData['INOUT'] = '진입'
pbData['시각'] = self.client.GetHeaderValue(4)
pbData['현재가'] = self.client.GetHeaderValue(5)
time.sleep(0.01)
#############################################################
# 매수주문
# 주문 초기화
initCheck = g_instCpTdUtil.TradeInit(0)
if (initCheck != 0):
print("주문 초기화 실패")
exit()
# 주식 매수 주문
acc = g_instCpTdUtil.AccountNumber[0] # 계좌번호
accFlag = g_instCpTdUtil.GoodsList(acc, 1) # 주식상품 구분
print(acc, accFlag[0])
g_instCpTd0311.SetInputValue(0, "2") # 2: 매수
g_instCpTd0311.SetInputValue(1, acc) # 계좌번호
g_instCpTd0311.SetInputValue(2, accFlag[0]) # 상품구분 - 주식 상품 중 첫번째
g_instCpTd0311.SetInputValue(3, pbData['code']) # 종목코드
g_instCpTd0311.SetInputValue(4, 1) # 매수수량
g_instCpTd0311.SetInputValue(5, pbData['현재가']) # 주문단가
g_instCpTd0311.SetInputValue(7, "0") # 주문 조건 구분 코드, 0: 기본 1: IOC 2:FOK
g_instCpTd0311.SetInputValue(8, "01") # 주문호가 구분코드 - 01: 보통
# 매수 주문 요청
g_instCpTd0311.BlockRequest()
rqStatus = g_instCpTd0311.GetDibStatus()
rqRet = g_instCpTd0311.GetDibMsg1()
print("통신상태", rqStatus, rqRet)
if rqStatus != 0:
print("통신상태:", rqStatus, rqRet)
elif (ord('2') == inoutflag):
pbData['INOUT'] = '퇴출'
#pbData['시각'] = self.client.GetHeaderValue(4)
#pbData['현재가'] = self.client.GetHeaderValue(5)
self.caller.checkRealtimeStg(pbData)