-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
94 lines (84 loc) · 2.8 KB
/
Form1.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
using BinanceAPI.db;
using BinanceAPI.services;
using BinanceAPI.utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BinanceAPI
{
public partial class MainForm : Form
{
List<ExchangeService> m_cryptoExchanges = new() { new BinanceService(), new KucoinService() };
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
LogToForm.Instance.Init(ProcessMessage);
}
private void ProcessMessage(Msg msg)
{
string message =
$"[{DateTime.Now.ToString("hh:mm:ss")}]\t{msg.Source.PadLeft(15, '-')}\t{msg.Content}\r\n";
Invoke(new Action(() =>
{
switch (msg.Type)
{
case 1:
BinanceLog.Text = message + BinanceLog.Text;
break;
case 2:
KuCoinLog.Text = message + KuCoinLog.Text;
break;
case 3:
HuobiLog.Text = message + HuobiLog.Text;
break;
}
}));
}
private void StartButton_Click(object sender, EventArgs e)
{
StartButton.Enabled = false;
PauseButton.Enabled = true;
foreach (var exchangeService in m_cryptoExchanges)
{
exchangeService.UpdateProductsStat();
}
}
private void PauseButton_Click(object sender, EventArgs e)
{
PauseButton.Text = "Resume";
foreach (var exchangeService in m_cryptoExchanges)
{
exchangeService.Suspend();
}
}
private void ConnectButton_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "d:\\";
openFileDialog.Filter = "SQLite database (*.db)|*.db|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
DatabaseLabel.Text = Path.GetFileName(openFileDialog.FileName);
foreach (var exchange in m_cryptoExchanges)
{
exchange.DatabasePath = openFileDialog.FileName;
}
}
}
}
}
}