IF COUNTDOWN > 0 COUNTDOWN = COUNTDOWN - 1 ELSE IF STATE == "WAIT BUY" IF LAST_ORDER_PRICE == BID COUNTDOWN = COUNTDOWN_INTERVAL ELSE STATE = "CANCEL BUY" END IF END IF IF STATE == "WAIT SELL" IF LAST_ORDER_PRICE == ASK COUNTDOWN = COUNTDOWN_INTERVAL ELSE STATE = "CANCEL SELL" END IF END IF END IF
IF STATE == "WATCH" SPREAD = ABS(ASK - BID) IF (SPREAD >= MIN_SPREAD) AND (SPREAD <= MAX_SPREAD) STATE = "PLACE BUY" ELSE RETURN END IF END IF
IF STATE == "PLACE BUY" LAST_ORDER = PLACE_ORDER("B", BID, SIZE) IF LAST_ORDER != 0 LAST_ORDER_PRICE = BID STATE = "WAIT BUY" COUNTDOWN = COUNTDOWN_INTERVAL END IF END IF
IF STATE == "WAIT BUY" IF GET_VALUE(GET_ORDER(LAST_ORDER), "STATUS") == "FILLED" STATE = "PLACE SELL" END IF END IF
IF STATE == "CANCEL BUY" STATUS = GET_VALUE(GET_ORDER(LAST_ORDER), "STATUS") IF STATUS == "FILLED" STATE = "PLACE SELL" END IF IF STATUS == "KILLED" STATE = "WATCH" END IF IF STATUS == "ACTIVE" CANCEL_ORDER(LAST_ORDER) END IF END IF
IF STATE == "PLACE SELL" LAST_ORDER = PLACE_ORDER("S", ASK, SIZE) IF LAST_ORDER != 0 LAST_ORDER_PRICE = ASK STATE = "WAIT SELL" COUNTDOWN = COUNTDOWN_INTERVAL END IF END IF
IF STATE == "WAIT SELL" IF GET_VALUE(GET_ORDER(LAST_ORDER), "STATUS") == "FILLED" STATE = "WATCH" END IF END IF
IF STATE == "CANCEL SELL" STATUS = GET_VALUE(GET_ORDER(LAST_ORDER), "STATUS") IF STATUS == "FILLED" STATE = "WATCH" END IF IF STATUS == "KILLED" STATE = "PLACE SELL" END IF IF STATUS == "ACTIVE" CANCEL_ORDER(LAST_ORDER) END IF END IF
FUNC GET_ORDER(ORDNUM) _TOTAL = GET_NUMBER_OF("ORDERS") RESULT = 0 FOR _I FROM 1 TO _TOTAL _ROW = GET_ITEM("ORDERS", _I) IF GET_VALUE(_ROW, "NUMBER")+0 == ORDNUM RESULT = _ROW BREAK END IF END FOR END FUNC
FUNC CANCEL_ORDER(NUMBER) T = CREATE_MAP() TRANS_ID = TRANS_ID + 1 T = SET_VALUE(T, "TRANS_ID", TRANS_ID) T = SET_VALUE(T, "ACTION", "KILL_ORDER") T = SET_VALUE(T, "ORDER_KEY", NUMBER) T = SET_VALUE(T, "CLASSCODE", MARKET) T = SET_VALUE(T, "SECCODE", TICKER) T = SET_VALUE(T, "ACCOUNT", ACCOUNT) T = SET_VALUE(T, "CLIENT_CODE", CLIENT_CODE) R = SEND_TRANSACTION(30, T) RESULT = GET_VALUE(R, "RESULT")+0 'GET_VALUE(R, "DESCRIPTION") END FUNC
FUNC PLACE_ORDER(OPERATION, PRICE, QUANTITY) T = CREATE_MAP() TRANS_ID = TRANS_ID + 1 T = SET_VALUE(T, "TRANS_ID", TRANS_ID) T = SET_VALUE(T, "ACTION", "NEW_ORDER") T = SET_VALUE(T, "CLASSCODE", MARKET) T = SET_VALUE(T, "SECCODE", TICKER) T = SET_VALUE(T, "ACCOUNT", ACCOUNT) T = SET_VALUE(T, "CLIENT_CODE", CLIENT_CODE) T = SET_VALUE(T, "TYPE", "L") T = SET_VALUE(T, "OPERATION", OPERATION) T = SET_VALUE(T, "PRICE", PRICE) T = SET_VALUE(T, "QUANTITY", QUANTITY) RES = SEND_TRANSACTION(10, T) ' ----------------------------------------------------Период ожидания в секундах RESULT = GET_VALUE(RES, "ORDER_NUMBER")+0 DT = GET_DATETIME() ROW = CREATE_MAP() ROW = SET_VALUE(ROW, "DT", GET_VALUE(DT, "DATETIME")) ROW = SET_VALUE(ROW, "SIDE", OPERATION) ROW = SET_VALUE(ROW, "PRICE", PRICE) ROW = SET_VALUE(ROW, "ORDER", RESULT) ADD_ITEM(1, ROW) '------------------------------------------------------------------------1-ставить заявку первой END FUNC
END_PROGRAM
PARAMETER DT; PARAMETER_TITLE Дата и Время; PARAMETER_DESCRIPTION Дата и Время; PARAMETER_TYPE STRING(30); END
PARAMETER SIDE; PARAMETER_TITLE Направление; PARAMETER_DESCRIPTION Направление; PARAMETER_TYPE STRING(30); END
PARAMETER PRICE; PARAMETER_TITLE Цена; PARAMETER_DESCRIPTION Цена; PARAMETER_TYPE STRING(30); END
PARAMETER ORDER; PARAMETER_TITLE Заявка; PARAMETER_DESCRIPTION Заявка; PARAMETER_TYPE STRING(30); END