-
Notifications
You must be signed in to change notification settings - Fork 0
/
fMain.pas
750 lines (668 loc) · 23.8 KB
/
fMain.pas
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
unit fMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
PropFilerEh, PropStorageEh, sSkinManager, sSkinProvider,
System.UITypes, Cromis.SimpleLog, System.StrUtils,
uConst, uAppParam, dea.Status,
uCurrency, uOper,
Vcl.StdCtrls, sButton, Vcl.ExtCtrls, sPanel, Vcl.ComCtrls, sStatusBar, acProgressBar,
System.Actions, Vcl.ActnList, sPageControl, sComboBox, ABSMain, Data.DB, scControls, scGPControls, sCheckBox, sEdit, sSpinEdit, sBevel,
sMemo, sLabel, Vcl.Menus, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh, EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh,
sGroupBox, System.ImageList, Vcl.ImgList, acAlphaImageList;
type
TMainForm = class(TForm)
sSkinProvider1: TsSkinProvider;
sSkinManager1: TsSkinManager;
PropStorageEh1: TPropStorageEh;
TopPanel: TsPanel;
StartButton: TsButton;
StopButton: TsButton;
ProgressBar2: TsProgressBar;
StatusBar1: TsStatusBar;
ActionList1: TActionList;
sPageControl: TsPageControl;
tsSettings: TsTabSheet;
tsLog: TsTabSheet;
tsMain: TsTabSheet;
TelegramNoComboBox: TsComboBox;
TestTelegramButton: TsButton;
DelayEdit: TsDecimalSpinEdit;
TelegramNo2ComboBox: TsComboBox;
tsBigDeals: TsTabSheet;
MinsEdit: TsDecimalSpinEdit;
TopCntEdit: TsDecimalSpinEdit;
MinSumEdit: TsDecimalSpinEdit;
IntervalMinsEdit: TsDecimalSpinEdit;
JumpCheckBox: TsCheckBox;
FilterCheckBox: TscGPCheckBox;
CurrencyComboBox: TsComboBox;
sBevel1: TsBevel;
LogMemo: TsMemo;
SendLogsLabel: TsWebLabel;
SendSettingsLabel: TsWebLabel;
dsReturns: TDataSource;
BigPopupMenu: TPopupMenu;
NFilter: TMenuItem;
NClearFilter: TMenuItem;
dsMemBigDeals: TDataSource;
tbMemBigDealsView: TABSTable;
DateTimeField1: TDateTimeField;
StringField1: TStringField;
BooleanField1: TBooleanField;
StringField2: TStringField;
FloatField2: TFloatField;
IntegerField1: TIntegerField;
ReturnsGrid: TDBGridEh;
BigGrid: TDBGridEh;
SignalKindRadio: TsRadioGroup;
sBevel2: TsBevel;
N1: TMenuItem;
NOpenLink: TMenuItem;
ReturnsPopupMenu: TPopupMenu;
NOpenReturnsLink: TMenuItem;
ExcludeCurrenciesMemo: TsMemo;
NAddtoExcludes: TMenuItem;
NAddtoexcludesFromBig: TMenuItem;
N2: TMenuItem;
NCopyLink: TMenuItem;
NCopyLinkBig: TMenuItem;
N3: TMenuItem;
CharImageList: TsCharImageList;
dsReturns2: TDataSource;
tsTopRemoved: TsTabSheet;
Returns2Grid: TDBGridEh;
tbMemBigDealsViewPlace2: TIntegerField;
Returns2PopupMenu: TPopupMenu;
NOpenReturns2Link: TMenuItem;
NCopy2Link: TMenuItem;
MenuItem3: TMenuItem;
NAddtoExcludes2: TMenuItem;
SiteComboBox: TsComboBox;
SaveSettingsButton: TsButton;
tbMemReturnsView: TABSTable;
tbMemReturnsViewCurrency: TStringField;
tbMemReturnsViewDealsBuy: TIntegerField;
tbMemReturnsViewDealsSell: TIntegerField;
tbMemReturnsViewDeals: TIntegerField;
tbMemReturnsViewVolumeBuy: TFloatField;
tbMemReturnsViewVolumeSell: TFloatField;
tbMemReturnsViewDexLink: TStringField;
tbMemReturns2View: TABSTable;
tbMemReturns2ViewCurrency: TStringField;
tbMemReturnsDeals2Buy: TIntegerField;
tbMemReturns2ViewDealsSell: TIntegerField;
tbMemReturns2ViewDeals: TIntegerField;
tbMemReturns2ViewVolumeBuy: TFloatField;
tbMemReturns2ViewVolumeSell: TFloatField;
tbMemReturns2ViewDexLink: TStringField;
BottomPanel: TsPanel;
SortAddedRadio: TsRadioGroup;
Bottom2Panel: TsPanel;
SortRemovedRadio: TsRadioGroup;
tbMemReturnsViewLastAddedTime: TDateTimeField;
tbMemReturnsViewLastRemovedTime: TDateTimeField;
tbMemReturns2ViewLastAddedTime: TDateTimeField;
tbMemReturns2ViewLastRemovedTime: TDateTimeField;
procedure BigGridColumns5CellDataLinkClick(Grid: TCustomDBGridEh; Column: TColumnEh);
procedure BigGridGetCellParams(Sender: TObject; Column: TColumnEh; AFont:
TFont; var Background: TColor; State: TGridDrawState);
procedure BigPopupMenuPopup(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StartButtonClick(Sender: TObject);
procedure StopButtonClick(Sender: TObject);
procedure ChangeControls(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure NAddtoExcludesClick(Sender: TObject);
procedure NAddtoexcludesFromBigClick(Sender: TObject);
procedure NOpenLinkClick(Sender: TObject);
procedure NClearFilterClick(Sender: TObject);
procedure NCopyLinkBigClick(Sender: TObject);
procedure NCopyLinkClick(Sender: TObject);
procedure NFilterClick(Sender: TObject);
procedure NOpenReturnsLinkClick(Sender: TObject);
procedure PropStorageEh1AfterLoadProps(Sender: TObject);
procedure Returns2GridGetCellParams(Sender: TObject; Column: TColumnEh; AFont:
TFont; var Background: TColor; State: TGridDrawState);
procedure ReturnsGridColumns0CellDataLinkClick(Grid: TCustomDBGridEh; Column: TColumnEh);
procedure ReturnsGridGetCellParams(Sender: TObject; Column: TColumnEh; AFont:
TFont; var Background: TColor; State: TGridDrawState);
procedure ReturnsPopupMenuPopup(Sender: TObject);
procedure SaveSettingsButtonClick(Sender: TObject);
procedure SendLogsToTelegramButtonClick(Sender: TObject);
procedure SendSettingsToTelegramButtonClick(Sender: TObject);
procedure SortAddedRadioClick(Sender: TObject);
procedure SortRemovedRadioClick(Sender: TObject);
procedure TestTelegramButtonClick(Sender: TObject);
private
AlreadyRun: Boolean;
procedure EnableButtons(AEnable: Boolean);
procedure DoWork;
procedure UpdateParams(Sender: TObject = nil);
procedure ProcessOpers(const Opers: TOpArray);
procedure GoTransactionLink;
procedure GoDexCurrencyLink(tbMemTable: TABSTable);
procedure AddtoExcludes(tbMemTable: TABSTable);
procedure CopyCurrencyBigLink;
procedure CopyCurrencyLink(tbMemTable: TABSTable);
function IsAddedMenu(Sender: TObject): Boolean;
procedure xLog(const s: string; toLog: Boolean = false);
public
end;
var
MainForm: TMainForm;
implementation
uses
dea.Tools, dea.debug, dea.cl, dea.TelegramHelper, System.Types, dea.Get,
Winapi.ShellAPI, Vcl.Clipbrd,
Rest.Json,
SynCommons, SynMustache, uProcess, uDataModule;
{$R *.dfm}
procedure TMainForm.NOpenLinkClick(Sender: TObject);
begin
GoTransactionLink;
end;
procedure TMainForm.NOpenReturnsLinkClick(Sender: TObject);
begin
if IsAddedMenu(Sender) then
GoDexCurrencyLink(tbMemReturnsView)
else
GoDexCurrencyLink(tbMemReturns2View);
end;
procedure TMainForm.NCopyLinkClick(Sender: TObject);
begin
if IsAddedMenu(Sender) then
CopyCurrencyLink(tbMemReturnsView)
else
CopyCurrencyLink(tbMemReturns2View);
end;
procedure TMainForm.CopyCurrencyLink(tbMemTable: TABSTable);
var
Link: string;
begin
Link := tbMemTable.FieldByName('DexLink').AsString;
Clipboard.AsText := Link;
end;
procedure TMainForm.CopyCurrencyBigLink;
var
Hash: string;
begin
Hash := tbMemBigDealsView.FieldByName('hash').AsString;
Clipboard.AsText := AppParam.GetTokenUrl(Hash);
end;
function TMainForm.IsAddedMenu(Sender: TObject): Boolean;
begin
result := (Sender as TMenuItem).GetParentMenu.Tag = 100;
end;
procedure TMainForm.NAddtoExcludesClick(Sender: TObject);
begin
if IsAddedMenu(Sender) then
AddtoExcludes(tbMemReturnsView)
else
AddtoExcludes(tbMemReturns2View);
end;
procedure TMainForm.NAddtoexcludesFromBigClick(Sender: TObject);
begin
AddtoExcludes(tbMemBigDealsView);
end;
procedure TMainForm.ReturnsGridColumns0CellDataLinkClick(Grid: TCustomDBGridEh;
Column: TColumnEh);
begin
GoDexCurrencyLink(Grid.DataSource.DataSet as TABSTable);
end;
procedure TMainForm.BigGridColumns5CellDataLinkClick(Grid: TCustomDBGridEh;
Column: TColumnEh);
begin
GoTransactionLink;
end;
procedure TMainForm.BigGridGetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
var
Place: Integer;
begin
if tbMemBigDealsView.FieldByName('InOut').AsBoolean and (Column.FieldName <> 'hash') then begin
AFont.Color := clGreen; // scDarkGreen;
Background := scLightGreen;
end;
if (Column.FieldName = 'Place') or (Column.FieldName = 'Place2') then begin // ôèêñèðîâàííûå ïîðîãè, ÷òîáû îòðèñîâêà íå òîðìîçèëà
Place := tbMemBigDealsView.FieldByName(Column.FieldName).AsInteger;
if Place <= 5 then begin
AFont.Style := [fsBold];
AFont.Color := scDarkBlue;
end
else if Place > 30 then
AFont.Size := 8
else if Place > 50 then
AFont.Size := 7;
end;
end;
procedure TMainForm.BigPopupMenuPopup(Sender: TObject);
var
Currency, Hash: string;
begin
Currency := tbMemBigDealsView.FieldByName('Currency').AsString;
Hash := tbMemBigDealsView.FieldByName('hash').AsString;
NOpenLink.Enabled := Hash <> '';
NOpenLink.Caption := 'Îòêðûòü ññûëêó íà òðàíçàêöèþ';
NCopyLinkBig.Enabled := Hash <> '';
NCopyLinkBig.Caption := 'Êîïèðîâàòü ññûëêó';
NAddtoexcludesFromBig.Enabled := tbMemBigDealsView.FieldByName('Currency').AsString <> '';
NAddtoexcludesFromBig.Caption := 'Äîáàâèòü âàëþòó ' + tbMemBigDealsView.FieldByName('Currency').AsString + ' â èñêëþ÷åíèÿ';
end;
procedure TMainForm.ReturnsPopupMenuPopup(Sender: TObject);
begin
if (Sender as TPopupMenu).Tag = 100 then begin
NOpenReturnsLink.Enabled := tbMemReturnsView.FieldByName('DexLink').AsString <> '';
NOpenReturnsLink.Caption := 'Îòêðûòü dex-ññûëêó íà ' + tbMemReturnsView.FieldByName('Currency').AsString;
NCopyLink.Enabled := tbMemReturnsView.FieldByName('DexLink').AsString <> '';
NCopyLink.Caption := 'Êîïèðîâàòü dex-ññûëêó';
NAddtoExcludes.Enabled := tbMemReturnsView.FieldByName('Currency').AsString <> '';
NAddtoExcludes.Caption := 'Äîáàâèòü âàëþòó ' + tbMemReturnsView.FieldByName('Currency').AsString + ' â èñêëþ÷åíèÿ';
end
else begin
NOpenReturns2Link.Enabled := tbMemReturns2View.FieldByName('DexLink').AsString <> '';
NOpenReturns2Link.Caption := 'Îòêðûòü dex-ññûëêó íà ' + tbMemReturns2View.FieldByName('Currency').AsString;
NCopy2Link.Enabled := tbMemReturns2View.FieldByName('DexLink').AsString <> '';
NCopy2Link.Caption := 'Êîïèðîâàòü dex-ññûëêó';
NAddtoExcludes2.Enabled := tbMemReturns2View.FieldByName('Currency').AsString <> '';
NAddtoExcludes2.Caption := 'Äîáàâèòü âàëþòó ' + tbMemReturns2View.FieldByName('Currency').AsString + ' â èñêëþ÷åíèÿ';
end;
end;
procedure TMainForm.EnableButtons(AEnable: Boolean);
begin
StartButton.Enabled := AEnable;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
AppParam := TAppParams.Create;
AppParam.BeginUpdate;
Application.UpdateFormatSettings := false;
FormatSettings.DecimalSeparator := '.';
utc_offset := OffsetUTC2;
AlreadyRun := false;
MainForm.Caption := AppParam.AppName;
SimpleLog.RegisterLog('log', WorkingPath + main_log, 2000, 5, [lpTimestamp, lpType]);
SimpleLog.LockType := ltProcess; // ltMachine, ltNone;
Log('start ' + AppParam.AppName + ' - - - - - - - - - - - - -');
StopButton.Visible := false;
ProgressBar2.Position := 0;
ProgressBar2.Step := 1;
Status.Bind(StatusBar1, StopButton, 1);
Status.Bind(StatusBar1, ProgressBar2, 2);
{$WARN SYMBOL_PLATFORM OFF}
// SaveStringOn := DebugHook <> 0;
{$WARN SYMBOL_PLATFORM ON}
Currencies := TCurrencies.Create; // ê êàæäîé âàëþòå ïðèñîåäèíåí îáúåêò tbMem
dm.ABSDatabase1.DatabaseFileName := WorkingPath + 'data.abs';
dm.tbDeals.Open;
dm.tbDeals.IndexName := 'xHash';
dm.tbDeals.First;
dm.tbMemReturns.CreateTable;
dm.tbMemReturns.Open;
dm.tbMemReturns.IndexName := 'xCurrency';
// dm.tbMemReturns2.Open;
// dm.tbMemReturns2.IndexName := 'xCurrency';
tbMemReturnsView.Open;
tbMemReturnsView.IndexName := 'xDealsBuy';
tbMemReturns2View.Open;
tbMemReturns2View.IndexName := 'xDealsSell';
dm.tbMemBigDeals.CreateTable;
dm.tbMemBigDeals.Open;
dm.tbMemBigDeals.IndexName := 'xDateRev';
tbMemBigDealsView.Open;
tbMemBigDealsView.IndexName := 'xDateRev';
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
Log('finish');
Currencies.Free;
AppParam.Free;
dm.ABSDatabase1.CloseDataSets;
end;
procedure TMainForm.PropStorageEh1AfterLoadProps(Sender: TObject);
begin
AppParam.EndUpdate;
UpdateParams;
end;
procedure TMainForm.StartButtonClick(Sender: TObject);
begin
Status.Stopped := false;
EnableButtons(false);
StopButton.Visible := true;
ProgressBar2.Position := 0;
ProgressBar2.Visible := true;
try
UpdateParams(StartButton);
Log('AppParam = ' + AppParam.AsJson);
DoWork;
finally
Status.Update('ok');
ProgressBar2.Visible := false;
StopButton.Visible := false;
EnableButtons(true);
end;
end;
procedure TMainForm.StopButtonClick(Sender: TObject);
begin
Status.Stopped := true;
StopButton.Visible := false;
Log('Ïðåðâàíî ïîëüçîâàòåëåì');
end;
procedure TMainForm.ChangeControls(Sender: TObject);
begin
UpdateParams(Sender);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Status.Stopped := true;
CanClose := true;
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
RunTelegramHelper;
end;
procedure TMainForm.NClearFilterClick(Sender: TObject);
begin
FilterCheckBox.Checked := false;
end;
procedure TMainForm.NFilterClick(Sender: TObject);
var
Currency: string;
begin
Currency := tbMemBigDealsView.FieldByName('Currency').AsString;
if Currency <> '' then begin
AppParam.BeginUpdate;
CurrencyComboBox.Text := Currency;
FilterCheckBox.Checked := true;
AppParam.EndUpdate;
UpdateParams;
end;
end;
procedure TMainForm.SendSettingsToTelegramButtonClick(Sender: TObject);
begin
SendToTelegramHelper(AppParam.AsJson + CR + AppParam.AppName, TelegramGroupCrypto);
end;
procedure TMainForm.SendLogsToTelegramButtonClick(Sender: TObject);
begin
TelegramHelperSendLogs(AppParam.AppName, TelegramGroupCrypto);
end;
procedure TMainForm.TestTelegramButtonClick(Sender: TObject);
begin
TestTelegramHelper(AppParam.AppName, TelegramNoComboBox.ItemIndex);
end;
procedure TMainForm.UpdateParams(Sender: TObject = nil);
begin
if AppParam.InUpdate then
exit;
AppParam.Site := SiteComboBox.ItemIndex;
AppParam.Channel := TelegramNoComboBox.ItemIndex;
AppParam.Channel2 := TelegramNo2ComboBox.ItemIndex;
AppParam.Delay := Trunc(DelayEdit.Value);
if AppParam.Delay < 0 then
AppParam.Delay := 0;
AppParam.Period := Trunc(MinsEdit.Value);
AppParam.TopCnt := Trunc(TopCntEdit.Value);
AppParam.MinSum := Trunc(MinSumEdit.Value);
AppParam.IntervalMins := IntervalMinsEdit.Value;
AppParam.Jump := JumpCheckBox.Checked;
AppParam.SignalKind := TSignalKind(SignalKindRadio.ItemIndex);
AppParam.Filter := FilterCheckBox.Checked;
AppParam.CurrencyFilter := CurrencyComboBox.Text;
if AppParam.Filter then
tbMemBigDealsView.Filter := 'Currency="' + AppParam.CurrencyFilter + '"'
else
tbMemBigDealsView.Filter := '';
tbMemBigDealsView.Filtered := AppParam.Filter;
if AppParam.TopCnt <= 0 then
AppParam.TopCnt := 3;
AppParam.ExcludedCurrencies.Assign(ExcludeCurrenciesMemo.Lines);
end;
procedure TMainForm.GoTransactionLink;
var
Hash: string;
begin
Hash := tbMemBigDealsView.FieldByName('hash').AsString;
if Hash <> '' then
ShellExecute(Application.Handle, 'Open', PChar(AppParam.GetTokenUrl(Hash)), nil, nil, SW_SHOWNORMAL);
end;
procedure TMainForm.GoDexCurrencyLink(tbMemTable: TABSTable);
var
Link: string;
begin
Link := tbMemTable.FieldByName('DexLink').AsString;
if Link <> '' then
ShellExecute(Application.Handle, 'Open', PChar(Link), nil, nil, SW_SHOWNORMAL);
end;
procedure TMainForm.AddtoExcludes(tbMemTable: TABSTable);
var
Currency: string;
begin
Currency := tbMemTable.FieldByName('Currency').AsString;
if Currency <> '' then
ExcludeCurrenciesMemo.Lines.Add(Currency);
end;
procedure TMainForm.NCopyLinkBigClick(Sender: TObject);
begin
CopyCurrencyBigLink;
end;
procedure TMainForm.Returns2GridGetCellParams(Sender: TObject; Column:
TColumnEh; AFont: TFont; var Background: TColor; State: TGridDrawState);
begin
if tbMemReturns2View.FieldByName('DealsSell').AsInteger = 0 then
AFont.Color := clGrayText;
end;
procedure TMainForm.ReturnsGridGetCellParams(Sender: TObject; Column:
TColumnEh; AFont: TFont; var Background: TColor; State: TGridDrawState);
begin
if tbMemReturnsView.FieldByName('DealsBuy').AsInteger = 0 then
AFont.Color := clGrayText;
end;
// îáðàáîòêà ñäåëîê òåêóùåãî ïðîõîäà, îïðåäåëåíèå ìåñò â òîïå, îòïðàâêà ñîîáùåíèé
procedure TMainForm.ProcessOpers(const Opers: TOpArray);
var
I, cntBig: Integer;
begin
cntBig := 0; // ñ÷èòàåì áîëüøèå ñäåëêè (>= MinSum), ÷òîáû çíàòü îáíîâëÿòü ëè BigDealsView
BigGrid.SaveVertPos('hash');
ReturnsGrid.SaveVertPos('currency');
Returns2Grid.SaveVertPos('currency');
dm.tbMemBigDeals.DisableControls;
tbMemReturnsView.DisableControls;
tbMemReturns2View.DisableControls;
try
for I := 0 to high(Opers) do begin
if not Opers[I].dupl and Opers[I].IsLiquid then begin // ïîâòîðíûå îïåðàöèè ïî õåøó íå ó÷èòûâàòü
// äîáàâëÿåì â ñïèñîê âàëþò è òàáëèöó îïåðàöèé ïî âàëþòå. Èñòèíà åñëè ñäåëêà áîëüøàÿ
if Currencies.AppendMemOper(Opers[I], dm.tbMemBigDeals, AppParam.MinSum) then
Inc(cntBig); // ñ÷èòàåì ñäåëêè äîáàâëåííûå íà âêëàäêó BigDeals
end;
end;
UpdateReturns(dm.tbMemReturns{, dm.tbMemReturns2}); // ïîñ÷èòàòü îáîðîòû è îáíîâèòü ïåðâóþ âêëàäêó
SetupPlaces(CurrencyComboBox, dm.tbMemBigDeals); // çäåñü îáíîâëÿåòñÿ tbMemBigDeals
finally
if JumpCheckBox.Checked then begin
if cntBig > 0 then
tbMemBigDealsView.First;
end
else begin
tbMemBigDealsView.Refresh;
BigGrid.RestoreVertPos('hash');
end;
tbMemReturnsView.Refresh;
tbMemReturns2View.Refresh;
if not JumpCheckBox.Checked then begin
ReturnsGrid.RestoreVertPos('currency');
Returns2Grid.RestoreVertPos('currency');
end;
dm.tbMemBigDeals.EnableControls;
tbMemReturnsView.EnableControls;
tbMemReturns2View.EnableControls;
end;
SendSignal(Opers); // îáÿçàòåëüíî ïîñëå ðàñïðåäåëåíèÿ ìåñò
end;
procedure TMainForm.DoWork;
var
Op: TOper;
Rows: TRowsArray;
Cells: TRowsArray;
I, cntAdded, cntRepeat, cntError: Integer;
s: string;
// NewOper: TStringDynArray; // õåøè äîáàâëåííûå â ýòîì ïðîõîäå
Opers: TOpArray; // îïåðàöèè äîáàâëåííûå â ýòîì ïðîõîäå (50 îïåðàöèé íà ñòðàíèöå, áåç ïîâòîðîâ ïî õåøó è áåç ëèøíèõ îïåðàöèé)
(* function FindHash(Hash: string): Boolean;
var
I: Integer;
begin
result := false;
for I := 0 to high(NewOper) do begin
if NewOper[I] = Hash then
exit(true);
end;
end;
// ïðîâåðÿåò íà óíèêàëüíîñòü è äîáàâëÿåò â ìàññèâ îïåðàöèé äàííîãî ïðîõîäà
procedure AddToOpers;
begin
// åñëè âìåñòî íàçâàíèÿ àäðåñ êîøåëüêà - íå áåðåì
// if StartsStr('0x', tbDeals.FieldByName('t1').AsString) or
// StartsStr('0x', tbDeals.FieldByName('t2').AsString) then
// exit; // îïåðàöèÿ íå äëÿ íàñ
if FindHashAndMarkAsDupl(Op.Hash, Opers) then
exit; // íè÷åãî äîáàâëÿòü íå íàäî, ïîâòîðíàÿ îïåðàöèÿ ïî õåøó
Opers := Opers + [Op];
end;
*)
begin
if AlreadyRun then
exit;
AlreadyRun := true;
dm.tbDeals.DisableControls;
try
repeat
Application.ProcessMessages;
if Status.Stopped then
Break;
try
// ñ÷èòûâàåì îñíîâíóþ ñòðàíèöó, íà íåé òðàíçàêöèè
// â àïè íå íàøëà òàêîé êîìàíäû, ïðèõîäèòñÿ ïàðñèòü
s := xGet(AppParam.SiteUrl, '', nil); // StringSaveToFile(s, 'full.html');
except
on E: Exception do begin
Log('!xget ' + E.Message);
Sleep(200);
Continue;
end;
end;
cntAdded := 0;
cntRepeat := 0;
cntError := 0;
Rows := reprepTable(reprep(s, '<tbody>', '</tbody>')); // òàáëèöà
if Length(Rows) = 0 then begin
xLog('!!! íå íàéäåíû òðàíçàêöèè', true);
// <h1 class="h2 font-weight-normal">Sorry, our servers are currently busy</h1>
if AppParam.Delay < 900 then begin // àäàïòèâíî óâåëè÷èòü çàäåðæêó
AppParam.Delay := AppParam.Delay + 25;
DelayEdit.Value := AppParam.Delay;
Log('AppParam.Delay = ', AppParam.Delay);
end;
AppParam.DoSleep(4); // 4-êðàòíàÿ çàäåðæêà
Inc(cntError);
end;
if Status.Stopped then
Break;
// NewOper := nil;
Opers := nil;
for I := 0 to high(Rows) do begin // öèêë ïî ñòðîêàì îñíîâíîãî àäðåñà - 50 øòóê
Cells := reprepCells(Rows[I], '<td'); // ÿ÷åéêè îäíîé ñòðîêè
Op.ParseRow(Cells); // ïàðñèì ñòðîêó òàáëèöû â ïåðåìåííóþ op
if Op.error or not Op.IsLiquid or
(not AppParam.NeedZeroSum and (Op.amount = 0)) then // ó÷èòûâàåì òîëüêî îïåðàöèè ïî ëèêâèäíîñòè
Continue;
if not dm.FindHash(Op.Hash) then begin // èùåì õåø â áàçå - íîâûé õåø
Op.ParseStep2; // äîïàðñèòü âàëþòó è ñóììó
if Op.Currency = '' then begin
Inc(cntError);
AppParam.DoSleep;
end
else begin
Op.AppendLine(dm.tbDeals); // äîáàâëÿåò â áàçó tbDeals íà äèñêå, ñ îáðåçàíèåì
// NewOper := NewOper + [Op.Hash];
// äîáàâëÿåò â ìàññèâ îïåðàöèé ïðîõîäà
if not FindHashAndMarkAsDupl(Op.Hash, Opers) then // íè÷åãî äîáàâëÿòü íå íàäî, ïîâòîðíàÿ îïåðàöèÿ ïî õåøó
Opers := Opers + [Op]; // ýòà ïðîâåðêà ñêîðåå âñåãî ëèøíÿÿ äëÿ ëèêâèäíîñòè
Inc(cntAdded);
end
end else begin
Inc(cntRepeat);
end;
// òàêîé õåø åñòü, ìèíèìóì îäèí. Èùåì ïîëíîå ñîâïàäåíèå
// if Op.Find(dm.tbDeals) then begin // ñîâïàëè - ïðîïóñêàåì, óæå åñòü ýòà îïåðàöèÿ
/// flag := 0;
/// if FindHash(Op.Hash) then begin // åñëè äâå îäèíàêîâûõ îïåðàöèè â òåêóùåì ïðîõîäå - îøèáêà
/// Inc(cntError);
/// Log('Ïîâòîðíàÿ îïåðàöèÿ !!!! ' + Op.Hash);
/// end;
// end else begin // ñòðîêè íå ñîâïàëè - äîáàâëÿåì - äóìàþ, äëÿ ëèêâèäíîñòè íå ðåàëüíî
/// flag := 1;
// Log('Ïîâòîðíûé õåø !!!! ' + Op.Hash);
// Op.AppendLine(dm.tbDeals);
// Inc(cntChanged);
// if not FindHash(Op.Hash) then // õåø èç ïðåäûäóùèõ ïðîõîäîâ
// Inc(cntChanged2);
// AddToOpers; // äîáàâëÿåò â ìàññèâ îïåðàöèé ïðîõîäà
// end;
// end;
// Log(flag.ToString + ' : ' + Op.LogLine);
end;
xLog('[' + TimeToStr(Now) + '] Íîâûõ: ' + cntAdded.ToString +
' / ' + Length(Opers).ToString + ' / ' + Length(Rows).ToString +
IfThen(cntRepeat > 0, ', ïîâòîðîâ: ' + cntRepeat.ToString, '') + CR +
' îøèáîê: ' + cntError.ToString
);
// äîáàâèòü îïåðàöèè â òàáëèöó â ïàìÿòè (êðîìå õåøåé-ïîâòîðîâ)
ProcessOpers(Opers); // òóò æå ïðîñòàâëÿþòñÿ ìåñòà è îòñûëàþòñÿ ñîîáùåíèÿ
// Currencies.Cleanup; ïîêà íå íàäî
AppParam.DoSleep;
until false;
finally
AlreadyRun := false;
dm.tbDeals.EnableControls;
end;
end;
procedure TMainForm.SaveSettingsButtonClick(Sender: TObject);
begin
PropStorageEh1.SaveProperties;
end;
procedure TMainForm.SortAddedRadioClick(Sender: TObject);
begin
if SortAddedRadio.ItemIndex = 0 then
tbMemReturnsView.IndexName := 'xDealsBuy'
else
if SortAddedRadio.ItemIndex = 1 then
tbMemReturnsView.IndexName := 'xVolumeBuy'
else
tbMemReturnsView.IndexName := 'xLastAddedTime';
end;
procedure TMainForm.SortRemovedRadioClick(Sender: TObject);
begin
if SortRemovedRadio.ItemIndex = 0 then
tbMemReturns2View.IndexName := 'xDealsSell'
else
if SortRemovedRadio.ItemIndex = 1 then
tbMemReturns2View.IndexName := 'xVolumeSell'
else
tbMemReturns2View.IndexName := 'xLastRemovedTime';
end;
procedure TMainForm.xLog(const s: string; toLog: Boolean = false);
begin
if LogMemo.Lines.Count > 1000 then
LogMemo.Lines.Clear;
LogMemo.Lines.Add(s);
if toLog then
Log(s);
end;
initialization
SetDefStorage;
end.