lsv
lsv

Reputation: 1757

mql4: Get data from site

How I can get "Maintenance" value from site

enter image description here

using a MQL4 script ?

As I understand, I must set an internet connection, get data from site, parse it and get data.

Is there a way how I can do it?

I'll be grateful for any example.

Upvotes: 2

Views: 2477

Answers (1)

user3666197
user3666197

Reputation: 1

Fact #1: MQL4 syntax restricts calling external sub-process:

This means ( if not using a DLL-workaround ) the whole task would require to re-invent a wheel and build the HTML-parser inside MQL4. Doable but a waste of anyone's resources.

Fact #2: There are better ways to choose from:

Once going to use a DLL-imported functionalities, one may either just bypass the MQL4 code-execution restrictions and call Windows-API services to fork sub-process and make things move forwards, however Windows-API, in my opinion, is rather a feature rich interfacing framework, but for a pretty low-level access to elementary services, so you finally can find yourself re-inventing wheel again, well, now "outside" from the MQL4 sandbox restrictions.

If you do not restrict our imagination, your project may benefit from rapid-prototyping in Python and setup a peer-to-peer distributed messaging/control in a heterogeneous Python / MQL4 environment.

Besides other benefits, Python strengths in smart and powerful ( not only ) web-content processing is fabulous, so this distributed approach will open your MQL4 projects into strategically new, unseen dimensions.


Python smart-scraping ( not a dumb-force one ):

def askAtPublisherWebURL( aControlDICT,
                          aURL             = "https://globalde?.?.?.?y?.com/en/products/.../...-DLON?Class_type=class_symbol=???&Class_exchange=???&ps=999&md=03-2014",
                          anOPT            = "ESX",
                          aMaturityDATE    = "03-2014",
                          anEmailRECIPIENT = "[email protected]",
                          aFileNAME        = "ESX_2014-03_anObservedStateTIMESTAMP[]"
                          ):
    import      time, urllib, re, winsound, urllib2             # late, dirty import

    try:
        aReturnFLAG     = True
        anOutputSTRING  = "|TRYING: " + aURL                    # a crash-proof proxy-value for a case IOError <EXC> would appear
      # --------------------------------------------------------# urllib2 MODE        
        anInputHANDLER  = urllib2.urlopen( aURL, None, 120 )    # urllib2 MODE with a 120 [sec] timeout before urllib2.URLError ... still gets stuck during peak-hours ( on aMaturityDATE )
        aListOfLINEs    = anInputHANDLER.readlines()
        anInputHANDLER.close()
      # --------------------------------------------------------# urllib2 MODE
    except urllib2.URLError as anExcREASON:
        aReturnFLAG     = False
                                                                # no RET here // JMP .FINALLY: to log IOError....

    except exceptions.IOError as ( ErrNO, ErrSTR ):             # an IOError <EXC> hase appeared, handle with care before JMP .FINALLY:
        aReturnFLAG     = False

    else:                                                       # no IOError or any other <EXC>, process the <content> .. JMP .FINALLY:
        # ------------------------------------------------------# HTML-processor
        # smart html-processing goes here
        # ...
        # ------------------------------------------------------# HTML-processor
    finally:                                                    # in any case do all this TIDY-UP-BEFORE-EXIT
        # fileIO + pre-exit ops
        # sendMsg4MQL() --> SIG MT4

    return aReturnFLAG # MISRA-motivated single point of RET

For hawkish Pythoneers, the post intentionally uses non-PEP-8 source code formatting as it is authors experience that during a learning phase, code read-ability improves the focus on task solution and helps getting used to the underlying concepts rather than to spend efforts on formally adhering typography. Hope the principle of providing help is respected and the non-PEP-8 styling format is forgiven in the name of the ease of reading.

Upvotes: 3

Related Questions