void Main(bool useDemoServer) { SqliteExtension.UseSqlite("test.sqlite"); if (useDemoServer == false) { Console.WriteLine("이 코드는 데모 서버로만 매수 주문을 하는 예제입니다."); return; } LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } string tradeAccount = xing.GetFirstAccount(); if (string.IsNullOrEmpty(tradeAccount) == true) { Console.WriteLine("추정순자산(sunamt) 또는 예수금(sunamt1)을 가진 계정이 없습니다."); return; } string inptpwd = null; if (useDemoServer == true) { inptpwd = "0000"; } if (useDemoServer) { using (XQCSPAQ12200 query = new XQCSPAQ12200()) { XQCSPAQ12200InBlock1 input = new XQCSPAQ12200InBlock1(); input.AcntNo = tradeAccount; // input.BalCreTp = input.Dump(Console.Out); query.SetBlock(input); if (query.Request() < 0) { Console.WriteLine("Failed to send request: "); Console.WriteLine(query.QueryResult); return; } var block1 = query.GetBlock1(); block1.Dump(Console.Out); var block2 = query.GetBlock2(); block2.Dump(Console.Out, DumpOutputType.Inline); } } } }
void Main(bool useDemoServer, bool loadFromDB) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (useDemoServer) { // 반복 쿼리는 반드시 이런 식으로! (XingAPI COM 개체에 메모리 누수 버그 예상) // XQt 개체를 생성 후 쿼리만 재실행 using (var query = new XQt2101()) { query.SetFieldData(XQt2101InBlock.BlockName, XQt2101InBlock.F.focode, 0, "101R3000"); while (true) { if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt2101OutBlock item = query.GetBlock(); if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } Thread.Sleep(200); } } } else { using (var query = new XQt2101()) { query.SetFieldData(XQt2101InBlock.BlockName, XQt2101InBlock.F.focode, 0, "101R3000"); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt2101OutBlock item = query.GetBlock(); if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var items = XQt1533.ReadFromDB(); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var items = XQt1533.Get(XQt1533Gubun.상승율상위); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } items.WriteToDB(replace: true); } else { using (var query = new XQt1533()) { query.SetFieldData(XQt1533InBlock.BlockName, XQt1533InBlock.F.gubun, 0, "2"); // 2 == XQt1533Gubun.하락율상위 if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1533OutBlock[] outBlocks = query.GetBlocks(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var items = XQt8425.ReadFromDB(); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline); } } else if (useDemoServer) { var items = XQt8425.Get(); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline); } items.WriteToDB(replace: true); } else { using (var query = new XQt8425()) { if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt8425OutBlock[] outBlocks = query.GetBlocks(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { XQt0167OutBlock outBlock = XQt0167.ReadFromDB(); outBlock?.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } else if (useDemoServer) { XQt0167OutBlock outBlock = XQt0167.Get(); Console.WriteLine(XQt0167OutBlock.F.dt + " == " + outBlock.dt); Console.WriteLine(XQt0167OutBlock.F.time + " == " + outBlock.time); outBlock.WriteToDB(replace: true); } else { using (XQt0167 query = new XQt0167()) { query.SetFieldData(XQt0167InBlock.BlockName, XQt0167InBlock.F.id, 0, ""); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt0167OutBlock outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } } } } }
void Main(bool useDemoServer) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } XQt8430.Get(XQt8430Gubun.전체).WriteToDB(); XQt8425.Get().WriteToDB(); } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (useDemoServer) { var items = XQt1532.Get(Stock.SHCODE.KOSPI.현대건설); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline); } } else { using (var query = new XQt1532()) { query.SetFieldData(XQt1532InBlock.BlockName, XQt1532InBlock.F.shcode, 0, Stock.SHCODE.KOSPI.현대건설); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1532OutBlock[] outBlocks = query.GetBlocks(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } } } } } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (useDemoServer) { var items = XQt8430.Get(XQt8430Gubun.코스닥); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else { using (var query = new XQt8430()) { query.SetFieldData(XQt8430InBlock.BlockName, XQt8430InBlock.F.gubun, 0, "1"); // 코스피 == '1' if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt8430OutBlock[] outBlocks = query.GetBlocks(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } } } } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (useDemoServer) { var outBlock = XQt1511.Get(XQt1511.Upcode.코스피200); outBlock?.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } else { using (XQt1511 query = new XQt1511()) { query.SetFieldData(XQt1511InBlock.BlockName, XQt1511InBlock.F.upcode, 0, XQt1511.Upcode.코스피); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1511OutBlock outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } } } } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); StringBuilder sb = new StringBuilder(); sb.AppendLine("namespace XingAPINet"); sb.AppendLine("{"); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } string tab = "\t"; sb.AppendLine($"{tab}public partial class Stock"); sb.AppendLine($"{tab}{{"); { string tmcodes = GetTmCode(tab + "\t"); sb.AppendLine(tmcodes); } { string shcodes = GetSHCode(tab + "\t"); sb.AppendLine(shcodes); } sb.AppendLine($"{tab}}}"); } sb.AppendLine("}"); File.WriteAllText("Stock.cs", sb.ToString(), Encoding.UTF8); }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } int totalSize = 30; if (loadFromDB == true) { var multiBlock = XQt1702.ReadFromDB(); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1702.Get(Stock.SHCODE.KOSPI.현대건설, volvalgb: XQt1702.VolvalgbCode.금액, msmdgb: XQt1702.MsmdgbCode.순매수); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt1702 query = new XQt1702()) { var inBlock = new XQt1702InBlock { shcode = Stock.SHCODE.KOSPI.현대건설, volvalgb = XQt1702.VolvalgbCode.금액, msmdgb = XQt1702.MsmdgbCode.순매수 }; while (totalSize > 0) { query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); break; } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); break; } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); totalSize--; } inBlock.CopyValueFromBlock(outBlock); } } } } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } int pageSize = 10; int totalSize = 30; if (useDemoServer) { var items = XQt1514.Get("301", gubun2: XQt1514.Gubun2.일, cnt: totalSize); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else { using (XQt1514 query = new XQt1514()) { var inBlock = new XQt1514InBlock { upcode = "301", cnt = pageSize, gubun2 = XQt1514.Gubun2.월, }; query.SetBlock(inBlock); bool nextPage = false; while (totalSize > 0) { if (query.Request(nextPage) < 0) { Console.WriteLine("Failed to send request"); } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); totalSize--; } inBlock.CopyValueFromBlock(outBlock); query.SetBlock(inBlock); nextPage = true; } } } } }
void Main(bool useDemoServer) { LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } int pageSize = 10; int totalSize = 30; if (useDemoServer) { var items = XQt1475.Get(Stock.SHCODE.KOSDAQ.이베스트투자증권, datacnt: totalSize); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else { using (XQt1475 query = new XQt1475()) { XQt1475InBlock inBlock = new XQt1475InBlock { shcode = Stock.SHCODE.KOSDAQ.이베스트투자증권, datacnt = pageSize, }; query.SetBlock(inBlock); bool nextPage = false; while (totalSize > 0) { if (query.Request(nextPage) < 0) { Console.WriteLine("Failed to send request"); } XQt1475OutBlock outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); totalSize--; } inBlock.CopyValueFromBlock(outBlock); query.SetBlock(inBlock); nextPage = true; } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var multiBlock = XQt1537.ReadFromDB(); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline); } } else if (useDemoServer) { var multiBlock = XQt1537.Get(Stock.TMCODE.테마파크); if (multiBlock.OutBlock?.IsValidData != true) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (var query = new XQt1537()) { query.SetFieldData(XQt1537InBlock.BlockName, XQt1537InBlock.F.tmcode, 0, Stock.TMCODE.테마파크); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1537OutBlock1[] outBlocks = query.GetBlock1s(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var multiBlock = XQt1305.ReadFromDB(); if (multiBlock.OutBlock?.IsValidData != true) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1305.Get(Stock.SHCODE.KOSPI.SK하이닉스, dwmcode: XQt1305.DWMCode.일, cnt: 10); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (var query = new XQt1305()) { XQt1305InBlock inBlock = new XQt1305InBlock() { shcode = Stock.SHCODE.KOSPI.SK하이닉스, dwmcode = XQt1305.DWMCode.일, cnt = 10, }; if (query.SetBlock(inBlock) == false) { Console.WriteLine($"Failed to set block"); return; } if (query.Request() < 0) { Console.WriteLine("Failed to send request"); return; } XQt1305OutBlock1[] outBlocks = query.GetBlock1s(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } } } } }
private void Form1_Load(object sender, EventArgs e) { /* * Type sessionType = Type.GetTypeFromProgID("XA_Session.XASession"); * object objSession = Activator.CreateInstance(sessionType); * IXASession xingSession = objSession as IXASession; */ bool useDemoServer = false; LoginInfo user = GetUserInfo(useDemoServer); _xingClient = new XingClient(useDemoServer); _xingClient.ConnectWithLogin(user); Console.WriteLine($"# of account: {_xingClient.NumberOfAccount}"); foreach (string account in _xingClient.GetAccounts()) { Console.WriteLine("\t" + account); } if (useDemoServer) { var outBlock = XQt1101.Get(shcode: Stock.SHCODE.KOSDAQ.이베스트투자증권); if (outBlock != null) { OutputPrice(outBlock.shcode, outBlock.price); } } else { using (XQt1101 query = new XQt1101()) { XQt1101InBlock inBlock = new XQt1101InBlock { shcode = Stock.SHCODE.KOSDAQ.이베스트투자증권 }; if (query.SetBlock(inBlock) == false) { Console.WriteLine("Failed to verify data: " + XQt1101InBlock.BlockName); return; } Console.WriteLine("GetFields: " + XQt1101InBlock.BlockName); int queryResult = query.Request(); if (queryResult < 0) { Console.WriteLine("Failed to send request"); } XQt1101OutBlock outBlock = query.GetBlock(); OutputPrice(outBlock.shcode, outBlock.price); } } { _realS3 = new XRS3_(); _realS3.DataArrived += _realS3_DataArrived; XRS3_InBlock inBlock = new XRS3_InBlock { shcode = Stock.SHCODE.KOSDAQ.이베스트투자증권 }; if (_realS3.SetBlock(inBlock) == false) { Console.WriteLine("Failed to verify data: " + XRS3_InBlock.BlockName); return; } _realS3.Advise(); } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } int pageSize = 10; int totalSize = 30; if (loadFromDB == true) { var multiBlock = XQt1475.ReadFromDB(); if (multiBlock.OutBlock?.IsValidData != true) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1475.Get(Stock.SHCODE.KOSDAQ.이베스트투자증권, datacnt: totalSize); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt1475 query = new XQt1475()) { XQt1475InBlock inBlock = new XQt1475InBlock { shcode = Stock.SHCODE.KOSDAQ.이베스트투자증권, datacnt = pageSize, }; while (totalSize > 0) { query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); break; } XQt1475OutBlock outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); break; } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); totalSize--; } inBlock.CopyValueFromBlock(outBlock); } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { foreach (string account in xing.GetAccounts()) { Console.WriteLine($"[Account = {account}]"); var multiBlock = XQt0424.ReadFromDB(); multiBlock.OutBlock?.Dump(Console.Out, DumpOutputType.FormattedKeyValue); Console.WriteLine($"# of items: {multiBlock.OutBlock1?.Length}"); foreach (var item in multiBlock.OutBlock1 ?? Enumerable.Empty <XQt0424OutBlock1>()) { item.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } } } else if (useDemoServer) { foreach (string account in xing.GetAccounts()) { Console.WriteLine($"[Account = {account}]"); var multiBlock = XQt0424.Get(account); multiBlock.OutBlock?.Dump(Console.Out, DumpOutputType.FormattedKeyValue); multiBlock.OutBlock?.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } multiBlock.OutBlock1.WriteToDB(replace: true); } } else { using (var query = new XQt0424()) { foreach (string account in xing.GetAccounts()) { Console.WriteLine($"[Account = {account}]"); XQt0424InBlock inBlock = new XQt0424InBlock() { accno = account, }; if (query.SetBlock(inBlock) == false) { Console.WriteLine($"Failed to set block"); return; } if (query.Request(false) < 0) { Console.WriteLine("Failed to send request"); return; } XQt0424OutBlock outBlock = query.GetBlock(); { outBlock?.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } XQt0424OutBlock1[] outBlocks = query.GetBlock1s(); foreach (var item in outBlocks) { item.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var multiBlock = XQt1301.ReadFromDB(); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1301.Get(Stock.SHCODE.KOSPI.현대건설, starttime: "0900", endtime: "1530"); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt1301 query = new XQt1301()) { var inBlock = new XQt1301InBlock { shcode = Stock.SHCODE.KOSPI.현대건설, starttime = "0900", endtime = "1530", }; while (true) { query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); break; } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); break; } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } inBlock.CopyValueFromBlock(outBlock); if (string.IsNullOrEmpty(outBlock.cts_time) == true) { break; } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var items = XQt1717.ReadFromDB(); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline); } } else if (useDemoServer) { var items = XQt1717.Get(Stock.SHCODE.KOSPI.현대건설, gubun: XQt1717.Gubun.일별, fromdt: "20170101", todt: "20172131"); foreach (var item in items) { item.Dump(Console.Out, DumpOutputType.Inline); } items.WriteToDB(replace: true); } else { using (var query = new XQt1717()) { query.SetFieldData(XQt1717InBlock.BlockName, XQt1717InBlock.F.shcode, 0, Stock.SHCODE.KOSPI.현대건설); query.SetFieldData(XQt1717InBlock.BlockName, XQt1717InBlock.F.gubun, 0, XQt1717.Gubun.일별.ToString()); query.SetFieldData(XQt1717InBlock.BlockName, XQt1717InBlock.F.fromdt, 0, "20170101"); query.SetFieldData(XQt1717InBlock.BlockName, XQt1717InBlock.F.todt, 0, "20172131"); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1717OutBlock[] outBlocks = query.GetBlocks(); foreach (var item in outBlocks) { if (item.IsValidData == true) { item.Dump(Console.Out, DumpOutputType.Inline); } } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } int pageSize = 10; int totalSize = 30; if (loadFromDB == true) { var multiBlock = XQt1514.ReadFromDB(); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1514.Get("301", gubun2: XQt1514.Gubun2.일, cnt: totalSize); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt1514 query = new XQt1514()) { var inBlock = new XQt1514InBlock { upcode = "301", cnt = pageSize, gubun2 = XQt1514.Gubun2.월, }; while (totalSize > 0) { query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); break; } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); break; } foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); totalSize--; } inBlock.CopyValueFromBlock(outBlock); } } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var multiBlock = XQt1310.ReadFromDB(Stock.SHCODE.KOSPI.현대건설); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt1310.Get(shcode: Stock.SHCODE.KOSPI.현대건설, daygb: XQt1310.DayGB.당일, timegb: XQt1310.TimeGB.틱); if (multiBlock.OutBlock.IsValidData == false) { return; } multiBlock.OutBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"# of items: {multiBlock.OutBlock1.Length}"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt1310 query = new XQt1310()) { var inBlock = new XQt1310InBlock { shcode = Stock.SHCODE.KOSPI.현대건설, daygb = XQt1310.DayGB.당일, timegb = XQt1310.TimeGB.틱, }; bool createFirst = true; while (true) { query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); break; } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.Inline); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); break; } var blocks = query.GetBlock1s(); foreach (var item in blocks) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } blocks.WriteToDB(createFirst, inBlock.shcode); createFirst = false; inBlock.CopyValueFromBlock(outBlock); if (string.IsNullOrEmpty(outBlock.cts_time) == true) { break; } } } } } }
void Main() { bool useDemoServer = true; LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } Console.WriteLine($"# of account: {xing.NumberOfAccount}"); foreach (string account in xing.GetAccounts()) { Console.WriteLine("\t" + account); } // 현재가 조회한 후, using (XQt1101 query = new XQt1101()) { XQt1101InBlock inBlock = new XQt1101InBlock { shcode = Stock.SHCODE.KOSDAQ.이베스트투자증권 }; if (query.SetBlock(inBlock) == false) { Console.WriteLine("Failed to verify data: " + XQt1101InBlock.BlockName); return; } if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } XQt1101OutBlock outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { outBlock.Dump(Console.Out, DumpOutputType.FormattedKeyValue); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } } // 실시간 데이터를 조회 using (XRS2_ real = new XRS2_()) { //XRS3_InBlock inBlock = new XRS3_InBlock { shcode = shcode }; //if (real.SetFields(inBlock) == false) //{ // Console.WriteLine("Failed to verify data: " + inBlock.BlockName); // return; //} real.SetFieldData(XRS2_InBlock.BlockName, XRS2_InBlock.F.shcode, Stock.SHCODE.KOSDAQ.이베스트투자증권); real.Advise(); while (_exitProcess == false) { if (real.WaitForData(1000) == false) { Console.Write("."); continue; } XRS2_OutBlock outBlock = real.GetBlock(); if (outBlock.IsValidData == true) { // outBlock.Dump(Console.Out, DumpOutputType.KeyValue); Console.WriteLine(outBlock.bidho); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } } } } }
void Main(bool useDemoServer) { SqliteExtension.UseSqlite("test.sqlite"); if (useDemoServer == false) { Console.WriteLine("이 코드는 데모 서버로만 매수 주문을 하는 예제입니다."); return; } LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } string tradeAccount = xing.GetFirstAccount(); if (string.IsNullOrEmpty(tradeAccount) == true) { Console.WriteLine("추정순자산(sunamt) 또는 예수금(sunamt1)을 가진 계정이 없습니다."); return; } string inptpwd = null; if (useDemoServer == true) { inptpwd = "0000"; } string shcode = Stock.SHCODE.KOSPI.현대건설; string isuNo = xing.GetExpCode(shcode); long currentPrice = xing.GetCurrentPrice(shcode); if (useDemoServer) { using (XQCSPAT00600 query = new XQCSPAT00600()) { XQCSPAT00600InBlock1 input = new XQCSPAT00600InBlock1(); input.AcntNo = tradeAccount; input.InptPwd = inptpwd; input.IsuNo = isuNo; input.OrdQty = 1; // input.OrdPrc = currentPrice - (currentPrice * 0.10); // 10% 낮은 가격으로 매수 주문 input.OrdPrc = currentPrice; // 현재가로 매수 주문 input.BnsTpCode = XQCSPAT00600.BnsTpCode.매수; // input.OrdprcPtnCode = XQCSPAT00600.OrdprcPtnCode.시장가; // 테스트를 위해 OrdPrc에 상관 없이 시장가로. input.OrdprcPtnCode = XQCSPAT00600.OrdprcPtnCode.지정가; input.MgntrnCode = XQCSPAT00600.MgntrnCode.보통; input.LoanDt = null; input.OrdCndiTpCode = XQCSPAT00600.OrdCndiTpCode.없음; Console.WriteLine("[매수 주문]"); input.Dump(Console.Out); query.SetBlock(input); if (query.Request() < 0) { Console.WriteLine("Failed to send request: "); Console.WriteLine(query.QueryResult); return; } var block1 = query.GetBlock1(); block1.Dump(Console.Out); var block2 = query.GetBlock2(); block2.Dump(Console.Out, DumpOutputType.Inline); Console.WriteLine($"===========> 매수 주문 번호: {block2.OrdNo}"); } } } }
void Main(bool useDemoServer, bool loadFromDB) { SqliteExtension.UseSqlite("test.sqlite"); LoginInfo user = GetUserInfo(useDemoServer); using (XingClient xing = new XingClient(useDemoServer)) { if (xing.ConnectWithLogin(user) == false) { Console.WriteLine(xing.ErrorMessage); return; } if (loadFromDB == true) { var multiBlock = XQt8419.ReadFromDB(); if (multiBlock.OutBlock.IsValidData == false) { return; } Console.WriteLine($"[{XQt8419OutBlock1.BlockName}]"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } else if (useDemoServer) { var multiBlock = XQt8419.Get("001", '2', 0, "20190101", "201905030", null, 'N'); if (multiBlock.OutBlock?.IsValidData != true) { return; } multiBlock.OutBlock.WriteToDB(replace: true); Console.WriteLine($"[{XQt8419OutBlock1.BlockName}]"); foreach (var item in multiBlock.OutBlock1) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } multiBlock.OutBlock1.WriteToDB(replace: true); } else { using (XQt8419 query = new XQt8419()) { var inBlock = new XQt8419InBlock { shcode = "001", gubun = '2', sdate = "20170101", edate = "20180424", /* qrycnt = pageSize, // not work */ comp_yn = 'N', }; query.SetBlock(inBlock); if (query.Request() < 0) { Console.WriteLine("Failed to send request"); } var outBlock = query.GetBlock(); if (outBlock.IsValidData == true) { Console.WriteLine($"[{outBlock.GetBlockName()}]"); outBlock.Dump(Console.Out, DumpOutputType.Inline80Cols); } else { Console.WriteLine($"Invalid: {outBlock.InvalidReason}"); } Console.WriteLine($"[{XQt8419OutBlock1.BlockName}]"); foreach (var item in query.GetBlock1s()) { item.Dump(Console.Out, DumpOutputType.Inline80Cols); } } } } }