simulation row 찾기 정교하게 수정
This commit is contained in:
@@ -10,8 +10,23 @@ namespace AutoSellerNS
|
||||
{
|
||||
public class CybosHelper
|
||||
{
|
||||
public class PriceNode
|
||||
{
|
||||
public int m_iTime;
|
||||
public int m_iPrice;
|
||||
public int m_iAskPrice;
|
||||
public int m_iBidPrice;
|
||||
public int m_iAccDealCnt;
|
||||
public int m_iDealCnt;
|
||||
public double m_dAvg;
|
||||
public double m_dSD;
|
||||
public double m_dSellLimit;
|
||||
public int m_iSellCnt;
|
||||
}
|
||||
|
||||
public class STOCK_CUR_ITEM
|
||||
{
|
||||
|
||||
public AutoSeller m_Listener = null;
|
||||
public CybosHelper m_CybosHelper = null;
|
||||
public string m_strCode;
|
||||
@@ -23,6 +38,7 @@ namespace AutoSellerNS
|
||||
public int[] m_aiAskPrice = new int[10];
|
||||
public int[] m_aiAskCount = new int[10];
|
||||
|
||||
public int m_iOpenigPrice = 0;
|
||||
public int m_iCurPrice = 0;
|
||||
public int m_iMaxPrice = 0;
|
||||
public int m_iCheckCount = 0;
|
||||
@@ -30,30 +46,41 @@ namespace AutoSellerNS
|
||||
public int m_iTrailingCount = 0;
|
||||
|
||||
// real time, price time, price
|
||||
public List<Tuple<int, int, int>> m_PriceList = new List<Tuple<int, int, int>>();
|
||||
public double m_dCheckCountLimit = 5;
|
||||
public List<PriceNode> m_PriceList = new List<PriceNode>();
|
||||
public double m_dCheckCountLimit = Config.GetBidCount();
|
||||
|
||||
int m_iPrevTime = 0;
|
||||
|
||||
public void OnRecievedPrice()
|
||||
{
|
||||
bool bReal = (m_StockCur.GetHeaderValue(19) == '2');
|
||||
bool bOpeningHour = (m_StockCur.GetHeaderValue(19) == '2');
|
||||
m_iCurPrice = m_StockCur.GetHeaderValue(13);
|
||||
if (m_iOpenigPrice == 0)
|
||||
m_iOpenigPrice = m_iCurPrice;
|
||||
int iTime = m_StockCur.GetHeaderValue(18);
|
||||
int iConclusionCnt = m_StockCur.GetHeaderValue(17);
|
||||
int iAccDealCnt = m_StockCur.GetHeaderValue(9);
|
||||
int iDealCnt = m_StockCur.GetHeaderValue(17);
|
||||
|
||||
int iTimeDiff = 0;
|
||||
if(m_iPrevTime > 0)
|
||||
iTimeDiff = ((iTime/10000)*60*60 + ((iTime%10000)/100)*60 + (iTime%100)) - ((m_iPrevTime/10000)*60*60 + ((m_iPrevTime%10000)/100)*60 + (m_iPrevTime%100));
|
||||
|
||||
if(bReal == true)
|
||||
if(bOpeningHour == true)
|
||||
{
|
||||
DateTime RealTime = DateTime.Now;
|
||||
int iRealTime = RealTime.Hour * 10000 + RealTime.Minute * 100 + RealTime.Second;
|
||||
m_PriceList.Add(new Tuple<int, int, int>(iRealTime, iTime, m_iCurPrice));
|
||||
double dAverage = (float)m_PriceList.Average(s => s.Item3);
|
||||
double sumOfSquaresOfDifferences = m_PriceList.Select(val => Math.Pow((val.Item3-dAverage)/m_CybosHelper.GetUnitValue(val.Item3), 2)).Sum();
|
||||
double dStdDev = Math.Sqrt(sumOfSquaresOfDifferences / m_PriceList.Count);
|
||||
|
||||
List<int> lastNPrice = null;
|
||||
if (Config.GetListSize() == 0)
|
||||
lastNPrice = m_PriceList.Select(s => s.m_iPrice).ToList();
|
||||
else
|
||||
lastNPrice = m_PriceList.Skip(Math.Max(0, m_PriceList.Count - (Config.GetListSize()-1))).Select(s => s.m_iPrice).ToList();
|
||||
lastNPrice.Add(m_iCurPrice);
|
||||
|
||||
double dAverage = lastNPrice.Average();
|
||||
double sumOfSquaresOfDifferences = lastNPrice.Select(val => Math.Pow((val - dAverage)/m_CybosHelper.GetUnitValue(val), 2)).Sum();
|
||||
double dStdDev = Math.Sqrt(sumOfSquaresOfDifferences / lastNPrice.Count);
|
||||
if(dStdDev >= Config.GetFastSD())
|
||||
{
|
||||
if(m_iCurPrice >= dAverage)
|
||||
@@ -120,9 +147,23 @@ namespace AutoSellerNS
|
||||
m_iCurPrice,
|
||||
m_iMaxPrice));
|
||||
}
|
||||
|
||||
|
||||
m_PriceList.Add(new PriceNode {
|
||||
m_iTime = iTime,
|
||||
m_iPrice = m_iCurPrice,
|
||||
m_iAskPrice = iAskPrice,
|
||||
m_iBidPrice = iBidPrice,
|
||||
m_iAccDealCnt = iAccDealCnt,
|
||||
m_iDealCnt = iDealCnt,
|
||||
m_dAvg = dAverage,
|
||||
m_dSD = dStdDev,
|
||||
m_dSellLimit = m_dCheckCountLimit,
|
||||
m_iSellCnt = m_iCheckCount,
|
||||
});
|
||||
}
|
||||
|
||||
m_Listener.OnReceivedCurPrice(m_strCode, m_iCurPrice, m_iMaxPrice, m_dCheckCountLimit, m_iCheckCount, bReal);
|
||||
m_Listener.OnReceivedCurPrice(m_strCode, m_iCurPrice, m_iMaxPrice, m_dCheckCountLimit, m_iCheckCount, bOpeningHour);
|
||||
m_iPrevTime = iTime;
|
||||
}
|
||||
|
||||
@@ -201,11 +242,16 @@ namespace AutoSellerNS
|
||||
Directory.CreateDirectory(Util.GetLogPath());
|
||||
|
||||
string strToday = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string strFilePath = Util.GetLogPath() + "/price-" + strToday + item.m_strCodeName + ".txt";
|
||||
string strMessage = "";
|
||||
foreach (var pair in item.m_PriceList)
|
||||
string strFilePath = Util.GetLogPath() + "/price-" + strToday + item.m_strCodeName + ".csv";
|
||||
string strMessage = "시간, 동시호가, 현재가, 매도호가, 매수호가, 거래량, 순간체결량, 평균, 표준편차, 매도 제한, 매도 수, 시가 대비";
|
||||
File.AppendAllText(strFilePath, strMessage + Environment.NewLine, new UTF8Encoding(true));
|
||||
foreach (var node in item.m_PriceList)
|
||||
{
|
||||
strMessage = string.Format("[{0}] {1} ({2})", pair.Item2, pair.Item3, pair.Item1);
|
||||
strMessage = string.Format("{0}:{1}:{2}, , {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12:0.00}",
|
||||
node.m_iTime/10000, (node.m_iTime/100)%100, node.m_iTime%100,
|
||||
node.m_iPrice, node.m_iAskPrice, node.m_iBidPrice,
|
||||
node.m_iAccDealCnt, node.m_iDealCnt,
|
||||
node.m_dAvg, node.m_dSD, node.m_dSellLimit, node.m_iSellCnt, (node.m_iPrice-item.m_PriceList[0].m_iPrice)*100/(double)item.m_PriceList[0].m_iPrice);
|
||||
File.AppendAllText(strFilePath, strMessage + Environment.NewLine, new UTF8Encoding(true));
|
||||
}
|
||||
}
|
||||
@@ -325,9 +371,8 @@ namespace AutoSellerNS
|
||||
Item.m_iOrderPrice = CP5339.GetDataValue(7, i);
|
||||
Item.m_iRemainCnt = CP5339.GetDataValue(11, i);
|
||||
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
|
||||
Item.m_iOrderNo = CP5339.GetDataValue(1, i);
|
||||
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
|
||||
if(Item.m_iOrgOrderNo == 0)
|
||||
Item.m_iOrgOrderNo = CP5339.GetDataValue(1, i);
|
||||
|
||||
NCItems.Add(Item);
|
||||
}
|
||||
@@ -388,7 +433,18 @@ namespace AutoSellerNS
|
||||
m_Listener.UpdateNCItem();
|
||||
Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 접수 ({3:n0}원 {4}주) - {5}", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt, strOrderCondition));
|
||||
if (bBid == true)
|
||||
SimulationHelper.InsertSimulationLog(strCode, strCodeName, iPrice);
|
||||
{
|
||||
if(m_aStockCur.ContainsKey(strCode) == true)
|
||||
{
|
||||
var priceList = m_aStockCur[strCode].m_PriceList;
|
||||
List<Tuple<int, int>> PriceDealCntList = new List<Tuple<int, int>>();
|
||||
for (int i = 0; i < Math.Min(5, priceList.Count); i++)
|
||||
PriceDealCntList.Add(new Tuple<int, int>(priceList[i].m_iPrice, priceList[i].m_iDealCnt));
|
||||
|
||||
SimulationHelper.InsertSimulationLog(strCode, strCodeName, PriceDealCntList);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -527,11 +583,7 @@ namespace AutoSellerNS
|
||||
int iIdx = iCorrectIdx++;
|
||||
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem Start ({0})", iIdx));
|
||||
|
||||
int iSellPrice = iAskPrice-GetUnitValue(iAskPrice);
|
||||
|
||||
//CancelItem(strCode, iOrgOrderNo);
|
||||
//Thread.Sleep(1000);
|
||||
//SellItem(strCode, iCnt, iAskPrice);
|
||||
int iSellPrice = iAskPrice;
|
||||
|
||||
CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313();
|
||||
Td0313.SetInputValue(1, iOrgOrderNo);
|
||||
|
||||
Reference in New Issue
Block a user