金融交易系统,尤其是数字货币交易所系统有复杂的逻辑设计,涉及到平仓,建仓,止盈,止损、爆仓以及出入金安全控制。
特别是出入金安全控制,容易产生虚假充值现象。
同时第三方行情数据,随时可能出现终止传输现象,时时刻刻都要检测扫描数据的有效性。
我们看一下建仓过程中可能发生的意外。
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pc_users_creatposition : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
///首先要校验行情数据是否异常,异常的情况下开关自动关闭
int kaiguan = ClassSys.IsOpenClose();
if (kaiguan == 0)
{
//// 接着要检查传输过来的 账号密码 是否符合格式要求,比较完整校验
string shoujihao = Request.Form["telnum"].ToString();
string mimyao = ClassSql.sha256(Request.Form["miyao"].ToString());
Regex rx = new Regex(@"^1\d{10}$");
if (rx.IsMatch(shoujihao))
{
///检查用户是否存在,以及用户的状态,是否允许建仓
string sqlinsert = "SELECT * FROM [dbo].[jiaoyizhe] where shoujihao='" + shoujihao + "' and miyaokey='" + mimyao + "' and jinzhijiancang=0";
DataSet dataSet = ClassSql.sqlGetdataset(sqlinsert);
int count = dataSet.Tables[0].Rows.Count;
if (count > 0)
{
double shengyuusdt = double.Parse(dataSet.Tables[0].Rows[0]["usdtzichan"].ToString());
double shengyuudx = double.Parse(dataSet.Tables[0].Rows[0]["udxzichan"].ToString());
double baozhengjin = double.Parse(Request.Form["baozhengjin"].ToString());
bool chongzu = false;
string zichanleixing = Request.Form["zichanleixing"].ToString();
string jinzhijiancang = dataSet.Tables[0].Rows[0]["jinzhijiancang"].ToString();
////检查用户的资金余额 是否充足
if (zichanleixing == "UDX" && (baozhengjin * 1.2) < shengyuudx && baozhengjin>0)
{
chongzu = true;
}
else if (zichanleixing == "USDT" && (baozhengjin * 1.2) < shengyuusdt && baozhengjin>0)
{
chongzu = true;
}
if (chongzu && jinzhijiancang == "0")
{
///接着检查用户的 代理商关系,以及传输过来的订单属性
string cengjiguanxi = dataSet.Tables[0].Rows[0]["cengji"].ToString();
string telkey = dataSet.Tables[0].Rows[0]["telkey"].ToString();
string dingdanbianhao = telkey + DateTime.Now.ToFileTime().ToString();
string bizhong = Request.Form["bizhong"].ToUpper().Replace("ABC","").ToString();
string cangdanleixing = Request.Form["cangdanleixing"].ToString();
string ganggan = Request.Form["ganggan"].ToString();
string zhiying = Request.Form["zhiying"].ToString();
string zhisun = Request.Form["zhisun"].ToString();
string moshi = "逐仓模式";
string weituojiage = Request.Form["weituojiage"].ToString();
double zuixinprice = ClassSql.getNewPrice(bizhong);
double chengjiaoshuliang = baozhengjin * double.Parse(ganggan) / zuixinprice;
string chicangliang = chengjiaoshuliang.ToString("f8");//8位
double shouxufeibili = double.Parse(ClassSys.getBKindAttribute(bizhong, "jiancangfeiyong"));
string shouxufei = (chengjiaoshuliang * zuixinprice * shouxufeibili).ToString("f4");//4位
string dingdanfangxiang = Request.Form["dingdanfangxiang"].ToString();
if (zichanleixing == "USDT")
{
if (cangdanleixing == "shijiadan")
{
sqlinsert = "INSERT INTO [dbo].[chicangdan]([dingdanhao] ,[zichanleixing],[bizhong],[cangdanleixing] ," +
"[ganggan] ,[baozhengjin],[zhiying],[zhisun],[moshi],[shouxufei] ,[fudongyingkui],[tongyi]," +
"[jiancangtime],[shoujihao] ,[shuliang],[dingdanfangxiang],[price],[cengji])VALUES('" +
dingdanbianhao + "','USDT','" + bizhong + "','shijiadan'," + ganggan + "," + baozhengjin + "," +
zhiying + "," + zhisun + ",'" + moshi + "'," + shouxufei + ",0,'同意',getdate(),'" +
shoujihao + "'," + chicangliang + ",'" + dingdanfangxiang + "'," + zuixinprice + ",'" + cengjiguanxi + "')" +
";UPDATE [dbo].[jiaoyizhe] SET [usdtzichan]=[usdtzichan]-CONVERT(money, '" +
baozhengjin + "')-CONVERT(money, '" + shouxufei + "') WHERE shoujihao='" + shoujihao + "';";
try
{
ClassSql.zhixingsql(sqlinsert);
Response.Write("success");
}
catch (Exception)
{
Response.Write("error");
}
}
else if (cangdanleixing == "xianjiadan")
{
sqlinsert = "INSERT INTO [dbo].[weituodan]([dingdanhao] ,[zichanleixing],[bizhong],[cangdanleixing] ," +
"[ganggan] ,[baozhengjin],[zhiying],[zhisun],[moshi],[shouxufei] ,[fudongyingkui],[tongyi]," +
"[jiancangtime],[shoujihao] ,[shuliang],[dingdanfangxiang],[price],[cengji])VALUES('" +
dingdanbianhao + "','USDT','" + bizhong + "','xianjiadan'," + ganggan + "," +
baozhengjin + "," + zhiying + "," + zhisun + ",'" + moshi + "'," + shouxufei
+ ",0,'同意',getdate(),'" + shoujihao + "'," + chicangliang + ",'" + dingdanfangxiang
+ "'," + weituojiage + ",'" + cengjiguanxi + "')" +
";UPDATE [dbo].[jiaoyizhe] SET [usdtzichan]=[usdtzichan]-CONVERT(money, '" +
baozhengjin + "') WHERE shoujihao='" + shoujihao + "';"; ;
try
{
ClassSql.zhixingsql(sqlinsert);
Response.Write("success");
}
catch (Exception)
{
Response.Write("error");
}
}
}
else if (zichanleixing == "UDX")
{
if (cangdanleixing == "shijiadan")
{
sqlinsert = "INSERT INTO [dbo].[chicangdan]([dingdanhao] ,[zichanleixing],[bizhong],[cangdanleixing] ," +
"[ganggan] ,[baozhengjin],[zhiying],[zhisun],[moshi],[shouxufei] ,[fudongyingkui],[tongyi]," +
"[jiancangtime],[shoujihao] ,[shuliang],[dingdanfangxiang],[price],[cengji])VALUES('" +
dingdanbianhao + "','UDX','" + bizhong + "','shijiadan'," + ganggan + "," + baozhengjin + "," +
zhiying + "," + zhisun + ",'" + moshi + "'," + shouxufei + ",0,'同意',getdate(),'" +
shoujihao + "'," + chicangliang + ",'" + dingdanfangxiang + "'," + zuixinprice + ",'" + cengjiguanxi + "')" +
";UPDATE [dbo].[jiaoyizhe] SET [udxzichan]=[udxzichan]-CONVERT(money, '" +
baozhengjin + "')-CONVERT(money, '" + shouxufei + "') WHERE shoujihao='" + shoujihao + "';";
try
{
ClassSql.zhixingsql(sqlinsert);
Response.Write("success");
}
catch (Exception)
{
Response.Write("error");
}
}
else if (cangdanleixing == "xianjiadan")
{
sqlinsert = "INSERT INTO [dbo].[weituodan]([dingdanhao] ,[zichanleixing],[bizhong],[cangdanleixing] ," +
"[ganggan] ,[baozhengjin],[zhiying],[zhisun],[moshi],[shouxufei] ,[fudongyingkui],[tongyi]," +
"[jiancangtime],[shoujihao] ,[shuliang],[dingdanfangxiang],[price],[cengji])VALUES('" +
dingdanbianhao + "','UDX','" + bizhong + "','xianjiadan'," + ganggan + "," +
baozhengjin + "," + zhiying + "," + zhisun + ",'" + moshi + "'," + shouxufei
+ ",0,'同意',getdate(),'" + shoujihao + "'," + chicangliang + ",'" + dingdanfangxiang
+ "'," + weituojiage + ",'" + cengjiguanxi + "')" +
";UPDATE [dbo].[jiaoyizhe] SET [udxzichan]=[udxzichan]-CONVERT(money, '" +
baozhengjin + "') WHERE shoujihao='" + shoujihao + "';";
try
{
ClassSql.zhixingsql(sqlinsert);
Response.Write("success");
}
catch (Exception)
{
Response.Write("error");
}
}
}
}
}
}
}
}
}