void Run(ulong trdAcc, String unlockTrdPwdMD5, TrdCommon.TrdMarket trdMarket, TrdCommon.TrdEnv trdEnv, QotCommon.Security sec) { if (sec.Market != (int)QotCommon.QotMarket.QotMarket_HK_Security && sec.Market != (int)QotCommon.QotMarket.QotMarket_US_Security) { Console.Error.WriteLine("unsupported stock market"); return; } bool ret = InitConnectTrdSync(Config.OpendIP, Config.OpendPort); if (!ret) { Console.Error.WriteLine("fail to connect trd"); return; } ret = InitConnectQotSync(Config.OpendIP, Config.OpendPort); if (!ret) { Console.Error.WriteLine("fail to connect qot"); return; } TrdUnlockTrade.Response unlockTrdRsp = UnlockTradeSync(unlockTrdPwdMD5, true); if (unlockTrdRsp.RetType != (int)Common.RetType.RetType_Succeed) { Console.Error.Write("fail to unlock trade; retType={0} msg={1}\n", unlockTrdRsp.RetType, unlockTrdRsp.RetMsg); return; } DateTime now = DateTime.Now; DateTime startDate = now.Subtract(new TimeSpan(100, 0, 0, 0)); QotRequestHistoryKL.Response historyKLRsp = RequestHistoryKLSync(sec, QotCommon.KLType.KLType_Day, QotCommon.RehabType.RehabType_Forward, startDate.ToString("yyyy-MM-dd"), now.ToString("yyyy-MM-dd"), 1000, null, new byte[] {}, false); List <double> klCloseList = new List <double>(); List <double> difList = new List <double>(); List <double> deaList = new List <double>(); List <double> macdList = new List <double>(); foreach (QotCommon.KLine kl in historyKLRsp.S2C.KlListList) { klCloseList.Add(kl.ClosePrice); } MACDUtil.CalcMACD(klCloseList, 12, 26, 9, difList, deaList, macdList); int difCount = difList.Count; int deaCount = deaList.Count; if (difCount > 0 && deaCount > 0) { if (difList[difCount - 1] < deaList[deaCount - 1] && difList[difCount - 2] > deaList[deaCount - 2]) { TrdCommon.TrdFilterConditions filterConditions = TrdCommon.TrdFilterConditions.CreateBuilder() .AddCodeList(sec.Code) .Build(); TrdGetPositionList.Response getPositionListRsp = GetPositionListSync(trdAcc, trdMarket, trdEnv, filterConditions, null, null, false); if (getPositionListRsp.RetType != (int)Common.RetType.RetType_Succeed) { Console.Error.Write("getPositionListSync err; retType={0} msg={1}\n", getPositionListRsp.RetType, getPositionListRsp.RetMsg); return; } foreach (TrdCommon.Position pstn in getPositionListRsp.S2C.PositionListList) { if (pstn.CanSellQty > 0) { Sell(sec, pstn, trdAcc, trdMarket, trdEnv); } } } else if (difList[difCount - 1] > deaList[deaCount - 1] && difList[difCount - 2] < deaList[deaCount - 2]) { Buy(sec, trdAcc, trdMarket, trdEnv); } } }
public void OnReply_RequestHistoryKL(FTAPI_Conn client, uint nSerialNo, QotRequestHistoryKL.Response rsp) { handleQotOnReply(nSerialNo, ProtoID.QotRequestHistoryKL, rsp); }
public void OnReply_RequestHistoryKL(FTAPI_Conn client, int nSerialNo, QotRequestHistoryKL.Response rsp) { }
public RequestHistoryKLEventArgs(FTAPI_Conn client, int nSerialNo, QotRequestHistoryKL.Response result) { Client = client; SerialNo = nSerialNo; Result = result; }