웹스쿨

init 초기세팅 본문

개인 프로젝트/C# 키움 주식 자동매매

init 초기세팅

마스터욱 2023. 3. 30. 01:51
반응형

개발이 어느정도 진행이 되었지만, 개발에 심취한 나머지 개발일지를 기록하지 못했습니다.

지금이라도 조금씩 일지를 적어 보겠습니다.

아래 소스는 초기 프로그램 실행시 시작되는 부분입니다.(키움 로그인은 이미 완료가 된 상태로 간주)

 

  1. public condition(Form1 form1)
  2. {
  3.     if (form1.login_id == "")
  4.     {
  5.         MessageBox.Show("로그인 후 이용가능합니다.");
  6.     }
  7.     else
  8.     {
  9.         /*
  10.         20,7 200(4% 수익시 매도)
  11.         20,9 200(4% 수익시 매도)
  12.         20,11 200(4% 수익시 매도)
  13.         20,13 600(5% 수익시 매도)
  14.         20,15 1200(5% 수익시 매도)
  15.         */
  16.         //추가매수간격은 2%
  17.         /*
  18.         수익구조["1"] = new Dictionary<string, string>();
  19.         수익구조["1"]["price"] = "200000";
  20.         수익구조["1"]["benefit"] = "4";
  21.  
  22.         수익구조["2"] = new Dictionary<string, string>();
  23.         수익구조["2"]["price"] = "200000";
  24.         수익구조["2"]["benefit"] = "4";
  25.  
  26.         수익구조["3"] = new Dictionary<string, string>();
  27.         수익구조["3"]["price"] = "200000";
  28.         수익구조["3"]["benefit"] = "4";
  29.  
  30.         수익구조["4"] = new Dictionary<string, string>();
  31.         수익구조["4"]["price"] = "600000";
  32.         수익구조["4"]["benefit"] = "5";
  33.  
  34.         수익구조["5"] = new Dictionary<string, string>();
  35.         수익구조["5"]["price"] = "1200000";
  36.         수익구조["5"]["benefit"] = "5";
  37.         */
  38.  
  39.         //세팅
  40.         수익구조["1"] = new Dictionary<string, string>();
  41.         수익구조["2"] = new Dictionary<string, string>();
  42.         수익구조["3"] = new Dictionary<string, string>();
  43.         수익구조["4"] = new Dictionary<string, string>();
  44.         수익구조["5"] = new Dictionary<string, string>();
  45.  
  46.         //MessageBox.Show(getCurrentTime().ToString()); //ex)20180621114927
  47.  
  48.         InitializeComponent();
  49.         //parent = (Form1)this.MdiParent;
  50.         fparent = form1;
  51.  
  52.         fparent.axKHOpenAPI1.OnReceiveConditionVer += this.axKHOpenAPI_OnReceiveConditionVer;
  53.         fparent.axKHOpenAPI1.OnReceiveTrCondition += this.axKHOpenAPI_OnReceiveTrCondition;
  54.         fparent.axKHOpenAPI1.OnReceiveRealCondition += this.axKHOpenAPI_OnReceiveRealCondition;
  55.         fparent.axKHOpenAPI1.OnReceiveTrData += this.axKHOpenAPI_OnReceiveTrData;
  56.         fparent.axKHOpenAPI1.OnReceiveRealData += this.axKHOpenAPI_OnReceiveRealData;
  57.         fparent.axKHOpenAPI1.OnReceiveChejanData += this.axKHOpenApi_OnReceiveChejanData;
  58.         Console.WriteLine("API Function 등록완료");
  59.  
  60.         //getConditionButton.Click += this.button_Clicked;
  61.         setRealButton.Click += this.button_Clicked;
  62.         removeRealButton.Click += this.button_Clicked;
  63.         autoTradingbutton.Click += this.button_Clicked;
  64.  
  65.         this.conditionGridView.SelectionChanged += this.DataGridView_SelectionChanged;
  66.  
  67.         //매수 종목 제한 개수 불러오기
  68.         dynamic api_result = fparent.get_api_data("get_buy_count");
  69.         textbox_buy_count.Text = api_result.data.buy_count;
  70.         get_buy_count = int.Parse(textbox_buy_count.Text);
  71.  
  72.         //자동매매세팅 불러오기
  73.         api_result = fparent.get_api_data("get_buy_setting");
  74.         if(api_result.data.exists == "OK")
  75.         {
  76.             setting_money_1.Text = api_result.data.setting_money_1;
  77.             setting_money_2.Text = api_result.data.setting_money_2;
  78.             setting_money_3.Text = api_result.data.setting_money_3;
  79.             setting_money_4.Text = api_result.data.setting_money_4;
  80.             setting_money_5.Text = api_result.data.setting_money_5;
  81.  
  82.             setting_benefit_1.Text = api_result.data.setting_benefit_1;
  83.             setting_benefit_2.Text = api_result.data.setting_benefit_2;
  84.             setting_benefit_3.Text = api_result.data.setting_benefit_3;
  85.             setting_benefit_4.Text = api_result.data.setting_benefit_4;
  86.             setting_benefit_5.Text = api_result.data.setting_benefit_5;
  87.  
  88.             set_setting();
  89.         }
  90.  
  91.         //계좌정보 가져오기
  92.         string[] acountArray = fparent.axKHOpenAPI1.GetLoginInfo("ACCNO").Split(';');
  93.        accountComboBox.Items.AddRange(acountArray);
  94.         accountComboBox.SelectedIndex = 0;
  95.         if (accountComboBox.SelectedItem.ToString().Length > 0)
  96.         {
  97.             currentAccount = accountComboBox.SelectedItem.ToString();
  98.          
  99.             refresh_buylist();    //매수 보도판 불러오기
  100.             requestProfitInfo();  //실현손익 갱신
  101.             requestAccountInfo(); //주식잔고 + 금일평가손익 갱신
  102.  
  103.             //autobuy_event();
  104.             /*
  105.             timer = new System.Timers.Timer(5000);
  106.             timer.Elapsed += new ElapsedEventHandler(timeEvent);
  107.             timer.Start();
  108.             */
  109.         }
  110.  
  111.         int result = fparent.axKHOpenAPI1.GetConditionLoad();
  112.         if(result > 0)
  113.         {
  114.             setLog("조건리스트 불러오기 성공");
  115.         }
  116.  
  117.         //매도취소테스트
  118.         /*
  119.         int sell_result = fparent.axKHOpenAPI1.SendOrder("주식주문", GetScrNum(), accountComboBox.Text.Trim(), 4, "000520", 0, 0, """70773");
  120.         if (sell_result == 0)
  121.         {
  122.             string ttt = "매도취소 성공!";
  123.             setLog(ttt);
  124.             Console.WriteLine(ttt);
  125.         }
  126.         else
  127.         {
  128.             string ttt = "매도취소 실패!";
  129.             setLog(ttt);
  130.             Console.WriteLine(ttt);
  131.         }
  132.         */
  133.     }
  134. }

 

크게 분류를 하자면

1. 초기 변수및 딕셔너리 세팅

2. 키움에서 제공하는 라이브러리 로드

3. 저의 데이터베이스에서 매매에 관련된 개인정보 가져오기.

4. 키움의 조건리스트 호출

입니다.

 

매매에 관련된 개인세팅정보는 저의 데이터베이스에 기록되고 불려와집니다.

데이터베이스는 MySQL 이며, 당연히 저의 웹서버와 겸용인 데이터베이스를 사용합니다.(헤헤 디비살돈 아껴야지용~)

 

현재까지 진행된 프로그램의 UI 는 아래와 같습니다.

 


이 게시글은
https://webschool.kr/?v=board_view&board_key=34&idx=560
에서 작성한 글입니다. 소스코드의 경우 해당 블로그에서 이뿌게 노출이 되지 않을 수 있사오니, 위 링크로 들어오셔서 보시길 바랍니다.

반응형