136 lines
2.8 KiB
C#
136 lines
2.8 KiB
C#
using MySql.Data.MySqlClient;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace upper_limit_crawler
|
|
{
|
|
public struct SETTING
|
|
{
|
|
public float m_fSearchMin;
|
|
public float m_fSearchMax;
|
|
public float m_fBidMin;
|
|
public float m_fBidMax;
|
|
public float m_fBidAmount;
|
|
public float m_fTimeout;
|
|
public float m_fTrailing;
|
|
public float m_fLossCut;
|
|
}
|
|
|
|
public struct BLACKLIST
|
|
{
|
|
public BLACKLIST(string strCode, int iTime)
|
|
{
|
|
m_strCode = strCode;
|
|
m_iTime = iTime;
|
|
}
|
|
|
|
public string m_strCode;
|
|
public int m_iTime;
|
|
}
|
|
|
|
public class ULDataMgr
|
|
{
|
|
public SETTING m_Setting = new SETTING();
|
|
|
|
ULTrader m_Trader = new ULTrader();
|
|
|
|
Dictionary<string, ULWatchItem> m_WatchList = new Dictionary<string, ULWatchItem>();
|
|
List<BLACKLIST> m_BlackList = new List<BLACKLIST>();
|
|
|
|
public ULDataMgr()
|
|
{
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
m_Trader.Init();
|
|
}
|
|
|
|
public string GetAccount()
|
|
{
|
|
return m_Trader.GetAccount();
|
|
}
|
|
|
|
public ULTrader GetTrader()
|
|
{
|
|
return m_Trader;
|
|
}
|
|
|
|
public void AddWatch(string strCode, string strCodeName, int iCurPrice, int iPrevClosing)
|
|
{
|
|
if (m_WatchList.ContainsKey(strCode))
|
|
return;
|
|
|
|
ULWatchItem item = new ULWatchItem();
|
|
item.m_strCode = strCode;
|
|
item.m_strCodeName = strCodeName;
|
|
item.m_iCurPrice = iCurPrice;
|
|
item.m_iPrevClosing = iPrevClosing;
|
|
|
|
item.FillPrice();
|
|
|
|
item.m_StockCur = new DSCBO1Lib.StockCur();
|
|
item.m_StockCur.SetInputValue(0, strCode);
|
|
item.m_StockCur.Received += item.Received;
|
|
item.m_StockCur.SubscribeLatest();
|
|
|
|
m_WatchList.Add(strCode, item);
|
|
}
|
|
|
|
public void RemoveWatch(string strCode)
|
|
{
|
|
if (m_WatchList.ContainsKey(strCode))
|
|
return;
|
|
|
|
m_WatchList[strCode].m_StockCur.Unsubscribe();
|
|
m_WatchList.Remove(strCode);
|
|
}
|
|
|
|
public void StartAll()
|
|
{
|
|
foreach (KeyValuePair<string, ULWatchItem> item in m_WatchList)
|
|
{
|
|
item.Value.m_StockCur = new DSCBO1Lib.StockCur();
|
|
item.Value.m_StockCur.SetInputValue(0, item.Value.m_strCode);
|
|
item.Value.m_StockCur.Received += item.Value.Received;
|
|
item.Value.m_StockCur.SubscribeLatest();
|
|
}
|
|
}
|
|
|
|
public void StopAll()
|
|
{
|
|
foreach (KeyValuePair<string, ULWatchItem> item in m_WatchList)
|
|
{
|
|
item.Value.m_StockCur.Unsubscribe();
|
|
}
|
|
}
|
|
|
|
public void AddBlackList(string strCode)
|
|
{
|
|
int iTime = int.Parse(UlUtil.GetCurTime().ToString("HHmmss"));
|
|
BLACKLIST black = new BLACKLIST(strCode, iTime);
|
|
m_BlackList.Add(black);
|
|
}
|
|
|
|
bool IsIn5Min(int iTime)
|
|
{
|
|
int iCurTime = int.Parse(UlUtil.GetCurTime().ToString("HHmmss"));
|
|
return (iTime >= iCurTime - 500);
|
|
}
|
|
|
|
public bool IsInBlackList(string strCode)
|
|
{
|
|
return m_BlackList.Any(r => r.m_strCode == strCode && IsIn5Min(r.m_iTime));
|
|
}
|
|
|
|
public Dictionary<string, ULWatchItem> GetWatchList()
|
|
{
|
|
return m_WatchList;
|
|
}
|
|
}
|
|
}
|