파이썬 키움증권 open api 분할매매 수식구하기
장시작 또는 현재가에서 지정한 투자금액에 따라 매수는 피라미드형, 매도는 역피라미드형으로 매매주문하기
#코스피 #5,000 ~ 10,000 = 10원 #10,000 ~ 50,000 = 50원 #50,000 ~ 100,000 = 100원 #100,000 ~ 500,000 = 500원 #500,000 ~ 1,000,000 = 1000원 #코스닥 #5,000 ~ 10,000 = 10원 #10,000 ~ 50,000 = 50원 #50,000 ~ 100원단위 order_money=5100 #현재가 max_order_money=1000000 #총매매금액 mom_ea=int(round(max_order_money/order_money,0)) #총매매금액 나누기 현재가 = 총매매 수량 print("총매매 주식수 : ",mom_ea) sellbuy_ea=[] rate_sb=0.027 for i in range(0,10): sellbuy_ea.append(int(mom_ea*rate_sb)) rate_sb = (rate_sb + 0.008) * 1.115 temp=0 for i in range(0,10): temp=temp+sellbuy_ea[i] temp1=order_money*temp print("실투자수량:",temp,"실투자금액:",temp1) print("매수호가주문수량",sellbuy_ea) #0.5% ~ 10%까지의 매수호가/매도호가 생성 sell_m=[] buy_m=[] rate_v=0.005 for i in range(0,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) ## 상한가 구하기 highlow = 0.28 max_money=order_money + order_money * highlow min_money=order_money - order_money * highlow #print(order_money,max_money,min_money) ## 상한가 자리수에 따라 반올림하고 정수화하기 if order_money < 1000: max_money = int(round(order_money + order_money * highlow, 0)) min_money = int(round(order_money - order_money * highlow, 0)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) if order_money < 5000: max_money = int(round(order_money + order_money * highlow, -1)) min_money = int(round(order_money - order_money * highlow, -1)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) elif order_money < 10000: max_money = int(round(order_money + order_money * highlow, -1)) min_money = int(round(order_money - order_money * highlow, -1)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) elif order_money < 50000: max_money = int(round(order_money + order_money * highlow, -2)) min_money = int(round(order_money - order_money * highlow, -2)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) elif order_money < 100000: max_money = int(round(order_money + order_money * highlow, -3)) min_money = int(round(order_money - order_money * highlow, -3)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) elif order_money < 500000: max_money = int(round(order_money + order_money * highlow, -4)) min_money = int(round(order_money - order_money * highlow, -4)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money) elif order_money < 1000000: max_money = int(round(order_money + order_money * highlow, -5)) min_money = int(round(order_money - order_money * highlow, -5)) print('현재가:',order_money,'상한가:',max_money,'하한가:',min_money)