관리자 0 676 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
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.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>();
 
        public MainForm()
        {
            InitializeComponent();
 
            /*
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand connCmd = new OleDbCommand();
            Console.WriteLine("mainform start");
            try
            {
                Console.WriteLine("db access 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 = "INSERT INTO favorite(usr_id) VALUES(@usr_id)";
                connCmd.Parameters.Add(new OleDbParameter("@usr_id", "test"));
                connCmd.ExecuteNonQuery();    // 입력
                connCmd.CommandText = "SELECT * FROM favorite";
                OleDbDataReader oleData = connCmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (oleData.Read())
                {
                    Console.WriteLine(oleData["userId"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            */
 
            /*
            Dictionary<int, string> test = new Dictionary<int, string>();
            test[0] = "000";
            test[1] = "111";
            test[2] = "222";
            test.Remove(1);
            foreach(KeyValuePair<int, string> row in test)
            {
                Console.WriteLine("key = " + row.Key + " / value = " + row.Value);
            }
            */
 
            /*
            Dictionary<string, string> test = new Dictionary<string, string>();
            test["111"] = "value_111";
            test["222"] = "value_222";
            Dictionary<string, string> test2 = test;
            Dictionary<string, string> test3 = test;
            test2["111"] = "value_111_change";
            Console.WriteLine(test3["111"]);
            */
 
            listView1.MouseDoubleClick += new MouseEventHandler(listView1_MouseDoubleClick); //즐겨찾기 row 더블클릭
        }
 
        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);
 
                //stock[코드번호][거래량][체결mktime] = stock_sign 배열   
                process.Text = code_name + "(" + code + ") 체결 리스트" + Environment.NewLine;
                foreach (KeyValuePair<stringDictionary<string, stock_row>> row in stock[code])
                {
                    string 체결량 = row.Key;
 
                    foreach (KeyValuePair<string, stock_row> row2 in row.Value)
                    {
                        string 체결mktime = row2.Key;
                        string 종목명 = row2.Value.code_name;
                        //string 체결량 = row2.Value.sign_cnt;
                        string 체결시간 = row2.Value.sign_YmdHis;
                        string 규칙성 = row2.Value.규칙성;
 
                        process.Text += 종목명 + " : " + 체결량 + " / " + 체결시간 + " / " + 규칙성 + 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;
        }
 
        //전체종목리스트에서 주식 row를 클릭하면 실행
        /*
        private void listBoxStock_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine("ok");
        }
        //관심종목리스트에서 주식 row를 클릭하면 실행
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine("ok");
        }
        */
 
        //종목리스트 불러오기
        private void ButtonListCall_Click(object sender, EventArgs e)
        {
            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]); //관심종목추가
                                listView1_cnt++;
 
                                axKHOpenAPI1.SetRealReg("0120", code, "20;15""1");
                            }
                            else
                            {
                                item.Checked = false;
                            }
 
                            //SubItem
                            item.SubItems.Add(i.ToString());
                            item.SubItems.Add(StockName);
                            item.SubItems.Add(code);
 
                            ListViewStock.Items.Add(item);
                            i++;
                        }
                    }
                }
 
                전체종목리스트_초기체크 = false;
 
                //axKHOpenAPI1.SetInputValue("종목코드", 000030.ToString());
                //axKHOpenAPI1.CommRqData("000030_주식기본정보", "opt10001", 0, "0101");
                //axKHOpenAPI1.SetRealReg("0120", "000030", "9001;302;10;11;25;12;13", "1");  // 000030 종목을 실시간 추가등록
            }
        }
 
        //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);
                }
                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);
                }
 
                listView1_loading();
            }
        }
 
        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_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 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);
            }
        }
 
 
 
        private void 반복체크(int 다음, int 갭, string 코드번호, string 거래량, bool 첫루프)
        {
            if (!stock[코드번호][거래량].ContainsKey(다음.ToString()))
            {
                return;
            }
            else
            {
                string 분초단위갭 = TimeShow(갭);
                stock[코드번호][거래량][다음.ToString()].규칙성 = 분초단위갭;
 
                if (첫루프 == true)
                {
                    int 이전 = 다음 - 갭;
                    int 이이전 = 이전 - 갭;
                    stock[코드번호][거래량][이전.ToString()].규칙성 = 분초단위갭;
                    stock[코드번호][거래량][이이전.ToString()].규칙성 = 분초단위갭;
                }
 
                int 다다음 = 다음 + 갭;
                반복체크(다다음, 갭, 코드번호, 거래량, false);
            }
        }
 
        //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 규칙성;
        }
        //분석하기 버튼클릭
        //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)
        {
            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 = "20170118"//일단 테스트를 위해
 
            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 += "데이터뽑기 종료" + 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());
                        foreach (KeyValuePair<string, stock_row> value2 in 체결량_리스트2)
                        {
                            string value2_mktime = value2.Value.sign_mktime; //2
                            int 갭 = int.Parse(value2_mktime) - int.Parse(value1_mktime);
                            int 다음 = int.Parse(value2_mktime) + 갭;
 
                            반복체크(다음, 갭, 코드번호, 거래량, true);
                        }
                    }
                }
 
                process.Text += "- " + CodeToString[종목코드] + " 분석종료" + Environment.NewLine;
            }
 
            //stock[코드번호][거래량][체결mktime] = stock_sign 배열
            /*
            foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, stock_row>>> row in stock)
            {
                string 종목코드 = row.Key;
                //하나하나씩 비교하자.
                foreach (KeyValuePair<string, Dictionary<string, stock_row>> row2 in row.Value)
                {
                    string 체결량 = row2.Key;
                    Dictionary<string, stock_row> 체결량_리스트 = new Dictionary<string, stock_row>(row2.Value);
                    foreach (KeyValuePair<string, stock_row> value1 in 체결량_리스트)
                    {
                        string 종묙명 = value1.Value.code_name;
                        string 거래량 = value1.Value.sign_cnt;
                        string 체결가 = value1.Value.sign_price;
                        string 체결시간 = value1.Value.sign_YmdHis;
                        string 규칙성 = value1.Value.규칙성;
                        //process.Text += 종목명 + " : " + 거래량 + " / " + 체결시간 + " / " + 규칙성 + Environment.NewLine;
                    }
                }
            }
            */
 
            /*
             *  걍 어렵게 생각할 필요없고 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  
             */
        }
 
        ///////////////////////////////////////////////////////// 자체제작 라이브러리
 
        //타임스템프 => 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)
            {
                time = 0;
            }
 
            return time;
        }
 
        public static string TimeShow(int second)
        {
            string return_minute = Regex.Replace((second / 60).ToString(), @"\d+", n => n.Value.PadLeft(2'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


카테고리