예스스탁
예스스탁 답변
2013-12-10 13:51:50
안녕하세요
예스스탁입니다.
아래식 참고하시기 바랍니다.
주문이후의 동작에 대해서는 저희쪽에서 테스트를 해드리지 않습니다.
작성해 드리는 내용은 가이드이므로 참고하셔서
수정 보완해 사용하시기 바랍니다.
정정주문은 주문유형을 정정할수는 없습니다.
60초뒤에 5호가로 정정하게 작성했습니다.
var OrdeCode;
var BEntryID;
var SExitID;
var BEntryNum;
var SExitNum;
var EntryVol;
var BExitID;
var BExitNum;
function Main_OnStart()
{
Main.MessageLog("시작");
OrdeCode = Main.GetOrderCode(F1.code);
}
function C1_OnRiseSignal(Signal)
{
Main.MessageLog("신호완성/"+Signal.signalKind);
//Buy 신호 발생
if (Signal.signalKind == 1 )
{
//F1종목 미체결주문 모두 취소
var UFnum = A1.GetTheNumberOfUnfills();
for (var i = 0; i < UFnum; i++)
{
A1.SetUnfillIndex(i);
if (A1.Unfill.code == OrdeCode && A1.Unfill.count > 0)
{
A1.OrderCancel(A1.Unfill.orderNum);
Main.MessageLog("미체결주문 모두 취소");
}
}
//잔고셋팅
A1.SetBalanceItem(OrdeCode, 0);
//잔고수량이 0 이상이면
if (A1.Balance.count == 0)
{
//주문수량 : 선물계좌 잔고금액의 50%, 최대 20계약내 산출수량
EntryVol = Math.min(20,Math.floor((A1.GetBalanceETCinfo(30) * 0.5)/(F1.Ask(2)*500000*0.15)));
if (EntryVol >= 1 )
{
BEntryID = A1.OrderBuy(OrdeCode, EntryVol ,F1.Ask(2), 0);
Main.SetTimer(1, 60000);
}
else
{
Main.MessageList("잔고불충분");
}
}
//잔고수량이 0이상이고 매도포지션 보유 중 청산
if (A1.Balance.count > 0 && A1.Balance.position == 1)
{
SExitID = A1.OrderBuy(OrdeCode,A1.Balance.count ,F1.Ask(2), 0);
Main.SetTimer(2, 60000);
}
}
//ExitLong 신호 수신시
if (Signal.signalKind == 2 )
{
//F1종목 미체결주문 모두 취소
var UFnum = A1.GetTheNumberOfUnfills();
for (var i = 0; i < UFnum; i++)
{
A1.SetUnfillIndex(i);
if (A1.Unfill.code == OrdeCode && A1.Unfill.count > 0)
{
A1.OrderCancel(A1.Unfill.orderNum);
Main.MessageLog("미체결주문 모두 취소");
}
}
//잔고셋팅
A1.SetBalanceItem(OrdeCode, 0);
//잔고수량이 0 이상이고 매수포지션 보유중이면 청산
if (A1.Balance.count > 0 && A1.Balance.position == 2)
{
BExitID = A1.OrderSell(OrdeCode,A1.Balance.count ,F1.Bid(2), 0);
Main.SetTimer(3, 60000);
}
}
}
//BEntryID,BExitID 주문이 들어올때 주문번호 저장
function Main_OnOrderResponse(OrderResponse)
{
if (OrderResponse.orderID == BEntryID)
{
BEntryNum = OrderResponse.orderNum;
}
if (OrderResponse.orderID == BExitID)
{
BExitNum = OrderResponse.orderNum;
}
if (OrderResponse.orderID == SExitID)
{
SExitNum = OrderResponse.orderNum;
}
}
//60초 후에 매도5호가로 정정
function Main_OnTimer(nEventID)
{
if (nEventID == 1)
{
A1.SetUnfillOrderNumber(BEntryNum);
BEntryID = A1.OrderReplacePrice(BEntryNum,F1.Ask(5)); //매도5호가로 정정
Main.KillTimer(1);
}
if (nEventID == 2 )
{
A1.SetUnfillOrderNumber(SExitNum);
BExitID = A1.OrderReplacePrice(SExitNum,F1.Ask(5)); //매도 5호가로 정정
Main.KillTimer(2);
}
if (nEventID == 3 )
{
A1.SetUnfillOrderNumber(BExitNum);
BExitID = A1.OrderReplacePrice(BExitNum,F1.bid(5)); //매도 5호가로 정정
Main.KillTimer(3);
}
}
//체결응답 수신시
function Main_OnNotifyFill(NotifyFill)
{
//SExitNum 주무에 대한 체결응답수신될때 잔고가 0이면 매수주문 실행
if (NotifyFill.orderNum == SExitNum)
{
A1.SetBalanceItem(OrdeCode, 0);
if (A1.Balance.count == 0)
{
//주문수량 : 선물계좌 잔고금액의 50%, 최대 20계약내 산출수량
EntryVol = Math.min(20,Math.floor((A1.GetBalanceETCinfo(30) * 0.5)/(F1.Ask(2)*500000*0.15)));
if (EntryVol >= 1 )
{
BEntryID1 = A1.OrderBuy(OrdeCode, EntryVol ,F1.Ask(2), 0);
Main.SetTimer(1, 60000);
}
else
{
Main.MessageList("잔고불충분");
}
}
}
}
즐거운 하루되세요
> gigi 님이 쓴 글입니다.
> 제목 : 수식 문의 드립니다
> 검토 후 수정바랍니다.
◎ 연결선물지수차트에서 완성신호가 발생하면
선물 잔고객체를 세팅하고 포지션상태를 확인합니다.
◎ 완성신호가 무포지션 상태에서 발생한 Buy이면,
1. 혹시 있을지 모를 미체결주문을 확인하여 모두 취소하고
주문수량 : 선물계좌 주문가능금액의 50%, 최대 20계약내 산출수량을
(주문수량계산 로직이 틀린 것 같은데... ㅠ)
주문가격 : 매도2호가로 매수주문합니다.
2. 선물 매도포지션 보유시 발생한 Buy이면 - 매도포지션 전량 청산하고, 매수포지션 주문합니다
① 매도포지션 청산
청산 : 미체결주문을 확인하여 모두 취소하고 청산주문을 집행합니다.
주문수량 : 보유 매도포지션 전량 청산주문
주 문 가 : "매도2호가",
1분 동안 미체결 잔량이 발생하면 "시장가"로 정정 청산주문합니다.
② 청산완료 되어 잔고상 포지션계약수가 0 이 응답확인 후 매수 주문합니다
주문수량 : 변경된 선물계좌 주문가능금액을 재확인하여 금액의 50%, 최대 20계약내 산출수량을
주문가격 : 매도2호가로 매수주문합니다.
◎ 차트에서 ExitLong 완성신호가 발생하면
청산 : 미체결주문을 확인하여 모두 취소하고 청산주문을 집행합니다.
주문수량 : 보유 매수포지션 전량
주 문 가 : "매도2호가", 1분 동안 미체결 잔량이 발생하면 "시장가"로 정정 청산주문합니다.
종목객체 F1 계좌객체 A1 차트객체 C1
var Position;
var OrdeCode;
var BID;
var SID;
var Number ;
var EntryVol
function Main_OnStart()
{
Main.MessageLog("시작");
OrdeCode = Main.GetOrderCode(F1.code);
}
function C1_OnRiseSignal(Signal)
{
Main.MessageLog("신호완성/"+Signal.signalKind);
A1.SetBalanceItem(OrdeCode, 0) ; // 차트 주종목의 잔고 객체 생성
if (A1.Balance.count == 0)
{
Position = 0;
}
A1.SetBalanceItem(OrdeCode, 1) ; // (0: 구분없음, 1:매도, 2: 매수)
if (A1.Balance.count > 0)
{
Position = -1;
}
A1.SetBalanceItem(OrdeCode, 2) ;
if (A1.Balance.count > 0)
{
Position = 1;
}
if (Position == 0 && Signal.signalKind == 1 )
{
Main.MessageLog("매수진입");
// 종목 미체결주문 모두 취소
var UFnum = A1.GetTheNumberOfUnfills();
for (var i = 0; i < UFnum; i++)
{
A1.SetUnfillIndex(i);
if (A1.Unfill.code == OrdeCode && A1.Unfill.count > 0)
{
A1.OrderCancel(A1.Unfill.orderNum);
Main.MessageLog("미체결주문 모두 취소");
}
}
//주문수량 : 선물계좌 잔고금액의 50%, 최대 20계약내 산출수량
EntryVol = Math.floor(A1.GetBalanceETCinfo(30) * 0.5 / OrdeCode.current);
if (EntryVol >= 20)
{
EntryVol = 20 ;
}
if (EntryVol < 1)
{
Main.MessageLog("잔고불충분");
}
A1.OrderBuy(OrdeCode, EntryVol , OrdeCode.Ask(2), 0);
}
if (Position == -1 && Signal.signalKind == 1 ) // buy
{
Main.MessageLog("매도청산후 매수진입");
// 종목 미체결주문 모두 취소
var UFnum = A1.GetTheNumberOfUnfills(); // 미체결리스트 개수
for (var i = 0; i < UFnum; i++)
{
A1.SetUnfillIndex(i);
if (A1.Unfill.code == OrdeCode && A1.Unfill.count > 0)
{
A1.OrderCancel(A1.Unfill.orderNum);
Main.MessageLog("미체결주문 모두 취소");
}
}
// 매도2호 청산주문하고 1분후 시장가로 정정하여 매도청산
BID = A1.OrderBuy (OrdeCode, A1.Balance.count, OrdeCode.Ask(2),0);
// 청산완료확인 후 변경된 잔고금액으로 주문수량결정 진입
A1.SetBalanceItem(OrdeCode, 0) ; // (0: 구분없음, 1:매도, 2: 매수)
if (A1.Balance.count == 0)
{
//주문수량 : 선물계좌 잔고금액의 50%, 최대 20계약내 산출수량
EntryVol = Math.floor(A1.GetBalanceETCinfo(30) * 0.5 / OrdeCode.current);
if (EntryVol >= 20)
{
EntryVol = 20 ;
}
if (EntryVol < 1)
{
Main.MessageLog("잔고불충분");
}
A1.OrderBuy(OrdeCode, EntryVol , OrdeCode.Ask(2), 0);
}
}
if (Position == 1 && Signal.signalKind == 2 ) // ExitLong
{
// 종목 미체결주문 모두 취소
var UFnum = A1.GetTheNumberOfUnfills();
for (var i = 0; i < UFnum; i++)
{
A1.SetUnfillIndex(i);
if (A1.Unfill.code == OrdeCode && A1.Unfill.count > 0)
{
A1.OrderCancel(A1.Unfill.orderNum);
Main.MessageLog("미체결주문 모두 취소");
}
}
//매수2호 매도하고 1분후 시장가로 정정 매도청산
SID == A1.OrderSell(OrdeCode,A1.Balance.count,OrdeCode.Bid(2),0);
}
}
function Main_OnOrderResponse(OrderResponse)
{
if (OrderResponse.orderID == BID)
{
Number = OrderResponse.orderNum;
Main.SetTimer(1, 60000);
}
if (OrderResponse.orderID == SID)
{
Number = OrderResponse.orderNum;
Main.SetTimer(2, 60000);
}
}
function Main_OnTimer(nEventID)
{
if (nEventID == 1)
{
A1.OrderReplacePrice(Number,0); //시장가청산으로 변경
Main.KillTimer(1);
}
if (nEventID == 2)
{
A1.OrderReplacePrice(Number,0); //시장가청산으로 변경
Main.KillTimer(2);
}
}
function Main_OnNotifyFill(NotifyFill)
{
if (NotifyFill.orderNum == Number)
{
Main.KillTimer(1);
Main.KillTimer(2);
}
}