- 시간에 따른 감소폭 추가

- 정정주문 수정
- crash 수정
This commit is contained in:
2017-03-07 15:40:25 +09:00
parent f4872096c6
commit 592fc7a365
5 changed files with 601 additions and 450 deletions

View File

@@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AutoSellerNS
{
class CybosHelper
public class CybosHelper
{
public class STOCK_CUR_ITEM
{
@@ -28,7 +29,7 @@ namespace AutoSellerNS
public int m_iTrailingCount = 0;
public List<int> m_PriceList = new List<int>();
public double m_dCheckCount = 5;
public double m_dCheckCountLimit = 5;
double m_dFastSD = 0.75;
double m_dFastUpCnt = 0.05;
@@ -36,62 +37,93 @@ namespace AutoSellerNS
double m_dSlowSD = 0.2;
double m_dSlowUpCnt = 0.4;
double m_dSlowDownCnt = 0.4;
int m_iTimeLimit = 5;
int m_iPrevTime = 0;
double m_dTimeSub = 0.02;
public void OnRecievedPrice()
{
bool bReal = (m_StockCur.GetHeaderValue(19) == '2');
m_iCurPrice = m_StockCur.GetHeaderValue(13);
int iTime = m_StockCur.GetHeaderValue(18); // *** 초단위 시간 확인
m_PriceList.Add(m_iCurPrice);
double dAverage = (float)m_PriceList.Average();
double sumOfSquaresOfDifferences = m_PriceList.Select(val => Math.Pow((val-dAverage)/m_CybosHelper.GetUnitValue(val), 2)).Sum();
double dStdDev = Math.Sqrt(sumOfSquaresOfDifferences / m_PriceList.Count);
if(dStdDev >= m_dFastSD)
{
if(m_iCurPrice >= dAverage)
m_dCheckCount += m_dFastUpCnt;
else
m_dCheckCount -= m_dFastDownCnt;
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));
}
else if(dStdDev <= m_dSlowSD)
{
if(m_iCurPrice >= dAverage)
m_dCheckCount += m_dSlowUpCnt;
else
m_dCheckCount -= m_dSlowDownCnt;
}
if(m_iCurPrice > m_iMaxPrice)
m_iTrailingCount = 0;
m_iMaxPrice = Math.Max(m_iCurPrice, m_iMaxPrice);
int iAskPrice = m_StockCur.GetHeaderValue(7);
int iBidPrice = m_StockCur.GetHeaderValue(8);
if(bReal == true)
{
m_PriceList.Add(m_iCurPrice);
double dAverage = (float)m_PriceList.Average();
double sumOfSquaresOfDifferences = m_PriceList.Select(val => Math.Pow((val-dAverage)/m_CybosHelper.GetUnitValue(val), 2)).Sum();
double dStdDev = Math.Sqrt(sumOfSquaresOfDifferences / m_PriceList.Count);
if(dStdDev >= m_dFastSD)
{
if(m_iCurPrice >= dAverage)
m_dCheckCountLimit += m_dFastUpCnt;
else
m_dCheckCountLimit -= m_dFastDownCnt;
}
else if(dStdDev <= m_dSlowSD)
{
if(m_iCurPrice >= dAverage)
m_dCheckCountLimit += m_dSlowUpCnt;
else
m_dCheckCountLimit -= m_dSlowDownCnt;
}
m_dCheckCountLimit -= iTimeDiff*m_dTimeSub;
if(m_iCurPrice > m_iMaxPrice)
m_iTrailingCount = 0;
m_iMaxPrice = Math.Max(m_iCurPrice, m_iMaxPrice);
int iAskPrice = m_StockCur.GetHeaderValue(7);
int iBidPrice = m_StockCur.GetHeaderValue(8);
if(m_iCurPrice <= iBidPrice)
m_iCheckCount++;
else
m_iCheckCount = 0;
if(m_iCheckCount >= m_dCheckCountLimit && m_Listener.IsSelling() == true)
{
m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName,
Config.GetBidCount(),
m_iCurPrice,
m_iMaxPrice));
}
if(m_iCurPrice < (m_iMaxPrice*(100.0f-Config.GetTrailingRate())/100.0f))
m_iTrailingCount++;
if(m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true)
{
m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {3:n0}원, 최고가 {4:n0}원)",
m_strCodeName,
Config.GetTrailingRate(),
Config.GetTrailingCnt(),
m_iCurPrice,
m_iMaxPrice));
}
if(iTimeDiff >= m_iTimeLimit)
{
m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName,
iTimeDiff,
m_iCurPrice,
m_iMaxPrice));
}
}
if(m_iCheckCount >= m_dCheckCount && m_Listener.IsSelling() == true)
{
m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)", m_strCodeName, Config.GetBidCount(), m_iCurPrice, m_iMaxPrice));
}
if(bReal == true && m_iCurPrice < (m_iMaxPrice*(100.0f-Config.GetTrailingRate())/100.0f))
m_iTrailingCount++;
if(m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true)
{
m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {2:n0}원, 최고가 {3:n0}원)", m_strCodeName, Config.GetTrailingRate(), Config.GetTrailingCnt(), m_iCurPrice, m_iMaxPrice));
}
m_Listener.OnReceivedCurPrice(m_strCode, m_iCurPrice, m_iMaxPrice, m_iCheckCount, bReal);
m_Listener.OnReceivedCurPrice(m_strCode, m_iCurPrice, m_iMaxPrice, m_dCheckCountLimit, m_iCheckCount, bReal);
m_iPrevTime = iTime;
}
public void OnReceivedCall()
@@ -124,7 +156,9 @@ namespace AutoSellerNS
CPTRADELib.CpTd6033 m_6033 = new CPTRADELib.CpTd6033();
Dictionary<string, STOCK_CUR_ITEM> m_aStockCur = new Dictionary<string, STOCK_CUR_ITEM>();
object m_NCItemLock = new object();
public CybosHelper(AutoSeller Listener)
{
m_Listener = Listener;
@@ -245,34 +279,38 @@ namespace AutoSellerNS
public List<AutoSeller.NCITEM> UpdateNC()
{
List<AutoSeller.NCITEM> NCItems = new List<AutoSeller.NCITEM>();
CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339();
CP5339.SetInputValue(0, Config.GetAccount());
CP5339.SetInputValue(1, Config.GetSubAccount());
CP5339.BlockRequest2(0);
bool bContinue = true;
while(bContinue)
lock(m_NCItemLock)
{
int iCnt = CP5339.GetHeaderValue(5);
for(int i = 0; i<iCnt; i++)
CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339();
CP5339.SetInputValue(0, Config.GetAccount());
CP5339.SetInputValue(1, Config.GetSubAccount());
CP5339.BlockRequest2(0);
bool bContinue = true;
while(bContinue)
{
AutoSeller.NCITEM Item = new AutoSeller.NCITEM();
int iCnt = CP5339.GetHeaderValue(5);
for(int i = 0; i<iCnt; i++)
{
AutoSeller.NCITEM Item = new AutoSeller.NCITEM();
Item.m_strCode = CP5339.GetDataValue(3, i);
Item.m_strCodeName = CP5339.GetDataValue(4, i);
Item.m_strDesc = CP5339.GetDataValue(5, i);
Item.m_iOrderPrice = CP5339.GetDataValue(7, i);
Item.m_iRemainCnt = CP5339.GetDataValue(11, i);
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
Item.m_strCode = CP5339.GetDataValue(3, i);
Item.m_strCodeName = CP5339.GetDataValue(4, i);
Item.m_strDesc = CP5339.GetDataValue(5, i);
Item.m_iOrderPrice = CP5339.GetDataValue(7, i);
Item.m_iRemainCnt = CP5339.GetDataValue(11, i);
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
if(Item.m_iOrgOrderNo == 0)
Item.m_iOrgOrderNo = CP5339.GetDataValue(1, i);
NCItems.Add(Item);
NCItems.Add(Item);
}
bContinue = (CP5339.Continue != 0);
if(bContinue)
CP5339.BlockRequest2(0);
}
bContinue = (CP5339.Continue != 0);
if(bContinue)
CP5339.BlockRequest2(0);
}
return NCItems;
@@ -421,10 +459,25 @@ namespace AutoSellerNS
Td0311.BlockRequest2(0);
}
public void CorrectionItem(string strCode, int iOrgOrderNo, int iAskPrice)
public void CancelItem(string strCode, int iOrgOrderNo)
{
CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314();
Td0314.SetInputValue(1, iOrgOrderNo);
Td0314.SetInputValue(2, Config.GetAccount());
Td0314.SetInputValue(3, Config.GetSubAccount());
Td0314.SetInputValue(4, strCode);
Td0314.SetInputValue(5, 0);
Td0314.BlockRequest2(0);
}
public void CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice)
{
int iSellPrice = iAskPrice-GetUnitValue(iAskPrice);
//CancelItem(strCode, iOrgOrderNo);
//Thread.Sleep(1000);
//SellItem(strCode, iCnt, iAskPrice);
CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313();
Td0313.SetInputValue(1, iOrgOrderNo);
Td0313.SetInputValue(2, Config.GetAccount());