관리자 2 795 0 0

힘든 여정이었다.

나름 알파고 이상의 패턴분석 알고리즘을 탑재했다고 생각은 든다만 결과가 어디까지 나와줄지 미지수다...

이제 클라이언트들에게 미래를 맡길 차례다...

자 돈을 벌어 보시오!

 

 

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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
 
namespace Auto_Stock
{
    public partial class MainForm : Form
    {
        private string LoginName;
        private string LoginId;
 
        private string accFileName = "stock_db.accdb";
        private string dbPasswd = "admin";
 
        bool IsListCall = false;
        bool 전체종목리스트_초기체크 = true;
        Dictionary<stringstring> CodeToString = new Dictionary<stringstring>();
        Dictionary<stringstring> CodeToLine = new Dictionary<stringstring>(); //즐겨찾기 삭제시 사용
        private static Dictionary<stringstring> 코드번호_To_시가총액 = new Dictionary<stringstring>();
        private System.Windows.Forms.Timer 타이머 = new System.Windows.Forms.Timer();
 
        public MainForm()
        {
            InitializeComponent();
            //listView1.MouseDoubleClick += new MouseEventHandler(listView1_MouseDoubleClick); //즐겨찾기 row 더블클릭
 
            /*
            Dictionary<string, ttt> test = new Dictionary<string, ttt>();
            test["111"] = new ttt();
            test["222"] = new ttt();
            test["222"].ddd = "222_value";
            test["333"] = new ttt();
            test["222"].Set_ddd("222_value_modify");
            test["222"].Set_ddd("222_value_modify");
            foreach (KeyValuePair<string, ttt> rrr in test)
            {
                Console.WriteLine(rrr.Value.ddd_count);
            }
            */
 
            /*
            Dictionary<string, string> test = new Dictionary<string, string>();
            test["111"] = "111_value";
            test["444"] = "222_value";
            test["333"] = "333_value";
            foreach(KeyValuePair<string, string> row in test.OrderByDescending(key => key.Key))
            {
                Console.WriteLine(row.Value);
            }
            */
            //.OrderBy(key => key.Value)
 
            /*
            Dictionary<string, string> test = new Dictionary<string, string>();
            foreach(KeyValuePair<string, string> r in test)
            {
                MessageBox.Show(r.Value);
            }
            */
 
            
            //하루가 지난 체결정보들 모두 삭제
            Dictionary<intstring> columns = new Dictionary<intstring>();
            columns[0= "sign_Ymd";
            Dictionary<intDictionary<stringstring>> list = database_select("SELECT TOP 1 * FROM stock_sign ORDER BY idx desc", columns);
            //MessageBox.Show(list[0]["sign_Ymd"]);
 
            if(list.Count > 0)
            {
                if (list[0]["sign_Ymd"!= DateTime.Now.ToString("yyyy"+ DateTime.Now.ToString("MM"+ DateTime.Now.ToString("dd"))
                {
                    //MessageBox.Show("하루가 지났넹");
                    OleDbConnection conn = new OleDbConnection();
                    OleDbCommand connCmd = new OleDbCommand();
                    try
                    {
                        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + accFileName + ";Mode=ReadWrite;Jet OLEDB:Database Password=" + dbPasswd;
                        conn.Open();
                        connCmd.Connection = conn;
 
                        connCmd.CommandText = "delete from stock_sign";
                        connCmd.ExecuteNonQuery();
 
                        connCmd.CommandText = "INSERT INTO stock_sign(idx) VALUES(0)";
                        connCmd.ExecuteNonQuery();
 
                        connCmd.CommandText = "delete from stock_sign";
                        connCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception 에러발생 : " + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
 
        /*
        private class ttt
        {
            public string ddd = "ddddd";
            public int ddd_count = 0;
            public void Set_ddd(string ddd_string)
            {
                ddd = ddd_string;
                ddd_count++;
            }
        }
        */
 
        //분석결과리스트 더블클릭
        private void listView2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listView2.SelectedItems.Count == 1)
            {
                ListView.SelectedListViewItemCollection items = listView2.SelectedItems;
                ListViewItem lvItem = items[0];
                string code = lvItem.SubItems[1].Text;
                string code_name = lvItem.SubItems[2].Text;
                textBox2.Text = "";
                int TotalCnt = 0;
                foreach (KeyValuePair<stringDictionary<string, stock_row>> row in stock[code])
                {
                    string 체결량 = row.Key;
                    Dictionary<string, ArrayList> 반복패턴 = new Dictionary<string, ArrayList>(); //규칙성을 기준으로 배열을 재조립한다.
                    foreach (KeyValuePair<string, stock_row> row2 in row.Value)
                    {
                        string 체결mktime = row2.Key;
                        string 종목명 = row2.Value.code_name;
                        string 체결시간 = row2.Value.sign_YmdHis;
                        string 규칙성 = row2.Value.규칙성;
 
                        if(규칙성 != null)
                        {
                            if(!반복패턴.ContainsKey(규칙성))
                            {
                                반복패턴[규칙성] = new ArrayList();
                            }
                            반복패턴[규칙성].Add(row2.Value);
                        }
                    }
 
                    string log = "";
                    int cnt = 0;
                    foreach(KeyValuePair<string, ArrayList> 패턴로우 in 반복패턴)
                    {
                        string 규칙성 = 패턴로우.Key;
                        if(패턴로우.Value.Count > 0)
                        {
                            float 초당결제금액 = 0;
                            foreach(stock_row stock_item in 패턴로우.Value) //같은패턴의 리스트
                            {
                                string[] 규칙성_split = stock_item.규칙성.Split(':');
                                int 규칙성초단위 = (int.Parse(규칙성_split[0]) * 60+ int.Parse(규칙성_split[1]);
 
                                int 패턴_체결량 = int.Parse(stock_item.sign_cnt);
                                int 패턴_체결가 = int.Parse(stock_item.sign_price.Replace("-"""));
                                초당결제금액 = 패턴_체결량 * 패턴_체결가 / 규칙성초단위;
                                break//평균이니깐 걍 1번만 돌고 나가자, 어차피 체결량이랑 규칙성초단위는 모두 동일하기 때문에~(체결가도 같다도 봐도 무방함)
                            }
 
                            string 카운트 = Regex.Replace(패턴로우.Value.Count.ToString(), @"\d+", n => n.Value.PadLeft(3'0'));
                            log += "규칙성 : " + 규칙성 + " => 반복 = " + 카운트 + " | 초당체결금액 = " + string.Format("{0:n0}", 초당결제금액) + Environment.NewLine;
                            cnt++;
                            TotalCnt++;
                        }
                    }
 
                    if(cnt > 0)
                    {
                        log = "체결량(" + 체결량 + ") 패턴" + Environment.NewLine + log;
                        log += Environment.NewLine;
                    }
 
                    textBox2.Text += log;
                }
 
                if(TotalCnt == 0)
                {
                    textBox2.Text = code + " 패턴이 존재하지 않습니다.";
                }
            }
        }
 
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            /*
            Console.WriteLine(e.Button);
            Console.WriteLine(e.Clicks);
            Console.WriteLine(e.Delta);
            Console.WriteLine(e.Location);
            */
 
            //Console.WriteLine(listView1.SelectedItems.Count);
            if(listView1.SelectedItems.Count == 1)
            {
                ListView.SelectedListViewItemCollection items = listView1.SelectedItems;
                ListViewItem lvItem = items[0];
                string code = lvItem.SubItems[1].Text;
                string code_name = lvItem.SubItems[2].Text;
                //MessageBox.Show("선택한행 : " + code + ", " + code_name);
 
                if(stock.ContainsKey(code))
                {
                    //stock[코드번호][거래량][체결mktime] = stock_sign 배열   
                    //process.Text = code_name + "(" + code + ") 체결 리스트" + Environment.NewLine;
                    //process.Text += Environment.NewLine;
                    foreach (KeyValuePair<stringDictionary<string, stock_row>> row in stock[code])
                    {
                        string 체결량 = row.Key;
                        if (int.Parse(체결량) > 0)
                        {
                            if (체결량.Substring(01!= "+")
                            {
                                체결량 = "+" + 체결량;
                            }
                        }
                        체결량 = Regex.Replace(체결량.ToString(), @"\d+", n => n.Value.PadLeft(5'0')); //다섯자리 숫자로 만들기
 
                        foreach (KeyValuePair<string, stock_row> row2 in row.Value)
                        {
                            string 체결mktime = row2.Key;
                            string 종목명 = row2.Value.code_name;
                            string 체결시간 = row2.Value.sign_YmdHis;
                            string 규칙성 = row2.Value.규칙성;
 
                            process.Text += 종목명 + " : " + 체결량 + " / " + 체결시간 + " / " + 규칙성 + Environment.NewLine;
                        }
                        //process.Text += Environment.NewLine;
                    }
                }
                else
                {
                    process.Text = "코드값("+code+") 수집 데이터가 존재하지 않습니다." + Environment.NewLine;
                }
            }
        }
 
        private void database_proc(string sql, Dictionary<stringstring> param)
        {
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand connCmd = new OleDbCommand();
            try
            {
                conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + accFileName + ";Mode=ReadWrite;Jet OLEDB:Database Password=" + dbPasswd;
                conn.Open();
                connCmd.Connection = conn;
 
                //connCmd.CommandText = "INSERT INTO favorite(usr_id) VALUES(@usr_id)";
                connCmd.CommandText = sql;
                foreach (KeyValuePair<stringstring> row in param)
                {
                    //connCmd.Parameters.Add(new OleDbParameter("@usr_id", "test"));
                    connCmd.Parameters.Add(new OleDbParameter(row.Key, row.Value));
                }
                connCmd.ExecuteNonQuery();    // 입력
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception 에러발생 : " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
 
        private Dictionary<intDictionary<stringstring>> database_select(string sql, Dictionary<intstring> columns)
        {
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand connCmd = new OleDbCommand();
            Dictionary<intDictionary<stringstring>> list = new Dictionary<intDictionary<stringstring>>();
            try
            {
                Console.WriteLine("select start");
                conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + this.accFileName + ";Mode=ReadWrite;Jet OLEDB:Database Password=" + this.dbPasswd;
                conn.Open();
                connCmd.Connection = conn;
 
                //connCmd.CommandText = "SELECT * FROM favorite";
                connCmd.CommandText = sql;
                OleDbDataReader oleData = connCmd.ExecuteReader(CommandBehavior.CloseConnection);
                int i = 0;
                while (oleData.Read())
                {
                    //Console.WriteLine("usr_id = " + oleData["usr_id"].ToString());
                    Dictionary<stringstring> list_row = new Dictionary<stringstring>();
                    foreach(KeyValuePair<intstring> row in columns)
                    {
                        string column = row.Value;
                        list_row[column] = oleData[column].ToString();
                    }
                    list[i++= list_row;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }
 
            return list;
        }
 
        //로그인 버튼 클릭
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            if(LoginName != null)
            {
                MessageBox.Show("이미 로그인 하셨습니다.");
                return;
            }
 
            long Result;
            Result = axKHOpenAPI1.CommConnect();
            if (Result != 0)
            {
                Console.WriteLine("로그인창 열기 실패!");
            }
            else
            {
                Console.WriteLine("로그인창 열기 성공!");
            }
        }
 
        //로그인 후 개인정보 가져오기
        private void axKHOpenAPI1_OnEventConnect(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnEventConnectEvent e)
        {
            Console.WriteLine("개인정보 가져오기 성공!");
            string UserName = axKHOpenAPI1.GetLoginInfo("USER_NAME");
            string UserId = axKHOpenAPI1.GetLoginInfo("USER_ID");
            //ButtonLogin.Text = UserName + "(" + axKHOpenAPI1.GetLoginInfo("USER_ID") +  ")";
            ButtonLogin.Text = axKHOpenAPI1.GetLoginInfo("USER_ID");
            LoginName = UserName;
            LoginId = UserId;
 
            ButtonListCall_Proc(); //주식리스트, 즐겨찾기 리스트 불러오기
        }
 
        //전체종목리스트에서 주식 row를 클릭하면 실행
        /*
        private void listBoxStock_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine("ok");
        }
        //관심종목리스트에서 주식 row를 클릭하면 실행
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine("ok");
        }
        */
 
        int 화면번호 = 0;
        private void ButtonListCall_Proc()
        {
            if (LoginName == null)
            {
                MessageBox.Show("로그인이 필요합니다.");
            }
            else
            {
                if (IsListCall == true)
                {
                    //MessageBox.Show("이미 호출된 상태입니다.");
                    //return;
                }
 
                Dictionary<stringstring> favorite_list = listVIew1_select();
                //Console.WriteLine(favorite_list);
 
                IsListCall = true;
 
                전체종목리스트_초기체크 = true;
                listView1.Items.Clear();
                ListViewStock.Items.Clear();
                ListViewStock.CheckBoxes = true// 항목옆에 확인란을 표시할지 여부를 선택합니다.
                //ListViewStock.Click += new EventHandler(ListViewCheckClick);
                //ListViewStock.OwnerDraw = true;
 
                //GetCodeListByMarket 메소드는 메소드의 인자로 시장 구분 코드를 문자열로 넘겨주면 메소드의 리턴 값으로 해당 시장에 속해 있는 종목들의 종목 코드 목록을 리턴
                //sMarket – 0:장내, 3:ELW, 4:뮤추얼펀드, 5:신주인수권, 6:리츠, 8:ETF, 9:하이일드펀드, 10:코스닥, 30:제3시장
                Console.WriteLine("종목 불러오기 시작");
                string[] marketList = { "0""10" };
                int InCnt = 0;
                int OutCnt = 0;
                int i = 0;
                foreach (string MNumber in marketList)
                {
                    string result = axKHOpenAPI1.GetCodeListByMarket(MNumber);
                    string[] stockList = result.Split(';');
 
                    if (MNumber == "0")
                    {
                        InCnt = stockList.Count();
                    }
                    else
                    {
                        OutCnt = stockList.Count();
                    }
 
                    int listView1_cnt = 0;
                    foreach (string code in stockList)
                    {
                        if (code != "")
                        {
                            string StockName = axKHOpenAPI1.GetMasterCodeName(code);
 
                            CodeToString[code] = StockName;
 
                            //전체종목리스트 ListView row 만들자
                            ListViewItem item = new ListViewItem(""0);
                            item.Checked = false// 체크박스는 일단 false
                            if (favorite_list.ContainsKey(code))
                            {
                                item.Checked = true;
                                listView1_add(listView1_cnt.ToString(), code, favorite_list[code]); //관심종목추가
                                //CodeToLine[code] = listView1_cnt.ToString(); //라인정보 추가
                                listView1_cnt++;
 
                                //Thread workerThread = new Thread(new ThreadStart(call));
                                화면번호++;
                                axKHOpenAPI1.SetRealReg(화면번호.ToString(), code, "20;15""1"); //실시간으로 DB에 체결정보를 넣기위해 호출한다.
                                //call_시가총액(code);
 
                                /*
                                Thread t = new Thread(new ParameterizedThreadStart(call_thread));
                                t.Start(code);
                                t.Join();
                                */
                            }
                            else
                            {
                                item.Checked = false;
                            }
 
                            //SubItem
                            item.SubItems.Add(i.ToString());
                            item.SubItems.Add(StockName);
                            item.SubItems.Add(code);
 
                            ListViewStock.Items.Add(item);
                            i++;
                        }
                    }
                }
 
                listView1_sort_proc();
 
                전체종목리스트_초기체크 = false;
 
                //axKHOpenAPI1.SetInputValue("종목코드", 000030.ToString());
                //axKHOpenAPI1.CommRqData("000030_주식기본정보", "opt10001", 0, "0101");
                //axKHOpenAPI1.SetRealReg("0120", "000030", "9001;302;10;11;25;12;13", "1");  // 000030 종목을 실시간 추가등록
 
                btn_ana_Click_Proc(); //DB불러오기
            }
        }
 
        private void call_thread(object code)
        {
            Console.WriteLine(code.ToString() + " 쓰레드 호출");
            axKHOpenAPI1.SetRealReg("0120", code.ToString(), "20;15""1"); //실시간으로 DB에 체결정보를 넣기위해 호출한다.
        }
 
        //종목리스트 불러오기
        private void ButtonListCall_Click(object sender, EventArgs e)
        {
            ButtonListCall_Proc();
        }
 
        //ListView의 이벤트는 [디자인]창에서 속성모드에서 function 명을 추가해서 사용하자.
        //[전체종목리스트] 체크박스 클릭시 발생
        private void ListViewStock_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            //Console.WriteLine("ListViewStock_ItemChecked");
            //Console.WriteLine(e.Item.Checked); //true or false
            if (전체종목리스트_초기체크 == false//초기로딩시에는 실행이 되면 안됨!
            {
                //Console.WriteLine(e.Item.SubItems.Count); //라인의 컬럼개수(4개)
                //Console.WriteLine(e.Item.Index); //라인 row index 번호
                //Console.WriteLine(e.Item.SubItems[2].Text); //유한양행
                if (e.Item.Checked == true)
                {
                    string sql = "INSERT INTO favorite(usr_id, stock_code, stock_name) VALUES(@usr_id, @stock_code, @stock_name)";
                    Dictionary<stringstring> param = new Dictionary<stringstring>();
                    param["@usr_id"= LoginId;
                    param["@stock_code"= e.Item.SubItems[3].Text; //000060
                    param["@stock_name"= e.Item.SubItems[2].Text; //하이트진로
                    database_proc(sql, param);
 
                    axKHOpenAPI1.SetRealReg("0120", e.Item.SubItems[3].Text, "20;15""1"); //실시간으로 DB에 체결정보를 넣기위해 호출한다.
 
                    //listView1_add(number, row.Key, row.Value); //번호, 종목코드, 종목명
                    /*
                    var items = listView1.Items;
                    var last = items[items.Count - 1];
                    last.EnsureVisible();
                    */
                    var r = Enumerable.Empty<ListViewItem>();
                    if (this.listView1.Items.Count > 0)
                    {
                        r = this.listView1.Items.OfType<ListViewItem>();
                    }
                    var last = r.LastOrDefault();
 
                    int 순번 = 0;
                    if (last != null)
                    {
                        //Console.WriteLine(last); //{9}
                        //Console.WriteLine(last.Index); //9
                        순번 = last.Index + 1;
                    }
 
                    listView1_add(순번.ToString(), param["@stock_code"], param["@stock_name"]); //즐찾목록 추가
                    listView1_sort_proc();
 
                    //call_시가총액(param["@stock_code"]);
                }
                else
                {
                    string sql = "DELETE FROM favorite WHERE usr_id = @usr_id AND stock_code = @stock_code";
                    Dictionary<stringstring> param = new Dictionary<stringstring>();
                    param["@usr_id"= LoginId;
                    param["@stock_code"= e.Item.SubItems[3].Text; //000060
                    database_proc(sql, param);
 
                    //axKHOpenAPI1.SetRealReg("0120", e.Item.SubItems[3].Text, "20;15", "0"); //실시간 DB 체결정보 해제
                    axKHOpenAPI1.SetRealRemove("0120", e.Item.SubItems[3].Text);
 
                    //삭제
                    int 삭제라인 = int.Parse(CodeToLine[param["@stock_code"]]);
                    listView1.Items[삭제라인].Remove();
                    listView1_sort_proc();
                }
 
                //listView1_loading();
            }
        }
 
        private void call_시가총액(string code)
        {
            //Console.WriteLine("시가총액 호출하자");
            axKHOpenAPI1.SetInputValue("종목코드", code);
            axKHOpenAPI1.CommRqData(code + "_주식기본정보""opt10001"0"0101");
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewStock.Items.Count; i++)
            {
                ListViewStock.Items[i].Checked = true;
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewStock.Items.Count; i++)
            {
                ListViewStock.Items[i].Checked = false;
            }
        }
 
        //즐겨찾기 라인재정렬
        private void listView1_sort_proc()
        {
            int i = 0;
            CodeToLine = new Dictionary<stringstring>();
            foreach (ListViewItem itemRow in listView1.Items)
            {
                itemRow.SubItems[0].Text = i.ToString();
                CodeToLine[itemRow.SubItems[1].Text] = i.ToString(); //라인정보 추가
                i++;
            }
        }
 
        private void listView1_loading()
        {
            listView1.Items.Clear();
            Dictionary<stringstring> favorite_list = listVIew1_select();
            int i = 0;
            foreach (KeyValuePair<stringstring> row in favorite_list)
            {
                string number = i.ToString();
                listView1_add(number, row.Key, row.Value);
                i++;
            }
        }
 
        private Dictionary<stringstring> listVIew1_select()
        {
            Dictionary<intstring> columns = new Dictionary<intstring>();
            int ci = 0;
            columns[ci++= "stock_code";
            columns[ci++= "stock_name";
            Dictionary<intDictionary<stringstring>> list = database_select("SELECT * FROM favorite WHERE usr_id = '" + LoginId + "'", columns);
            Dictionary<stringstring> favorite_list = new Dictionary<stringstring>();
            foreach (KeyValuePair<intDictionary<stringstring>> row in list)
            {
                //Console.WriteLine(row.Value["stock_code"] + " => " + row.Value["stock_name"]);
                favorite_list[row.Value["stock_code"]] = row.Value["stock_name"];
            }
 
            return favorite_list;
        }
 
        //관심종목 추가
        private void listView1_add(string number, string code, string codeString)
        {
            ListViewItem item2 = new ListViewItem(number, 0);
            item2.SubItems.Add(code);
            item2.SubItems.Add(codeString);
            item2.SubItems.Add("[ 리스트 GO! ]");
 
            listView1.Items.Add(item2);
        }
 
        //실시간 시세 이벤트라는데 뭔지 잘 몰겠다.
        //이게 보니깐 주기적으로 호출이 된다... 아마도 특정초단위로 알아서 호출되는 건가보다...
        private void axKHOpenAPI1_OnReceiveRealData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            //Console.WriteLine("sRealKey : " + e.sRealKey);
            //Console.WriteLine("sRealType : " + e.sRealType);
            //Console.WriteLine("sRealData : " + e.sRealData);
 
            //e.sRealKey = 종목코드
            //e.sRealType = 리얼타입 (주식시세, 주식체결 등)
            //e.sRealData = 실시간 데이터 전문
 
            if (e.sRealType == "주식체결")
            {
                string 현재가 = axKHOpenAPI1.GetCommRealData(e.sRealKey, 10);
                string 체결량 = axKHOpenAPI1.GetCommRealData(e.sRealKey, 15);
                string 체결시간 = axKHOpenAPI1.GetCommRealData(e.sRealKey, 20);
 
                /*
                Console.WriteLine("=======================" + e.sRealKey + "==================================");
                Console.WriteLine("현재가 : " + 현재가);
                Console.WriteLine("체결량 : " + 체결량);
                Console.WriteLine("체결시간 : " + 체결시간);
                */
 
                /*
                 * =======================000030==================================
                 * 현재가   : +12800
                 * 체결량   : +116
                 * 체결시간 : 121850
                 * 
                 * stock_sign 테이블 스키마
                 * idx, code, code_name, sign_price, sign_cnt, sign_mktime, sign_YmdHis, sign_Ymd
                 */
 
                string sql = "";
                sql += "INSERT INTO stock_sign(code, code_name, sign_price, sign_cnt, sign_mktime, sign_YmdHis, sign_Ymd)";
                sql += "VALUES(@code, @code_name, @sign_price, @sign_cnt, @sign_mktime, @sign_YmdHis, @sign_Ymd)";
                Dictionary<stringstring> param = new Dictionary<stringstring>();
                param["@code"]          = e.sRealKey; //종목코드번호
                param["@code_name"]     = CodeToString[e.sRealKey];
                param["@sign_price"]    = 현재가;
                param["@sign_cnt"]      = 체결량;
                param["@sign_mktime"]   = GetMktime(체결시간).ToString();
                param["@sign_YmdHis"]   = DateTime.Now.ToString("yyyy"+ DateTime.Now.ToString("MM"+ DateTime.Now.ToString("dd"+ " " + 체결시간;
                param["@sign_Ymd"]      = DateTime.Now.ToString("yyyy"+ DateTime.Now.ToString("MM"+ DateTime.Now.ToString("dd");
                database_proc(sql, param);
 
                //DB에 넣었으니 변수에도 적용해야지
                if (!stock.ContainsKey(e.sRealKey))
                    stock[e.sRealKey] = new Dictionary<stringDictionary<string, stock_row>>();
 
                if (!stock[e.sRealKey].ContainsKey(체결량))
                    stock[e.sRealKey][체결량] = new Dictionary<string, stock_row>();
 
                if (!stock[e.sRealKey][체결량].ContainsKey(param["@sign_mktime"]))
                    stock[e.sRealKey][체결량][param["@sign_mktime"]] = new stock_row();
 
                //규칙성이 있는지 확인하고, 있으면 추가하자(거꾸로 올라가기)
                foreach (KeyValuePair<string, stock_row> item in stock[e.sRealKey][체결량].OrderByDescending(key => key.Key))
                {
                    //Console.WriteLine("row = " + item.Value.code + " | " + item.Value.sign_YmdHis + " | " + item.Value.code_name + " | " + item.Value.sign_price);
                    //Console.WriteLine(item.Value.sign_YmdHis);
                    //Console.WriteLine(param["@sign_mktime"] + " - " + item.Value.sign_mktime + " = " + 갭);
                    if(item.Value.sign_mktime == null)
                    {
                        continue;
                    }
 
                    int 갭 = int.Parse(param["@sign_mktime"]) - int.Parse(item.Value.sign_mktime);
                    if(갭 == 0)
                    {
                        continue;
                    }
 
                    int 다음 = int.Parse(item.Value.sign_mktime) - 갭;
                    int 시작 = 다음 - 1;
                    int 종료 = 다음 + 1;
                    for (int 체결키 = 시작; 체결키 <= 종료; 체결키++)
                    {
                        string 키 = 체결키.ToString();
                        if (stock[e.sRealKey][체결량].ContainsKey(키)) //3
                        {
                            string 규칙성 = stock[e.sRealKey][체결량][키].규칙성;
                            if (stock[e.sRealKey][체결량][키].규칙성 == null)
                            {
                                규칙성 = TimeShow(갭);
                            }
 
                            stock[e.sRealKey][체결량][param["@sign_mktime"]].규칙성 = 규칙성;
                            //Console.WriteLine(CodeToString[e.sRealKey] + " => 규칙성 : " + 규칙성);
                            break;
                        }
                    }
                }
 
                stock[e.sRealKey][체결량][param["@sign_mktime"]].code = e.sRealKey;
                stock[e.sRealKey][체결량][param["@sign_mktime"]].code_name = param["@code_name"];
                stock[e.sRealKey][체결량][param["@sign_mktime"]].sign_price = 현재가;
                stock[e.sRealKey][체결량][param["@sign_mktime"]].sign_cnt = 체결량;
                stock[e.sRealKey][체결량][param["@sign_mktime"]].sign_mktime = param["@sign_mktime"];
                stock[e.sRealKey][체결량][param["@sign_mktime"]].sign_YmdHis = param["@sign_YmdHis"];
                stock[e.sRealKey][체결량][param["@sign_mktime"]].sign_Ymd = param["@sign_Ymd"];
            }
        }
 
 
        //stock[코드번호][거래량][체결mktime] = stock_sign 배열
        private void 반복체크(int 다음, int 갭, string 코드번호, string 거래량)
        {
            //Console.WriteLine("코드번호 = " + 코드번호 + " | 거래량 = " + 거래량);
            //Console.WriteLine(다음);
 
            int 시작 = 다음 - 1;
            int 종료 = 다음 + 1;
            int 다다음 = 0;
            string 다음키 = null;
            for(int CheckKey = 시작; CheckKey <= 종료; CheckKey++)
            {
                string 체크키 = CheckKey.ToString();
                if(stock[코드번호][거래량].ContainsKey(체크키))
                {
                    if(stock[코드번호][거래량][체크키].규칙성 == null)
                    {
                        다다음 = CheckKey + 갭;
                        다음키 = CheckKey.ToString();
                        break;
                    }
                }
            }
 
            if(다다음 != 0//다음 규칙성이 존재한다면
            {
                string return_minute = Regex.Replace((갭 / 60).ToString(), @"\d+", n => n.Value.PadLeft(3'0'));
                string return_second = Regex.Replace((갭 % 60).ToString(), @"\d+", n => n.Value.PadLeft(2'0'));
                string 규칙성 = return_minute + ":" + return_second;
 
                stock[코드번호][거래량][다음키].Set_규칙성(규칙성);
 
                반복체크(다다음, 갭, 코드번호, 거래량);
            }
        }
 
        //stock 딕셔너리에 저장될 클래스 데이터
        private class stock_row
        {
            public string code;
            public string code_name;
            public string sign_price;
            public string sign_cnt;
            public string sign_mktime;
            public string sign_YmdHis;
            public string sign_Ymd;
            public string 규칙성 = null;
            public void Set_규칙성(string 기모띠_규칙성)
            {
                규칙성 = 기모띠_규칙성;
                /*
                if (규칙성 == null)
                {
                    규칙성 = 기모띠_규칙성;
                }
                else
                {
                    //Console.WriteLine("이미 규칙성이 존재함.(" + 규칙성 + " != " + 기모띠_규칙성 + ")" + where);
                    //Console.WriteLine("where = " + where + " | " + t1 + " ? " + t2);
                    if(t1 == t2)
                    {
                        Console.WriteLine("같은데???");
                    }
                }
                */
            }
        }
 
        //땡겨오기 버튼클릭
        //stock[코드번호][거래량][체결mktime] = stock_sign 배열
        Dictionary<stringDictionary<stringDictionary<string, stock_row>>> stock = new Dictionary<stringDictionary<stringDictionary<string, stock_row>>>();
        private void btn_ana_Click(object sender, EventArgs e)
        {
            btn_ana_Click_Proc();
        }
 
        private void btn_ana_Click_Proc()
        {
            stock = new Dictionary<stringDictionary<stringDictionary<string, stock_row>>>();
 
            Console.WriteLine("데이터뽑기 시작");
 
            Dictionary<intstring> columns = new Dictionary<intstring>();
            int ci = 0;
 
            columns[ci++= "code";
            columns[ci++= "code_name";
            columns[ci++= "sign_price";   //현재가
            columns[ci++= "sign_cnt";     //체결량
            columns[ci++= "sign_mktime";  //체결_mktime
            columns[ci++= "sign_YmdHis";
            columns[ci++= "sign_Ymd";
 
            string sign_Ymd = DateTime.Now.ToString("yyyy"+ DateTime.Now.ToString("MM"+ DateTime.Now.ToString("dd"); //실사용코드 - 오늘데이터 분석
            //string sign_Ymd = "20170131"; //일단 테스트를 위해
 
            Dictionary<intDictionary<stringstring>> list = database_select("SELECT * FROM stock_sign WHERE sign_Ymd = '" + sign_Ymd + "' ORDER BY idx ASC", columns);
            foreach (KeyValuePair<intDictionary<stringstring>> row in list)
            {
                int sort = row.Key;
 
                if (!stock.ContainsKey(row.Value["code"]))
                {
                    stock[row.Value["code"]] = new Dictionary<stringDictionary<string, stock_row>>();
                }
 
                if (!stock[row.Value["code"]].ContainsKey(row.Value["sign_cnt"]))
                {
                    stock[row.Value["code"]][row.Value["sign_cnt"]] = new Dictionary<string, stock_row>();
                }
 
                if (!stock[row.Value["code"]][row.Value["sign_cnt"]].ContainsKey(row.Value["sign_mktime"]))
                {
                    stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]] = new stock_row();
                }
 
                //stock[코드번호][거래량][체결mktime] = stock_sign 배열
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].code = row.Value["code"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].code_name = row.Value["code_name"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].sign_price = row.Value["sign_price"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].sign_cnt = row.Value["sign_cnt"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].sign_mktime = row.Value["sign_mktime"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].sign_YmdHis = row.Value["sign_YmdHis"];
                stock[row.Value["code"]][row.Value["sign_cnt"]][row.Value["sign_mktime"]].sign_Ymd = row.Value["sign_Ymd"];
 
                //CodeToString[code] = StockName;
                if (!CodeToString.ContainsKey(row.Value["code"]))
                {
                    CodeToString[row.Value["code"]] = row.Value["code_name"];
                }
            }
 
            Console.WriteLine("데이터뽑기 종료");
            process.Text = "분석 실행 시간 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"+ Environment.NewLine;
            process.Text += Environment.NewLine;
            //process.Text += "데이터뽑기 종료" + Environment.NewLine;
 
            /*
            //자료 잘 들어갔는지 확인
            foreach(Dictionary<string, string> value in stock["000030"]["-5"])
            {
                string test = value["sign_YmdHis"];
                Console.WriteLine(test);
            }
            */
 
            //종목을 돌자
            //stock[코드번호][거래량][체결mktime] = stock_sign 배열
            foreach (KeyValuePair<stringDictionary<stringDictionary<string, stock_row>>> row in stock)
            {
                string 종목코드 = row.Key;
 
                //하나하나씩 비교하자.
                foreach (KeyValuePair<stringDictionary<string, stock_row>> row2 in row.Value)
                {
                    string 체결량 = row2.Key;
                    Dictionary<string, stock_row> 체결량_리스트1 = new Dictionary<string, stock_row>(row2.Value);
                    Dictionary<string, stock_row> 체결량_리스트2 = new Dictionary<string, stock_row>(row2.Value);
                    foreach (KeyValuePair<string, stock_row> value1 in 체결량_리스트1)
                    {
                        string 코드번호 = value1.Value.code;
                        //string 거래량 = value1.Value.sign_cnt;
                        string value1_mktime = value1.Value.sign_mktime; //1
 
                        체결량_리스트2.Remove(체결량_리스트2.Keys.First());
 
                        if (stock[코드번호][체결량][value1_mktime].규칙성 != null)
                        {
                            //규칙성이 존재하면 비교를 할 필요가 없지
                            //Console.WriteLine("value1 규칙성 = " + stock[코드번호][체결량][value1_mktime].규칙성);
                            continue;
                        }
 
                        foreach (KeyValuePair<string, stock_row> value2 in 체결량_리스트2)
                        {
                            string value2_mktime = value2.Value.sign_mktime; //2
                            if (stock[코드번호][체결량][value2_mktime].규칙성 != null)
                            {
                                //규칙성이 존재하면 비교를 할 필요가 없지
                                //Console.WriteLine("value2 규칙성 = " + stock[코드번호][체결량][value2_mktime].규칙성);
                                continue;
                            }
 
                            int 갭 = int.Parse(value2_mktime) - int.Parse(value1_mktime);
 
                            if (갭 != 0)
                            {
                                int 다음 = int.Parse(value2_mktime) + 갭;
                                //Console.WriteLine("= s");
                                반복체크(다음, 갭, 코드번호, 체결량);
                                //Console.WriteLine("e =");
                                //Console.WriteLine("");
                            }
                        }
                    }
                }
 
                //process.Text += "- " + CodeToString[종목코드] + " 분석종료" + Environment.NewLine;
            }
            process.Text += Environment.NewLine;
 
            순위리스트생성();
 
            타이머.Interval = 5000//100 => 0.1 second
            타이머.Tick += new EventHandler(timerHandler);
            타이머.Start(); //The countdown is launched!
 
            /*
            int rank = 0;
            foreach (KeyValuePair<string, float> row in 순위.OrderBy(key => key.Value))
            {
                rank++;
                ListViewItem item = new ListViewItem(rank.ToString(), 0);
                item.SubItems.Add(row.Key);
                item.SubItems.Add(CodeToString[row.Key]);
                item.SubItems.Add(row.Value.ToString());
                listView2.Items.Add(item);
            }
            */
 
            /*
             *  걍 어렵게 생각할 필요없고 1초당 체결금액을 알아내면 됨
             * 
                시총(시가총액)
 
                1000억에 100만원을 기준으로 = 0.00001(시가총액 * 0.00001) 금액을 마지막에 빼는거임.
                100 - 분당 규칙패턴 = 순위가 가장 높은순으로
                2분 간격으로 5번 반복하고 가격이 100만원 이고 10개씩 구매했다면 = 1000만원이 2분 간격으로 5번 반복하는 거임
                그러면 1분에 500만원을 사게 된다는 규칙이 성립되는 것이고
                .....
                ....
                ...
                ..
                .
                계속 반복패턴 찾아서 그 분당 금액을 모두 더한다...
                1분당 100
                1분당 40
                뭐 이렇게 쌓이다가.... 토탈이 900이 나왔으면 900 - 100(0.001) = 800 이 되는거임... 
 
 
                500 - 100(0.001) = 400(순위반영)이 되는거임
 
                기준은 반복 5회이상....
 
 
 
 
                특정시간을 정해서 하면 좋을거 같은데???
                장내,코스닥만???
 
 
                1. 클릭 -> 분당금액 리스트 보여주고... 총합계보여주고 총합계 - (시가총액 * 0.001) => 금액
                2. 
                ....
                ...
                10.
 
 
                분단위 규칙성 합계금액
                ---------------------- *  100 => 제일 높은거
                  시가총액 * 0.00001  
             */
        }
 
        private void 순위리스트생성()
        {
            //순위[코드] = 점수
            //stock[코드번호][거래량][체결mktime] = stock_sign 배열
            //process.Text = "===== 순위 분석 시작 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " =====" + Environment.NewLine;
            Dictionary<stringfloat> 순위 = new Dictionary<stringfloat>();
            foreach (KeyValuePair<stringDictionary<stringDictionary<string, stock_row>>> row in stock) //코드별 루프
            {
                순위[row.Key] = 0;
                foreach (KeyValuePair<stringDictionary<string, stock_row>> row2 in row.Value) //거래량 루프
                {
                    Dictionary<stringbool> 중복체크 = new Dictionary<stringbool>();
                    foreach (KeyValuePair<string, stock_row> row3 in row2.Value) //리스트
                    {
                        string 규칙성 = row3.Value.규칙성;
                        if (규칙성 != null)
                        {
                            if (!중복체크.ContainsKey(규칙성))
                            {
                                //초당점수 구하자
                                string[] 규칙성_split = 규칙성.Split(':');
                                int 규칙성초단위 = (int.Parse(규칙성_split[0]) * 60+ int.Parse(규칙성_split[1]);
 
                                int 체결량 = int.Parse(row2.Key);
                                //int 체결가 = int.Parse(row3.Value.sign_price.Replace("-", "")); //체결가를 빼버리자, 금액높은 종목만 상위로 갈수도 있으니...
                                int 체결가 = 1;
                                float 초당점수 = 체결량 * 체결가 / 규칙성초단위;
 
                                순위[row.Key] += 초당점수;
 
                                중복체크[규칙성] = true;
                            }
                        }
                    }
 
                    //여기서 시가총액 나누자.
                    //Console.WriteLine(CodeToString[row.Key] + " 의 시가총액 = " + 코드번호_To_시가총액[row.Key]);
                }
 
                //process.Text += row.Key + " 점수 = " + 순위[row.Key] + Environment.NewLine;
            }
            //process.Text += "===== 순위 분석 종료 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " =====" + Environment.NewLine;
 
            //분석결과리스트 만들기
            //전체종목리스트 ListView row 만들자
            listView2.Items.Clear();
            var items = from row in 순위
                        orderby row.Value descending
                        select row;
 
            // Display results.
            int rank = 0;
            foreach (KeyValuePair<stringfloat> row in items)
            {
                rank++;
                ListViewItem item = new ListViewItem(rank.ToString(), 0);
                item.SubItems.Add(row.Key); //종목코드
                item.SubItems.Add(CodeToString[row.Key]); //종목명
                item.SubItems.Add(string.Format("{0:n0}", row.Value)); //분석금액
                listView2.Items.Add(item);
            }
        }
 
        private void axKHOpenAPI1_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            string[] tmp = e.sRQName.Split('_');
            string CodeNumber = tmp[0];
            string sRQName = tmp[1];
 
            //Console.WriteLine(sRQName);
            if (sRQName == "주식기본정보")
            {
                /*
                content += "종목명 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "종목명").Trim() + Environment.NewLine;
                content += "등락율 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "등락율").Trim() + Environment.NewLine;
                content += "거래량 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "거래량").Trim() + Environment.NewLine;
                content += "시가 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "시가").Trim() + Environment.NewLine;
                content += "고가 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "고가").Trim() + Environment.NewLine;
                content += "저가 : " + axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "저가").Trim() + Environment.NewLine;
                MessageBox.Show(content);
                */
 
                //각 종목별로 시가총액을 저장하자.
                string 시가총액 = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0"시가총액").Trim();
                if(시가총액 != "" && !코드번호_To_시가총액.ContainsKey(CodeNumber))
                {
                    코드번호_To_시가총액[CodeNumber] = 시가총액; //시가총액은 단위가 (억)임.
                    //Console.WriteLine("시가총액(" + CodeNumber + " : " + CodeToString[CodeNumber] + ") = " + 시가총액);
                }
            }
        }
 
        //순위재집결
        private void re_sort_Click(object sender, EventArgs e)
        {
            순위리스트생성();
        }
 
        private void timerHandler(object sender, System.EventArgs e)
        {
            //타이머.Stop();
            //타이머 = new System.Windows.Forms.Timer(); //꼭 재시작 해줘야 한다.
 
            순위리스트생성();
        }
 
        ///////////////////////////////////////////////////////// 자체제작 라이브러리
 
        //타임스템프 => MKTIME
        static DateTime ConvertFromUnixTimestamp(double timestamp)
        {
            DateTime origin = new DateTime(1970119000);
            return origin.AddSeconds(timestamp);
        }
 
        //MKTIME => HHiiss
        static string TimestampToHis(int mktime)
        {
            // 2016-10-10 오후 2:46:16 => 14:46:16
            // 타임 스템프 값을 hhiiss 값으로 변경하기...
            DateTime test = ConvertFromUnixTimestamp(mktime);
            string test2 = test.ToString();
            string[] test3 = test2.Split(' ');
            string[] test4 = test3[2].Split(':');
            string test5 = "";
            int i = 0;
            foreach (string str in test4)
            {
                string ttt = "";
                if (test3[1== "오후" && i == 0)
                {
                    ttt = (int.Parse(str) + 12).ToString();
                }
                else
                {
                    ttt = str;
                }
 
                string str2 = Regex.Replace(ttt, @"\d+", n => n.Value.PadLeft(2'0'));
                string add = "";
                if (i < 2)
                {
                    add = ":";
                }
                test5 += str2 + add;
                i++;
            }
 
            return test5;
        }
 
        static int GetMktime(string time_data)
        {
            int year = int.Parse(DateTime.Now.ToString("yyyy"));
            int month = int.Parse(DateTime.Now.ToString("MM"));
            int day = int.Parse(DateTime.Now.ToString("dd"));
            int hour = int.Parse(time_data.ToString().Substring(02));
            int minute = int.Parse(time_data.ToString().Substring(22));
            int second = int.Parse(time_data.ToString().Substring(42));
 
            if (hour < 9)
            {
                return 999999;
            }
 
            DateTime dt = new DateTime(year, month, day, hour - 9, minute, second);
 
            int time;
            try
            {
                time = ConvertDatetimeToInt(dt);
            }
            catch (System.IndexOutOfRangeException e)
            {
                Console.WriteLine(e);
                time = 0;
            }
 
            return time;
        }
 
        public static string TimeShow(int second)
        {
            string return_minute = Regex.Replace((second / 60).ToString(), @"\d+", n => n.Value.PadLeft(3'0'));
            string return_second = Regex.Replace((second % 60).ToString(), @"\d+", n => n.Value.PadLeft(2'0'));
 
            return return_minute + ":" + return_second;
        }
 
        public static int ConvertDatetimeToInt(System.DateTime dt)
        {
            System.TimeSpan ts = dt.Subtract(new System.DateTime(197011));
            return (int)(ts.Ticks / 10000000L);
        }
    }
}
 
cs

 

Comments [2]

비회원
안녕하세요~ 올려주신걸로 만들어보고 싶어서 공부해보는데 워낙 초보라 어렵네요.
처음부터 따라하기 식으로 배워볼만한 책이나, 동영상 추천 해주실게 있으신지 알려주시면 감사하겠습니다.
10 마스터욱
답변      추천 
글쎄요... 저도 모르는건 구글로 검색해가면서 공부하면서 만든거라...
C# 은 아니지만 파이썬으로는 추천할 만한 곳이 있습니다.
https://wikidocs.net/2872

카테고리