220 lines
7.8 KiB
C#
220 lines
7.8 KiB
C#
using CPSYSDIBLib;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MarketWatchNS
|
|
{
|
|
class CybosHelper
|
|
{
|
|
MarketWatch m_Listener = null;
|
|
|
|
CPUTILLib.CpCybos m_CPCybos = new CPUTILLib.CpCybos();
|
|
CPFORETRADELib.CpForeTdUtil m_CPUtil = new CPFORETRADELib.CpForeTdUtil();
|
|
|
|
CpMarketWatchS m_MarketWatch = null;
|
|
DSCBO1Lib.StockMst m_CPStockMst = new DSCBO1Lib.StockMst();
|
|
object m_StockMstLock = new object();
|
|
CPSYSDIBLib.StockChart m_StockChart = new CPSYSDIBLib.StockChart();
|
|
object m_StockChartLock = new object();
|
|
Dictionary<int, string> m_EventCodeStr = new Dictionary<int, string>();
|
|
|
|
public CybosHelper(MarketWatch Listener)
|
|
{
|
|
m_Listener = Listener;
|
|
|
|
m_EventCodeStr.Add(10, "외국계 증권사 창구 첫 매수");
|
|
m_EventCodeStr.Add(11, "외국계 증권사 창구 첫 매도");
|
|
m_EventCodeStr.Add(12, "외국인 순매수");
|
|
m_EventCodeStr.Add(13, "외국인 순매도");
|
|
m_EventCodeStr.Add(21, "전일 거래량 갱신");
|
|
m_EventCodeStr.Add(22, "최근5일 거래량최고 갱신");
|
|
m_EventCodeStr.Add(23, "최근5일 매물대 돌파");
|
|
m_EventCodeStr.Add(24, "최근60일 매물대 돌파");
|
|
m_EventCodeStr.Add(28, "최근5일 첫 상한가");
|
|
m_EventCodeStr.Add(29, "최근5일 신고가 갱신");
|
|
m_EventCodeStr.Add(30, "최근5일 신저가 갱신");
|
|
m_EventCodeStr.Add(31, "상한가 직전");
|
|
m_EventCodeStr.Add(32, "하한가 직전");
|
|
m_EventCodeStr.Add(41, "주가 5MA 상향 돌파");
|
|
m_EventCodeStr.Add(42, "주가 5MA 하향 돌파");
|
|
m_EventCodeStr.Add(43, "거래량 5MA 상향 돌파");
|
|
m_EventCodeStr.Add(44, "주가 데드크로스(5MA < 20MA)");
|
|
m_EventCodeStr.Add(45, "주가 골든크로스(5MA > 20MA)");
|
|
m_EventCodeStr.Add(46, "MACD 매수-Signal(9) 상향돌파");
|
|
m_EventCodeStr.Add(47, "MACD 매도-Signal(9) 하향돌파");
|
|
m_EventCodeStr.Add(48, "CCI 매수-기준선(-100) 상향돌파");
|
|
m_EventCodeStr.Add(49, "CCI 매도-기준선(100) 하향돌파");
|
|
m_EventCodeStr.Add(50, "Stochastic(10, 5, 5)매수- 기준선 상향돌파");
|
|
m_EventCodeStr.Add(51, "Stochastic(10, 5, 5)매도- 기준선 하향돌파");
|
|
m_EventCodeStr.Add(52, "Stochastic(10, 5, 5)매수- %K%D 교차");
|
|
m_EventCodeStr.Add(53, "Stochastic(10, 5, 5)매도- %K%D 교차");
|
|
m_EventCodeStr.Add(54, "Sonar 매수-Signal(9) 상향돌파");
|
|
m_EventCodeStr.Add(55, "Sonar 매도-Signal(9) 하향돌파");
|
|
m_EventCodeStr.Add(56, "Momentum 매수-기준선(100) 상향돌파");
|
|
m_EventCodeStr.Add(57, "Momentum 매도-기준선(100) 하향돌파");
|
|
m_EventCodeStr.Add(58, "RSI(14) 매수-Signal(9) 상향돌파");
|
|
m_EventCodeStr.Add(59, "RSI(14) 매도-Signal(9) 하향돌파");
|
|
m_EventCodeStr.Add(60, "Volume Oscillator 매수-Signal(9) 상향돌파");
|
|
m_EventCodeStr.Add(61, "Volume Oscillator 매도-Signal(9) 하향돌파");
|
|
m_EventCodeStr.Add(62, "Price roc 매수-Signal(9) 상향돌파");
|
|
m_EventCodeStr.Add(63, "Price roc 매도-Signal(9) 하향돌파");
|
|
m_EventCodeStr.Add(64, "일목균형표 매수-전환선 > 기준선 상향교차");
|
|
m_EventCodeStr.Add(65, "일목균형표 매도-전환선 < 기준선 하향교차");
|
|
m_EventCodeStr.Add(66, "일목균형표 매수-주가가 선행스팬 상향돌파");
|
|
m_EventCodeStr.Add(67, "일목균형표 매도-주가가 선행스팬 하향돌파");
|
|
m_EventCodeStr.Add(68, "삼선전환도-양전환");
|
|
m_EventCodeStr.Add(69, "삼선전환도-음전환");
|
|
m_EventCodeStr.Add(70, "캔들패턴-상승반전형");
|
|
m_EventCodeStr.Add(71, "캔들패턴-하락반전형");
|
|
m_EventCodeStr.Add(81, "단기급락 후 5MA 상향돌파");
|
|
m_EventCodeStr.Add(82, "주가 이동평균밀집-5%이내");
|
|
m_EventCodeStr.Add(83, "눌림목 재 상승-20MA 지지");
|
|
}
|
|
|
|
public void InitCybos()
|
|
{
|
|
short iResult = m_CPUtil.TradeInit();
|
|
switch (iResult)
|
|
{
|
|
case -1:
|
|
Util.Log(Util.LOG_TYPE.ERROR, "[TradeInit] 오류");
|
|
break;
|
|
|
|
case 0:
|
|
Util.Log(Util.LOG_TYPE.VERVOSE, "[TradeInit] 로그인 되었습니다");
|
|
break;
|
|
|
|
case 1:
|
|
Util.Log(Util.LOG_TYPE.ERROR, "[TradeInit] 업무 키 입력 잘못됨");
|
|
break;
|
|
|
|
case 2:
|
|
Util.Log(Util.LOG_TYPE.ERROR, "[TradeInit] 계좌 비밀번호가 잘못되었습니다");
|
|
break;
|
|
|
|
case 3:
|
|
Util.Log(Util.LOG_TYPE.ERROR, "[TradeInit] 취소되었습니다");
|
|
break;
|
|
}
|
|
|
|
m_Listener.SetAccountList(m_CPUtil.AccountNumber);
|
|
SubscribeMarketWatch();
|
|
}
|
|
|
|
public int GetLimitRemainCountTrade()
|
|
{
|
|
return m_CPCybos.GetLimitRemainCount(CPUTILLib.LIMIT_TYPE.LT_TRADE_REQUEST);
|
|
}
|
|
|
|
public int GetLimitRemainCountRQ()
|
|
{
|
|
return m_CPCybos.GetLimitRemainCount(CPUTILLib.LIMIT_TYPE.LT_NONTRADE_REQUEST);
|
|
}
|
|
|
|
public int GetLimitRemainCountSB()
|
|
{
|
|
return m_CPCybos.GetLimitRemainCount(CPUTILLib.LIMIT_TYPE.LT_SUBSCRIBE);
|
|
}
|
|
|
|
public bool IsConnected()
|
|
{
|
|
return (m_CPCybos.IsConnect==1);
|
|
}
|
|
|
|
void SubscribeMarketWatch()
|
|
{
|
|
m_MarketWatch = new CpMarketWatchS();
|
|
m_MarketWatch.SetInputValue(0, "*");
|
|
m_MarketWatch.Received += MarketWatch_Received;
|
|
m_MarketWatch.Subscribe();
|
|
}
|
|
|
|
private void MarketWatch_Received()
|
|
{
|
|
string strCode = m_MarketWatch.GetHeaderValue(0);
|
|
string strCodeName = m_MarketWatch.GetHeaderValue(1);
|
|
int iCount = m_MarketWatch.GetHeaderValue(2);
|
|
for(int i=0; i<iCount; i++)
|
|
{
|
|
int iTime = m_MarketWatch.GetDataValue(0, i);
|
|
sbyte cType = m_MarketWatch.GetDataValue(1, i);
|
|
int iEventCode = m_MarketWatch.GetDataValue(2, i);
|
|
m_Listener.OnWatchReceived(iTime, strCode, strCodeName, cType == 'n', iEventCode);
|
|
}
|
|
}
|
|
|
|
public void GetLowHighPrice(string strCode, DateTime StartTime, int iAfterMin, out int iLowPrice, out int iHighPrice)
|
|
{
|
|
iLowPrice = 10000000;
|
|
iHighPrice = 0;
|
|
|
|
lock(m_StockChartLock)
|
|
{
|
|
if(GetLimitRemainCountRQ() < 5)
|
|
return;
|
|
|
|
string strTime = StartTime.ToString("yyyyMMdd");
|
|
|
|
m_StockChart.SetInputValue(0, strCode);
|
|
m_StockChart.SetInputValue(1, '1');
|
|
m_StockChart.SetInputValue(2, strTime);
|
|
m_StockChart.SetInputValue(3, strTime);
|
|
m_StockChart.SetInputValue(4, 20);
|
|
m_StockChart.SetInputValue(5, new int[] { 0, 1, 2, 3, 4, 5, });
|
|
m_StockChart.SetInputValue(6, 'm');
|
|
m_StockChart.SetInputValue(7, 1);
|
|
m_StockChart.BlockRequest2(0);
|
|
|
|
int iTimeStart;
|
|
int.TryParse(StartTime.ToString("HHmm"), out iTimeStart);
|
|
|
|
int iCount = m_StockChart.GetHeaderValue(3);
|
|
for(int i = 0; i<iCount; i++)
|
|
{
|
|
uint uiDate = m_StockChart.GetDataValue(0, i);
|
|
long iTime = m_StockChart.GetDataValue(1, i);
|
|
|
|
if(iTime >= iTimeStart && iTime <= iTimeStart+iAfterMin)
|
|
{
|
|
long iPriceStartLocal = m_StockChart.GetDataValue(2, i);
|
|
long iPriceHighLocal = m_StockChart.GetDataValue(3, i);
|
|
long iPriceLowLocal = m_StockChart.GetDataValue(4, i);
|
|
long iPriceEndLocal = m_StockChart.GetDataValue(5, i);
|
|
|
|
iLowPrice = Math.Min(iLowPrice, (int)iPriceLowLocal);
|
|
iHighPrice = Math.Max(iHighPrice, (int)iPriceHighLocal);
|
|
}
|
|
|
|
if(iTime < iTimeStart)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int GetCurPrice(string strCode)
|
|
{
|
|
lock(m_StockMstLock)
|
|
{
|
|
m_CPStockMst.SetInputValue(0, strCode);
|
|
Console.WriteLine("[{0}] lock", Thread.CurrentThread.ManagedThreadId);
|
|
m_CPStockMst.BlockRequest2(0);
|
|
Console.WriteLine("[{0}] unlock", Thread.CurrentThread.ManagedThreadId);
|
|
int iCurPrice = m_CPStockMst.GetHeaderValue(11);
|
|
return iCurPrice;
|
|
}
|
|
}
|
|
|
|
public string GetEventCodeStr(int iEventCode)
|
|
{
|
|
if(m_EventCodeStr.ContainsKey(iEventCode) == false)
|
|
return "";
|
|
|
|
return m_EventCodeStr[iEventCode];
|
|
}
|
|
}
|
|
}
|