public static int updaterecord(int position) { string jsonStrings = File.ReadAllText("real/position.json", Encoding.Default); JObject abc = JObject.Parse(jsonStrings); JToken positiontoken = abc["user"][0]["position"]; int positions = Convert.ToInt32(positiontoken); if (positions != 0) { string bs = "0"; if (positions > 0) { bs = "B"; } if (positions < 0) { bs = "S"; } string result = string.Join("|", Spapidll.LastGetTrade()); string[] ary = result.Split('|'); if (ary[0] == "1") { string update = File.ReadAllText("real/position.json", Encoding.Default); JObject updates = JObject.Parse(update); updates["user"][0]["id"] = ary[1]; updates["user"][0]["BS"] = bs; updates["user"][0]["price"] = ary[3]; updates["user"][0]["cases"] = ary[4]; string updatestring = Convert.ToString(updates); //将json装换为string File.WriteAllText("real/position.json", updatestring); //将内容写进jon文件中 } } return(0); }
public static int testdel(string code) { string jsonStrings = File.ReadAllText("real/waitlist.json", Encoding.Default); JObject abc = JObject.Parse(jsonStrings); JToken idtoken = abc["user"][0]["id"]; int iid = Convert.ToInt32(idtoken); string id = idtoken.ToString(); if (iid != 0) { Spapidll.DeleteOrder(id, code); } return(0); }
public static int testch(string ChangePrice) { string jsonStrings = File.ReadAllText("real/waitlist.json", Encoding.Default); JObject abc = JObject.Parse(jsonStrings); JToken idtoken = abc["user"][0]["id"]; JToken casestoken = abc["user"][0]["cases"]; int iid = Convert.ToInt32(idtoken); string cases = casestoken.ToString(); string id = idtoken.ToString(); if (iid != 0) { Spapidll.ChangeOrder(id, ChangePrice, cases); } return(0); }
public static int tradeoperate() { DateTime dt = DateTime.Now; int hour = Convert.ToInt32(dt.Hour.ToString()); //13 int min = Convert.ToInt32(dt.Minute.ToString()); //13 int sec = Convert.ToInt32(dt.Second.ToString()); //13 int nowsec = Convert.ToInt32(hour) * 60 * 60 + Convert.ToInt32(min) * 60 + Convert.ToInt32(sec); string jsonStrings = File.ReadAllText("real/trade.json", Encoding.Default); JObject abc = JObject.Parse(jsonStrings); JToken actiontoken = abc["user"][0]["action"]; JToken codetoken = abc["user"][0]["code"]; JToken bstoken = abc["user"][0]["bs"]; JToken pricetoekn = abc["user"][0]["price"]; JToken qtytoekn = abc["user"][0]["qty"]; JToken casestoekn = abc["user"][0]["cases"]; int action = Convert.ToInt32(actiontoken); string code = codetoken.ToString(); string bs = bstoken.ToString(); string price = pricetoekn.ToString(); string qty = qtytoekn.ToString(); string cases = casestoekn.ToString(); if (action == 1) { string update = File.ReadAllText("real/trade.json", Encoding.Default); JObject updates = JObject.Parse(update); updates["user"][0]["action"] = 0; updates["user"][0]["code"] = 0; updates["user"][0]["bs"] = 0; updates["user"][0]["price"] = 0; updates["user"][0]["qty"] = 0; updates["user"][0]["cases"] = 0; updates["user"][0]["totalsec"] = nowsec; string updatestring = Convert.ToString(updates); //将json装换为string File.WriteAllText("real/trade.json", updatestring); //将内容写进jon文件中 Spapidll.AddOrder(Convert.ToChar(bs), price, code, qty, cases, 0.ToString()); } return(0); }
public static int sell(int count, string code) { if (count == 0) { string jsonStrings = File.ReadAllText("setting/setting.json", Encoding.Default); JObject abc = JObject.Parse(jsonStrings); JToken price = abc["sell"][0]["price"]; JToken operate = abc["sell"][0]["operate"]; int ioperate = Convert.ToInt32(operate); int iprice = Convert.ToInt32(price); if (ioperate > 0) { string jsonStrings2 = File.ReadAllText("setting/setting.json", Encoding.Default); JObject abc2 = JObject.Parse(jsonStrings2); abc2["sell"][0]["price"] = 0; abc2["sell"][0]["operate"] = 0; string updatestring2 = Convert.ToString(abc2); //将json装换为string File.WriteAllText("setting/setting.json", updatestring2); //将内容写进jon文件中 Spapidll.AddOrder('S', iprice.ToString(), code, 1.ToString(), "0:0:0:0:0:selfsell", 0.ToString()); } } return(0); }
public static int recordlasttrade() { string result = string.Join("|", Spapidll.LastGetTrade()); string[] ary = result.Split('|'); DateTime dt = DateTime.Now; int hour = Convert.ToInt32(dt.Hour.ToString()); //13 int min = Convert.ToInt32(dt.Minute.ToString()); //13 int sec = Convert.ToInt32(dt.Second.ToString()); //13 int totalsec = Convert.ToInt32(hour) * 60 * 60 + Convert.ToInt32(min) * 60 + Convert.ToInt32(sec); if (ary[0] == "1") { string update = File.ReadAllText("real/recordlasttrade.json", Encoding.Default); JObject updates = JObject.Parse(update); updates["user"][0]["id"] = ary[1]; updates["user"][0]["price"] = ary[3]; updates["user"][0]["cases"] = ary[4]; updates["user"][0]["time"] = totalsec; string updatestring = Convert.ToString(updates); //将json装换为string File.WriteAllText("real/recordlasttrade.json", updatestring); //将内容写进jon文件中 } return(0); }
public static int testbs(string bs, string code, string price, string qty, string ClOrderId) { //讀取user DateTime dt = DateTime.Now; int hour = Convert.ToInt32(dt.Hour.ToString()); //13 int min = Convert.ToInt32(dt.Minute.ToString()); //13 int sec = Convert.ToInt32(dt.Second.ToString()); //13 int nowsec = Convert.ToInt32(hour) * 60 * 60 + Convert.ToInt32(min) * 60 + Convert.ToInt32(sec); int wcount = Spapidll.countorder(); int uposition = Spapidll.GetPosByProduct(code); string[] ary = ClOrderId.Split(':'); int countresult = Spapidll.countorder(); realposition.delmorewait(countresult, code); string record = File.ReadAllText("real/recordlasttrade.json", Encoding.Default); JObject records = JObject.Parse(record); JToken totalsectoken = records["user"][0]["time"]; JToken casestoken = records["user"][0]["cases"]; string cases = casestoken.ToString(); int totalsec = Convert.ToInt32(totalsectoken); string[] caseary = cases.Split(':'); if (ary[5] == "peisellcase2" || ary[5] == "peibuycase2") { if ((wcount == 0) && uposition != 0) { char buy_sell = '0'; if (bs == "1") { buy_sell = 'B'; } if (bs == "2") { buy_sell = 'S'; } string DecInPrice = "0"; trade.writetrade(code, buy_sell.ToString(), price, qty, ClOrderId); } } else if (ary[5] == "3timesell" || ary[5] == "3timebuy") { if ((wcount == 0) && uposition == 0) { char buy_sell = '0'; if (bs == "1") { buy_sell = 'B'; } if (bs == "2") { buy_sell = 'S'; } string DecInPrice = "0"; if (nowsec > totalsec + 120) { trade.writetrade(code, buy_sell.ToString(), price, qty, ClOrderId); } } } else { if ((wcount == 0) && uposition != 0) { char buy_sell = '0'; if (bs == "1") { buy_sell = 'B'; } if (bs == "2") { buy_sell = 'S'; } string DecInPrice = "0"; trade.writetrade(code, buy_sell.ToString(), price, qty, ClOrderId); } } return(0); }
public static void Init() { APIDLL = new Spapidll(); APIDLL.init(); }