208 lines
5.2 KiB
C#
208 lines
5.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
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 POSTPONE_ITEM
|
|
{
|
|
public POSTPONE_ITEM(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();
|
|
public ULDB m_DB = new ULDB();
|
|
|
|
ULTrader m_Trader = new ULTrader();
|
|
|
|
Dictionary<string, ULWatchItem> m_WatchList = new Dictionary<string, ULWatchItem>();
|
|
List<POSTPONE_ITEM> m_PostponeList = new List<POSTPONE_ITEM>();
|
|
Dictionary<string, int> m_LossCutList = new Dictionary<string, int>();
|
|
List<string> m_BlackList = new List<string>();
|
|
|
|
string m_AvailableListKey;
|
|
List<string> m_AvailableList = new List<string>();
|
|
|
|
long m_iCacheBalance = 0;
|
|
long m_iEvalProfit = 0;
|
|
|
|
public ULDataMgr()
|
|
{
|
|
m_AvailableListKey= "available-"+ULUtil.GetCurTime().ToString("yyyy-MM-dd");
|
|
string strValue = m_DB.Get(m_AvailableListKey).ToString();
|
|
m_AvailableList=strValue.Split(',').ToList();
|
|
}
|
|
|
|
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 AddPostphoneItem(int iTime, string strCode)
|
|
{
|
|
POSTPONE_ITEM postpone = new POSTPONE_ITEM(strCode, iTime);
|
|
m_PostponeList.Add(postpone);
|
|
}
|
|
|
|
public bool IsInPostponeList(int iTime, string strCode)
|
|
{
|
|
return m_PostponeList.Any(r => r.m_strCode == strCode && ULUtil.IsInTime(r.m_iTime, iTime, 4));
|
|
}
|
|
|
|
public void AddLosscutItem(string strCode)
|
|
{
|
|
if(m_LossCutList.ContainsKey(strCode) == false)
|
|
{
|
|
m_LossCutList.Add(strCode, 1);
|
|
}
|
|
else
|
|
{
|
|
m_LossCutList[strCode] += 1;
|
|
if(m_LossCutList[strCode] >= 2)
|
|
m_BlackList.Add(strCode);
|
|
}
|
|
}
|
|
|
|
public bool IsInBlackList(string strCode)
|
|
{
|
|
return m_BlackList.Any(r => r == strCode);
|
|
}
|
|
|
|
public Dictionary<string, ULWatchItem> GetWatchList()
|
|
{
|
|
return m_WatchList;
|
|
}
|
|
|
|
public void SetCacheBalance(long iBalance)
|
|
{
|
|
m_iCacheBalance = iBalance;
|
|
}
|
|
|
|
public long GetCacheBalance()
|
|
{
|
|
return m_iCacheBalance;
|
|
}
|
|
|
|
public void SetEvalProfit(long iProfit)
|
|
{
|
|
m_iEvalProfit = iProfit;
|
|
}
|
|
|
|
public long GetEvalProfit()
|
|
{
|
|
return m_iEvalProfit;
|
|
}
|
|
|
|
public ULDB GetDB()
|
|
{
|
|
return m_DB;
|
|
}
|
|
|
|
public void AddAvailableItem(string strCode)
|
|
{
|
|
if(m_AvailableList.Any(r => r==strCode)==false)
|
|
{
|
|
m_AvailableList.Add(strCode);
|
|
m_DB.Put(m_AvailableListKey, string.Join(",", m_AvailableList));
|
|
}
|
|
}
|
|
|
|
public void AddBidLog(string strCode, string strCodeName, int iTime, int iBidPrice, float f5MAslope)
|
|
{
|
|
string strKey = string.Format("bid-{0}-{1}-{2}", ULUtil.GetCurTime().ToString("yyyyMMdd"), iTime, strCodeName);
|
|
string strValue = string.Format("{0},{1},{2},{3},{4}", strCodeName, strCode, iTime, iBidPrice, f5MAslope);
|
|
m_DB.Put(strKey, strValue);
|
|
}
|
|
|
|
public void AddAskLog(string strCode, string strCodeName, int iTime, int iBidPrice, float f5MAslope, bool bLosscut, int iProfit, float fProfitRate)
|
|
{
|
|
string strKey = string.Format("ask-{0}-{1}-{2}", ULUtil.GetCurTime().ToString("yyyyMMdd"), iTime, strCodeName);
|
|
string strValue = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", strCodeName, strCode, iTime, iBidPrice, f5MAslope, bLosscut?"Losscut":"Trailing", iProfit, fProfitRate);
|
|
m_DB.Put(strKey, strValue);
|
|
}
|
|
}
|
|
}
|