Skip to content
조회 수 2352 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬 키움증권 open api 분할매매 주문하기

 

 


import os
import json
import time
import sys
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
sys.path.insert(0, '"H:/python/kiwoomapi/anaconda3/PACKAGE_DIR')
from 키움증권.config.errCode import *

from pykiwoom.kiwoom import *
kiwoom = Kiwoom()
kiwoom.CommConnect(block=True)

TR_REQ_TIME_INTERVAL = 0.2

# 주식계좌
accounts = kiwoom.GetLoginInfo("ACCNO")
stock_account = accounts[0]

# 피라미드 주문
account_num = "계좌번호"

item_num = "128540"                 # 종목명

order_money=5250                 #현재가를 변수에 담기
max_order_money=1500000
mom_ea=int(max_order_money/order_money)                             # 총매매금액 나누기 현재가 = 총매매 수량
rate=0.01
합계=0
sellbuy_ea=[]

print("총매매 주식수 : ", mom_ea)
print("총매매금액 : ", max_order_money)
print("총매매금액 : %s, 현재가 : %s, 총수량 %s" %(max_order_money,order_money,mom_ea))
for i in range(0,10):
    sellbuy_ea.append(int(mom_ea * rate))
    rate = rate + 0.02
    합계 = int(int(mom_ea * rate) + 합계)

print("총매매 주식수 : ", mom_ea)
print("총매매금액 : ", max_order_money)

print(order_money*합계,sellbuy_ea)

# 0.5% ~ 10%까지의 매수호가/매도호가 생성
sell_m = []
buy_m = []
rate_v = 0.005
for i in range(0, 40):  ## 20 = 10%에 대한 매도호가 생성 / 40 = 20%에 대한 매도호가 생성
    sell_m.append(order_money + (order_money * rate_v))
    buy_m.append(order_money - (order_money * rate_v))
    rate_v = rate_v + 0.005
# print("매도호가",sell_m)
# 0.5% ~ 10%까지의 폭

## 호가를 자리수에따라 반올림하면서 정수화 함.
buyQ = []
sellQ = []
for i in range(0, len(buy_m)):
    if buy_m[i] < 1000:
        buyQ.append(int(round(buy_m[i], 0)))
    elif buy_m[i] < 5000:
        buyQ.append(int(round(buy_m[i], -1)))
    elif buy_m[i] < 10000:
        buyQ.append(int(round(buy_m[i], -1)))
    elif buy_m[i] < 50000:
        buyQ.append(int(round(buy_m[i], -2)))
    elif buy_m[i] < 100000:
        buyQ.append(int(round(buy_m[i], -2)))
    elif buy_m[i] < 500000:
        buyQ.append(int(round(buy_m[i], -3)))
    elif buy_m[i] < 1000000:
        buyQ.append(int(round(buy_m[i], -3)))

for i in range(0, len(sell_m)):
    if sell_m[i] < 1000:
        sellQ.append(int(round(sell_m[i], 0)))
    elif sell_m[i] < 5000:
        sellQ.append(int(round(sell_m[i], -1)))
    elif sell_m[i] < 10000:
        sellQ.append(int(round(sell_m[i], -1)))
    elif sell_m[i] < 50000:
        sellQ.append(int(round(sell_m[i], -2)))
    elif sell_m[i] < 100000:
        sellQ.append(int(round(sell_m[i], -2)))
    elif sell_m[i] < 500000:
        sellQ.append(int(round(sell_m[i], -3)))
    elif sell_m[i] < 1000000:
        sellQ.append(int(round(sell_m[i], -3)))
#print("매도호가:", sellQ, "\n매수호가:", buyQ)

print("계좌번호 : %s / 종목번호 : %s\n 주문개수 : %s\n 매수가격 : %s" % (account_num, item_num, sellbuy_ea, buyQ)) #buyQ 40호가 까지 / sellbuy_ea 10개까지)
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[0], buyQ[0], "00", "")
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[1], buyQ[2], "00", "")
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[2], buyQ[4], "00", "")
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[3], buyQ[7], "00", "")
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[4], buyQ[9], "00", "")
kiwoom.SendOrder("피라미드매수", "0101", account_num, 1, item_num, sellbuy_ea[5], buyQ[12], "00", "")
print("지정가 매수완료")


 

 

로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
97 WindowsTip Windows-XP 의 [Prefetch] 폴더에 대하여[C:\WINDOWS\Prefetch] 2013.12.04 24635
96 컴퓨터잡담 자바스크립트 변수를 php로 옮기기 2010.02.03 24987
95 컴퓨터잡담 Excel VBA (1): 셀 선택 및 변수 및 비활성시트 컨트롤하기 3 2011.10.24 25007
94 컴퓨터잡담 무선공유기(AP) 채널간섭 해결하기 file 2013.08.17 25050
93 Excel 엑셀) 피벗테이블 원본데이터 영역범위 수정방법 1 2 file 2012.03.06 25123
92 AutoHotKey [AUTOHOTKEY] FTP 제어 file 2011.02.04 25254
91 컴퓨터잡담 부팅시마다 체크디스크 실행되는 경우 설정방법 2010.08.21 26565
90 Excel [excel] GET.CELL사용법 8 2012.07.16 26621
89 컴퓨터잡담 mysql 접속에러시 재부팅 하는 배치파일 2009.11.24 26693
88 프로세스 Searchindexer.exe 제거하기 1 2011.03.18 27269
87 AutoHotKey [COM] 자바스크립트 / DOM / HTML 웹페이지 컨트롤 3 2011.02.12 27305
86 컴퓨터잡담 MySQL FEDERATED / InnoDB is disabled, myint64.dll 오류 어찌하오리 4 2010.04.19 27709
85 컴퓨터잡담 php 에서 mysql 제어하기 2009.11.28 28200
84 WindowsTip 네트워크 무선연결이 안될 때의 점검 방법 file 2013.03.12 28284
83 컴퓨터잡담 트랜지스터의 종류와 특정 2013.10.12 28534
82 컴퓨터잡담 DIV 라운드박스 쉽게 만들자. 1 1 file 2009.07.24 28592
81 AutoHotKey autohotkey) postmessage mouse control 13 2012.02.22 28639
80 컴퓨터잡담 curl로 다음 자동로그인 가능하다. 2 5 2009.06.30 28914
79 AutoHotKey autohotkey) 편입 변수 4 2012.03.13 28921
78 Excel Excel) 엑셀 콤보박스 대화상자 목록지정하기 2011.12.21 29400
Board Pagination Prev 1 ... 40 41 42 43 44 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소