-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDatabase.cs
92 lines (74 loc) · 2.92 KB
/
Database.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using BitBotBackToTheFuture;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Database
{
//private static string dataBaseFile = MainClass.location + "bd.xml";
public static void captureDataJob()
{
while (true)
{
try
{
captureData();
}
catch
{
}
System.Threading.Thread.Sleep(MainClass.intervalCapture);
}
}
public static void captureData()
{
lock (MainClass.data)
{
string dataBaseFile = MainClass.location + "bd.xml";
try
{
System.Data.DataSet ds = null;
bool create = false;
if (!System.IO.File.Exists(dataBaseFile))
{
System.Data.DataTable dt = new System.Data.DataTable("Balances");
dt.Columns.Add("Date");
dt.Columns.Add("Coin");
dt.Columns.Add("Amount");
dt.Rows.Add("", "", "");
System.Data.DataTable dtParameters = new System.Data.DataTable("Parameters");
dtParameters.Columns.Add("Parameter");
dtParameters.Columns.Add("Value");
dtParameters.Rows.Add("", "");
ds = new System.Data.DataSet();
ds.DataSetName = "Database";
ds.Tables.Add(dt);
ds.Tables.Add(dtParameters);
ds.WriteXml(dataBaseFile);
create = true;
}
ds = new System.Data.DataSet();
ds.ReadXml(dataBaseFile);
BitMEX.BitMEXApi bitMEXApi = new BitMEX.BitMEXApi(MainClass.bitmexKey, MainClass.bitmexSecret, MainClass.bitmexDomain);
string json = bitMEXApi.GetWallet();
JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer)));
//ClassDB.execS(ClassDB.dbquery.Replace("@balance", jCointaner[0]["walletBalance"].ToString().Replace(",", ".")));
if (create)
ds.Tables[0].Rows.Clear();
ds.Tables[0].Rows.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MainClass.pair, jCointaner[0]["walletBalance"].ToString());
ds.Tables[1].Rows.Clear();
ds.Tables[1].Rows.Add("OpenOrders", bitMEXApi.GetOpenOrders(MainClass.pair).Count);
ds.Tables[1].Rows.Add("Amount", jCointaner[0]["walletBalance"].ToString());
System.IO.File.Delete(dataBaseFile);
ds.WriteXml(dataBaseFile);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}