-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathProgram.cs
242 lines (167 loc) · 6.93 KB
/
Program.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using BitBotBackToTheFuture;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
enum TendencyMarket
{
HIGH,
NORMAL,
LOW,
VERY_LOW,
VERY_HIGH
}
class MainClass
{
//REAL NET
public static string version = "0.0.2.14";
public static string location = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + System.IO.Path.DirectorySeparatorChar;
public static string bitmexKey = "";
public static string bitmexSecret = "";
public static string bitmexKeyWeb = "";
public static string bitmexSecretWeb = "";
public static string pair = "";
public static int qtdyContacts = 0;
public static int interval = 0;
public static int intervalOrder = 0;
public static int intervalCapture = 0;
public static int intervalCancelOrder = 30;
public static int positionContracts = 0;
public static double profit = 0;
public static string bitmexDomain = "";
public static BitMEX.BitMEXApi bitMEXApi = null;
public static Object data = new Object();
public static void Main(string[] args)
{
try
{
Console.Title = "Loading...";
Console.ForegroundColor = ConsoleColor.White;
log("Deleron - Back to the future - v" + version + " - Bitmex version");
log("by Matheus Grijo ", ConsoleColor.Green);
log("GITHUB http://github.com/matheusgrijo", ConsoleColor.Blue);
log("Load config...");
String jsonConfig = System.IO.File.ReadAllText(location + "key.txt");
JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer)));
bitmexKey = jCointaner["key"].ToString();
bitmexSecret = jCointaner["secret"].ToString();
bitmexKeyWeb = jCointaner["webserverKey"].ToString();
bitmexSecretWeb = jCointaner["webserverSecret"].ToString();
bitmexDomain = jCointaner["domain"].ToString();
pair = jCointaner["pair"].ToString();
qtdyContacts = int.Parse(jCointaner["contract"].ToString());
interval = int.Parse(jCointaner["interval"].ToString());
intervalCapture = int.Parse(jCointaner["webserverIntervalCapture"].ToString());
bitMEXApi = new BitMEX.BitMEXApi(bitmexKey, bitmexSecret, bitmexDomain);
if (jCointaner["webserver"].ToString() == "enable")
{
WebServer ws = new WebServer(WebServer.SendResponse, jCointaner["webserverConfig"].ToString());
ws.Run();
System.Threading.Thread tCapture = new Thread(Database.captureDataJob);
tCapture.Start();
System.Threading.Thread.Sleep(1000);
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
if (pid != PlatformID.Unix)
{
System.Diagnostics.Process.Start(jCointaner["webserverConfig"].ToString());
}
}
log("Total open orders: " + bitMEXApi.GetOpenOrders(pair).Count);
log("");
log("Wallet: " + bitMEXApi.GetWallet());
string codeTendency = "";
//LOOP
while (true)
{
try
{
//Surf mode
String json = Http.get("https://anubis.website/api/anubis/trend/");
JContainer jTrrend = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer)));
int open = getPosition();
//OPEN LONG
if (jTrrend["data"][0]["trend"].ToString() == "LONG" )
{
if (open <= 0)
{
open = Math.Abs(open);
codeTendency = jTrrend["data"][0]["timestamp"].ToString();
bitMEXApi.MarketOrder(pair, "Buy", qtdyContacts + open);
}
}
//OPEN SHORT
if (jTrrend["data"][0]["trend"].ToString() == "SHORT")
{
if (open >= 0)
{
codeTendency = jTrrend["data"][0]["timestamp"].ToString();
bitMEXApi.MarketOrder(pair, "Sell", qtdyContacts + open);
}
}
log("wait " + interval + "ms", ConsoleColor.White);
Thread.Sleep(interval);
}
catch (Exception ex)
{
log("while true::" + ex.Message + ex.StackTrace);
}
}
}
catch (Exception ex)
{
log("ERROR FATAL::" + ex.Message + ex.StackTrace);
}
}
//By Lucas Sousa modify MatheusGrijo
static int getPosition()
{
try
{
log("getPosition...");
List<BitMEX.Position> OpenPositions = bitMEXApi.GetOpenPositions(pair);
int _qtdContacts = 0;
foreach (var Position in OpenPositions)
_qtdContacts += (int)Position.CurrentQty;
log("getPosition: " + _qtdContacts);
return _qtdContacts;
}
catch (Exception ex)
{
log("getPosition::" + ex.Message + ex.StackTrace);
throw new Exception("Error getPosition");
}
}
static string getValue(String nameList, String nameIndicator, String nameParameter)
{
String jsonConfig = System.IO.File.ReadAllText(location + "key.txt");
JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer)));
foreach (var item in jCointaner[nameList])
if (item["name"].ToString().Trim().ToUpper() == nameIndicator.ToUpper().Trim())
return item[nameParameter].ToString().Trim();
return null;
}
public static void log(string value, ConsoleColor color = ConsoleColor.White)
{
try
{
value = "[" + DateTime.Now.ToString() + "] - " + value;
Console.ForegroundColor = color;
Console.WriteLine(value);
Console.ForegroundColor = ConsoleColor.White;
System.IO.StreamWriter w = new StreamWriter(location + DateTime.Now.ToString("yyyyMMdd") + "_log.txt", true);
w.WriteLine(value);
w.Close();
w.Dispose();
}
catch { }
}
}