Skip to content
조회 수 2345 추천 수 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
번호 분류 제목 날짜 조회 수
857 AutoHotKey autohotkey) postmessage mouse control 13 2012.02.22 28635
856 AutoHotKey autohotkey) Virus? 6 2011.12.31 34683
855 AutoHotKey autohotkey) WinSpector spy를 이용한 post,sendmessage Control ID 추출하기 3 file 2012.02.22 10902
854 AutoHotKey autohotkey) 네 코드를 보여, 내가 당신에게서 배우고 싶어요 1 2012.01.08 15115
853 AutoHotKey autohotkey) 런처시스템 3 2012.05.30 14288
852 AutoHotKey autohotkey) 맥어드레스 추출 2 2011.12.21 15083
851 AutoHotKey autohotkey) 스크린세이버 활성화 / 비활성화 시키기. 2012.03.17 8058
850 AutoHotKey autohotkey) 오토핫키에서 자주쓰는 함수모음 2013.10.30 33708
849 AutoHotKey autohotkey) 웹페이지의 프레임 내용보기 & 클릭하기 2011.11.29 15149
848 AutoHotKey autohotkey) 윈도우 ahk_id 추출하기 2 2012.03.06 30093
847 AutoHotKey autohotkey) 파일리스트 가져오기 3 2012.11.26 14992
846 AutoHotKey autohotkey) 편입 변수 4 2012.03.13 28913
845 AutoHotKey autohotkey) 핑테스트 프로그램 1 file 2011.12.31 18952
844 AutoHotKey autohotkey) 화면보호기 실행 전 클릭으로 화면보호 안걸리게 하기 2012.03.15 8870
843 AutoHotKey Autohotkey) 화면보호기(ScreenSaver) On/Off 방법 17 2012.03.16 40707
842 AutoHotKey autohotkey) 화면보호기, 바탕화면 control 창 열기 3 2012.03.17 8365
841 AutoHotKey autohotkey)매월 1일의 요일 구하기 1 2013.01.27 15268
840 AutoHotKey Autohotkey] 키보드 후킹 테스트 file 2018.07.07 9684
839 AutoHotKey autohotkey_L Object 2011.02.21 15392
838 AutoHotKey AutoHotkey_L: Arrays, Debugger, x64, COM, #If expression 3 2011.02.14 21594
Board Pagination Prev 1 2 3 4 5 6 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소