akapur / pyiqfeed

Python LIbrary for reading DTN's IQFeed
GNU General Public License v2.0
172 stars 109 forks source link

Failures on apache #34

Closed obiben closed 5 years ago

obiben commented 5 years ago

I'm setting up apache instead of serving data from flask, and started getting errors when fetching data from iqfeed. Do you have any idea what might be causing this?

[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]   File "C:/_tools/iqfeed\\data.py", line 88, in get_eod_since
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]     ascend=False
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]   File "c:\\python36\\lib\\site-packages\\pyiqfeed-0.9-py3.6.egg\\pyiqfeed\\conn.py", line 2238, in request_daily_data_for_dates
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]     self._send_cmd(req_cmd)
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]   File "c:\\python36\\lib\\site-packages\\pyiqfeed-0.9-py3.6.egg\\pyiqfeed\\conn.py", line 188, in _send_cmd
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933]     self._sock.sendall(cmd.encode(encoding='latin-1', errors='strict'))
[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied

The same function is happily churning out data running on Flask on port 5000.

akapur commented 5 years ago

Sorry but pyiqfeed doesn’t talk to apache or flask. It only communicated with IQFeed.

On Oct 19, 2018, at 10:05 AM, obiben notifications@github.com wrote:

I'm setting up apache instead of serving data from flask, and started getting errors when fetching data from iqfeed. Do you have any idea what might be causing this?

[Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] File "C:/_tools/iqfeed\data.py", line 88, in get_eod_since [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] ascend=False [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] File "c:\python36\lib\site-packages\pyiqfeed-0.9-py3.6.egg\pyiqfeed\conn.py", line 2238, in request_daily_data_for_dates [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] self._send_cmd(req_cmd) [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] File "c:\python36\lib\site-packages\pyiqfeed-0.9-py3.6.egg\pyiqfeed\conn.py", line 188, in _send_cmd [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] self._sock.sendall(cmd.encode(encoding='latin-1', errors='strict')) [Fri Oct 19 10:00:36.805171 2018] [wsgi:error] [pid 4016:tid 1312] [client ::1:59933] OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied The same function is happily churning out data running on Flask on port 5000.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/akapur/pyiqfeed/issues/34, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyQVFZjZjsjjGF9aGu77IQNWmgaNOqDks5umdwngaJpZM4XwbSM.

obiben commented 5 years ago

I know but I thought apache might be limiting connectivity since the error happened in conn.py.

It turns out I'm either dumb or missing coffee:

My flask file ends like this:

if __name__ == '__main__':
    with iq.ConnConnector([data.hist_conn]) as connector:
        print("Web server IQ Feed connection established, preparing to serve...")
        #from waitress import serve
        #serve(app, listen='0.0.0.0:5000')
        app.run(host='0.0.0.0', port=5001, threaded=True)

Which is fine, but my wsgi script is:

import sys
import os
sys.path.append('C:/_tools/iqfeed/')
os.chdir('C:/_tools/iqfeed/')
from iq_web import app as application

application gets run by apache's mod_wsgi, but I'm missing the iq.ConnConnector bit.

Now I just have to figure out how to run this correctly without a with statement and I'll be golden.

obiben commented 5 years ago

And my answer probably lies in establishing a distinct connection every request, as long as it isn't too costly!

akapur commented 5 years ago

We are all caffeine challenged at various times. I’ve only every built stuff using IQFeed for trading, and I’ve certainly never done something that involved using apache with it. My suggestion is that if you are writing a web service sending data, write a micro-service that talks to IQFeed and listens on a TCP port, straight sockets, not HTTP or anything else on top of it, and sends out whatever you need as JSON or some other protocol and have your web app talk to that service using something like the requests library when it needs market data.

On Oct 19, 2018, at 11:57 AM, obiben notifications@github.com wrote:

I know but I thought apache might be limiting connectivity since the error happened in conn.py.

It turns out I'm either dumb or missing coffee:

My flask file ends like this:

if name == 'main': with iq.ConnConnector([data.hist_conn]) as connector: print("Web server IQ Feed connection established, preparing to serve...")

from waitress import serve

    #serve(app, listen='0.0.0.0:5000')
    app.run(host='0.0.0.0', port=5001, threaded=True)

Which is fine, but my wsgi script is:

import sys import os sys.path.append('C:/_tools/iqfeed/') os.chdir('C:/_tools/iqfeed/') from iq_web import app as application application gets run by apache's mod_wsgi, but I'm missing the iq.ConnConnector bit.

Now I just have to figure out how to run this correctly without a with statement and I'll be golden.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/akapur/pyiqfeed/issues/34#issuecomment-431411878, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyQVDMnS3p31AliisZfNlpriXKToKs7ks5umfaFgaJpZM4XwbSM.

obiben commented 5 years ago

Thanks for the suggestion, that's probably the neatest way to manage it.