C++11 , How to get the entire NYSE listing daily?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rollerbladegirl
    New Member
    • Jan 2020
    • 69

    C++11 , How to get the entire NYSE listing daily?

    In C++11.

    On a Windows computer.

    How do I add to my program a way for it to download from the internet the entire NYSE listing daily?

    I am still learning C++11.

    If you give an example that is stable, and it is really simple, then I can go from there.

    Code that is baby level simple please.

    Thanks.
    Last edited by rollerbladegirl; Jan 24 '20, 06:36 PM. Reason: Removed some limits that were not necessary.
  • SioSio
    Contributor
    • Dec 2019
    • 272

    #2
    This program to get the source by specifying the URL and save it in a binary file.(Only Windows)
    Code:
    #include "pch.h"
    #include <iostream>
    
    #include <windows.h>
    #include <stdio.h>
    #include <wininet.h>
    #include <tchar.h>
    #include <locale.h>
    
    #pragma comment(lib,"wininet.lib")
    
    //      Get data from the specified URL and save it in a file in binary
    int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp);
    
    int _tmain(int argc, TCHAR** argv) {
    	HINTERNET hInet;
    	FILE* fp;
    
    	//      Sets the locale to display UNICODE characters correctly on stderr
    	_tsetlocale(LC_ALL, _TEXT(""));
    
    	if (argc != 3) {
    		_ftprintf(stderr, _TEXT("Usage : This_Prog_Name.exe [url] [save file name]\n"));
    		return 1;
    	}
    	//Start Internet connect(WinInet)
    	hInet = InternetOpen(TEXT("wxz123"),
    		INTERNET_OPEN_TYPE_PRECONFIG,
    		NULL, NULL, 0);
    	if (hInet == NULL) {
    		_ftprintf(stderr, _TEXT("Failure the handl eacquisition\n"));
    		return 2;
    	}
    	if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
    		InternetCloseHandle(hInet);
    		_ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
    		return 3;
    	}
    	if (webBinGet(hInet, argv[1], fp) < 0)
    		_ftprintf(stderr, _TEXT("Could not load source from internet successfully\n"));
    	InternetCloseHandle(hInet);
    	fclose(fp);
    	return 0;
    }
    
    //      Get HTML source from the URL and save binary file.
    
    int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp) {
    	char buf[1024];
    	HINTERNET hUrl;
    	//HTTP session Start,and URL open.
    	hUrl = InternetOpenUrl(hInet, url, NULL, 0, 0, 0);
    	if (hUrl == NULL) {
    		_ftprintf(stderr, _TEXT("URL Open Error %s\n"), url);
    		return -1;
    	}
    	//Read to the end
    	int len;
    	int size = 0;
    	for (;;) {
    		InternetReadFile(hUrl, buf, sizeof(buf), (LPDWORD)&len);
    		if (len <= 0)
    			break;
    		fwrite(buf, sizeof(buf[0]), len, fp);
    		size += len;
    	}
    	InternetCloseHandle(hUrl);
    	return len;     //      Return File size.
    }
    After that, create a part to find your required tag and get the value in bin file.

    If you run at a fixed time every day,
    Use time scheduling(Wiin dows).

    Comment

    • rollerbladegirl
      New Member
      • Jan 2020
      • 69

      #3
      SioSio YES !

      Thank you.

      And it uses Unicode ! Yes again! Again Thank You. I wanted this program to be usable by any Unicode user. I have been starting with #define _UNICODE and #define UNICODE.

      Direct, to the point, a bit of a stretch to keep up with it, but it looks like code that I can study and learn from.

      OH, I LIKE THIS SITE !

      I see that you use #include "pch.h". I have read about this and it seems to be used in some examples with Visual Studio. Does that mean that I have to use VS to use this code.

      I am using CODE::BLOCKS 17.12 and GNU GCC Compiler.

      My main is int WINAPI WinMain(...). I am compiling to a Windows GUI. I hope that if I study your code example that I can use it. It looks nice.

      And, with #include "pch.h", does that mean that, in my final compiled program, that my headers will be compiled separately? I wanted the entire program to be one single executable with no dlls, etc. I have been using #define IDC_STATIC (-1). Or, does #include "pch.h" just make the compilation faster. Can I use this code without #include "pch.h"?

      Really, Thanks SioSio.

      Comment

      • rollerbladegirl
        New Member
        • Jan 2020
        • 69

        #4
        I am looking up your code (parts) and studying it and it seems to be written for Visual Studio. I am not getting the following to work:

        Code:
            if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
                InternetCloseHandle(hInet);
                _ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
                return 3;
        I looked up _tfopen_s and it does not seem to work outside of Visual Studio. I am trying to find how to do the VS parts in C or C++ by itself without VS.

        Thanks.

        Comment

        • SioSio
          Contributor
          • Dec 2019
          • 272

          #5
          Yes, this source was written in VS.

          #include "pch.h" is not required if the environment is not VS.

          In Visual Studio, fopen cannot be used as it is (it is necessary to write #pragma warning (disable: 4996) at the beginning of the source), so use _fopen_s.
          Code:
          _tfopen_s(&fp、argv [2]、TEXT( "wb"))
          
          fp = fopen(argv[2], "wb");

          Comment

          • rollerbladegirl
            New Member
            • Jan 2020
            • 69

            #6
            Thank you SioSio.

            Last summer 2019 I decided to learn C++11.

            I have no interest in using Visual Studio (at this time).

            As a new C++ programmer, it has taken me sometimes hours to convert VS stuff to C++ code. Now I have been trying to stay away from VS studio stuff.

            Your offer to help me with VS code was nice. I appreciate the offer. Thank you. But, I am looking for C++11 code.

            At your level of expertise, maybe you can supply that code in C++? I can use any version of C++ up to 11 and I can use straight C. Would you please help me with doing this in C++ (up to C++11)?

            Thank you SioSio.

            Comment

            Working...