Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »NEW IQFEED FORUMS »IQFeed API Questions »Connection refused
Author Topic: Connection refused (5 messages, Page 1 of 1)

jaesle
-Interested User-
Posts: 6
Joined: Jul 26, 2023


Posted: Jul 26, 2023 11:41 AM          Msg. 1 of 5
If I have iQConnect running, then my app works.

However when I try and start iQConnect in my app, I can't connect and it says:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

The log appears below. What am I missing?

Python code
===

import subprocess
import socket

pr = open("product.txt", "r")
product = pr.read()
l = open("login.txt", "r")
login = l.read()
p = open("password.txt", "r")
password = p.read()

subprocess.run(["IQConnect.exe","-product",product,"-version","0.5","-login",login,"-password",password,"-autoconnect"])

host = '127.0.0.1'
port = 9300

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

===



=== IQConnect Log File Opened On Wed Jul 26 12:37:18 ===
Current Log Levels,Connectivity,Information,Admin
Current IQFeed Version,6.2.0.25
STATUS Connectivity 21188 0 2023-07-26 12:37:18 Creating trader account verification thread. Status idle
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Initializing the login thread
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Getting login from registry:
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Getting Password from registry: (0 characters)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Either login or password not saved. Clearing autoconnect and saveinfo flags
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Retrieving IP addresses.
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Connecting to server (login.interquote.com) on port 60020.
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Connect Process: Status 1.
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Processing Command Line
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Connect Process: Status 2.
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Received product ID from 3rd party application: (16 characters)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Received product version from 3rd party application: (0.5)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Received login from 3rd party application: (5xxxx0)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Recieved password from 3rd party application: (20 characters)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Received autoconnect from 3rd party application
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Adding Product. Request Auth 0
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Adding Product to authentication list (1:0)
STATUS Connectivity 14916 0 2023-07-26 12:37:18 Ignoring autoconnect from 3rd party application because we don't have credentials yet.
STATUS Information 14916 0 2023-07-26 12:37:18 Initialization complete.
STATUS Connectivity 20540 0 2023-07-26 12:37:18 Connect Process: Status 3.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connected to server 14.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 0 (12.36.218.210:60000)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 1 (0.0.0.0:4000)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 2 (0.0.0.0:4000)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 3 (12.36.218.210:60009)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 4 (0.0.0.0:4000)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 5 (12.36.218.211:60005)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 6 (12.36.218.212:60012)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 7 (12.36.218.148:60003)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 8 (0.0.0.0:60015)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 9 (12.36.218.210:60050)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 10 (12.36.218.210:60014)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 11 (12.36.218.202:60045)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 12 (12.36.218.211:60013)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 13 (12.36.218.211:60018)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Initiating disconnection from server 14.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connection to server 14 closed.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connection to server (14) closed gracefully.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 1 products left to authenticate. Ready
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Resetting socket in authentication thread.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Waiting for user or server list. 1 : 0
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Initiating a login of type (0).
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Clearing previous authenticationResult.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connecting To Login Server - 12.36.218.210:60000
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connecting to server (12.36.218.210) on port 60000.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connect Process: Status 1.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connect Process: Status 2.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connect Process: Status 3.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connected to server 0.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Clearing previous authenticationResult.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 No products pending authentication. Checking for unauthenticated products.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Authentication Successful
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Setting symbol limit to 500
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Processed Server 15 (12.36.218.206:60002)
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Authentication Successful
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connection to server 0 closed.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Connection to server (0) closed gracefully.
STATUS Connectivity 20540 0 2023-07-26 12:37:19 0 products left to authenticate. Ready
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Authentication Complete - Debug value = 1
STATUS Connectivity 20540 0 2023-07-26 12:37:19 Resetting socket in authentication thread.
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Connecting to quote server (12.36.218.206, 60002).
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Login Initiated without IQ32.dll
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Cleared QuoteServer Send Buffer
STATUS Connectivity 14916 0 2023-07-26 12:37:19 Successful connection to quote server made.
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 16 (12.36.218.206:60013)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 15 (12.36.218.206:60004)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 0 (12.36.218.212:60000)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 3 (12.36.218.212:60009)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 5 (12.36.218.212:60005)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 7 (12.36.218.150:60003)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 9 (12.36.218.210:60050)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 11 (12.36.218.202:60045)
STATUS Connectivity 21100 0 2023-07-26 12:37:19 Processed Server 13 (12.36.218.210:60018)
STATUS Information 14916 0 2023-07-26 12:37:20 NO CLIENTS CONNECTED SINCE STARTUP. SHUTTING DOWN IN 30 SEC.
STATUS Information 14916 0 2023-07-26 12:37:21 SHUTTING DOWN IN 29 SEC.
STATUS Information 14916 0 2023-07-26 12:37:22 SHUTTING DOWN IN 28 SEC.
STATUS Information 14916 0 2023-07-26 12:37:23 SHUTTING DOWN IN 27 SEC.
STATUS Information 14916 0 2023-07-26 12:37:24 SHUTTING DOWN IN 26 SEC.
STATUS Information 14916 0 2023-07-26 12:37:25 SHUTTING DOWN IN 25 SEC.
STATUS Information 14916 0 2023-07-26 12:37:26 SHUTTING DOWN IN 24 SEC.
STATUS Information 14916 0 2023-07-26 12:37:27 SHUTTING DOWN IN 23 SEC.
STATUS Information 14916 0 2023-07-26 12:37:28 SHUTTING DOWN IN 22 SEC.
STATUS Information 14916 0 2023-07-26 12:37:29 SHUTTING DOWN IN 21 SEC.
STATUS Information 14916 0 2023-07-26 12:37:30 SHUTTING DOWN IN 20 SEC.
STATUS Information 14916 0 2023-07-26 12:37:31 SHUTTING DOWN IN 19 SEC.
STATUS Information 14916 0 2023-07-26 12:37:32 SHUTTING DOWN IN 18 SEC.
STATUS Information 14916 0 2023-07-26 12:37:33 SHUTTING DOWN IN 17 SEC.
STATUS Information 14916 0 2023-07-26 12:37:34 SHUTTING DOWN IN 16 SEC.
STATUS Information 14916 0 2023-07-26 12:37:35 SHUTTING DOWN IN 15 SEC.
STATUS Information 14916 0 2023-07-26 12:37:36 SHUTTING DOWN IN 14 SEC.
STATUS Information 14916 0 2023-07-26 12:37:37 SHUTTING DOWN IN 13 SEC.
STATUS Information 14916 0 2023-07-26 12:37:38 SHUTTING DOWN IN 12 SEC.
STATUS Information 14916 0 2023-07-26 12:37:39 SHUTTING DOWN IN 11 SEC.
STATUS Information 14916 0 2023-07-26 12:37:40 SHUTTING DOWN IN 10 SEC.
STATUS Information 14916 0 2023-07-26 12:37:41 SHUTTING DOWN IN 9 SEC.
STATUS Information 14916 0 2023-07-26 12:37:42 SHUTTING DOWN IN 8 SEC.
STATUS Information 14916 0 2023-07-26 12:37:43 SHUTTING DOWN IN 7 SEC.
STATUS Information 14916 0 2023-07-26 12:37:44 SHUTTING DOWN IN 6 SEC.
STATUS Information 14916 0 2023-07-26 12:37:45 SHUTTING DOWN IN 5 SEC.
STATUS Information 14916 0 2023-07-26 12:37:46 SHUTTING DOWN IN 4 SEC.
STATUS Information 14916 0 2023-07-26 12:37:47 SHUTTING DOWN IN 3 SEC.
STATUS Information 14916 0 2023-07-26 12:37:48 SHUTTING DOWN IN 2 SEC.
STATUS Information 14916 0 2023-07-26 12:37:49 SHUTTING DOWN IN 1 SEC.
STATUS Information 14916 0 2023-07-26 12:37:50 SHUTTING DOWN.
STATUS Information 14916 0 2023-07-26 12:37:50 Ping Results: Round Trip Time: 33ms
STATUS Connectivity 21100 0 2023-07-26 12:37:50 Authorizations Thread shutting down (156384765) - Context was terminated
STATUS Information 14916 0 2023-07-26 12:37:50 IQConnect Exit

jaesle
-Interested User-
Posts: 6
Joined: Jul 26, 2023


Posted: Jul 27, 2023 03:37 PM          Msg. 2 of 5
I figured it out. I created and ran a separate app that opens iQConnect and logs in, then I run my app and everything works fine.

DTN_Gary_Stephen
-DTN Guru-
Posts: 402
Joined: Jul 3, 2019


Posted: Jul 28, 2023 09:42 AM          Msg. 3 of 5
Error 10061 is a socket error meaning "connection refused". IQFeed doesn't refuse connections, except for reasons it will explain in the log, like bad credentials. And this is one of those times.

The 30-second log you see in the countdown is the IQFeed server waiting for you to make a socket connection. If you have a connection to the server, you have 30 seconds to make a socket connection, or the server disconnects you. Opening an IQFeed app first, as you're doing now, creates at least one socket connection, which prevents this countdown from happening. But it's not the only possible resolution.

Sincerely,
Gary Stephen
DTN IQFeed Implementation Support Specialist

jaesle
-Interested User-
Posts: 6
Joined: Jul 26, 2023


Posted: Jul 29, 2023 07:34 AM          Msg. 4 of 5
What I don't understand is that if I run the iQConnect app from my (slightly improved) code and then start a separate app with the socket connection, then it works.

But when I try and use this line

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

in the connect.py application (see below) then the connection is refused. Why does the line work in a separate application but not in the connect.py app?

Can you give me a hint as to another possible resolution?

Thanks!



=== connect.py file ===

import time
import win32api

def readline(textfile):
filename = textfile + '.txt'
temp = open (filename,'r')
content = temp.read()
return content

product = readline('product')
login = readline('login')
password = readline('password')

iqfeed_args = ("-product %s -version 0.5 -login %s -password %s -autoconnect" %
(product, login, password))

win32api.ShellExecute(0,'open', 'IQConnect.exe', iqfeed_args,'',1)

# give myself 10 seconds to start the other app
time.sleep(10)

mkvalor
-Interested User-
Posts: 26
Joined: Oct 6, 2020

Keep your tools sharp.


Posted: Feb 10, 2024 07:29 PM          Msg. 5 of 5
I found a way to cover most of the edge cases. Recall that one may connect to several different ports on the local IQFeed exe server. One of those is the admin port. So firts, I try to connect to the admin port just as a test to see if IQFeed is already running. If that fails twice (after pausing between attempts), I call a shell script (a batch file on Windows) which runs IQFeed.exe. Then I try to connect 3 more times (after pauses). Since my rust code might looke like gobbledygook, I'll demonstrat this with pseudo code that resembles python (but is not actually python):

admin_conn_attempts = 0
conn_attempt_pause_seconds = 4
while True:
admin_conn = tcp_connect("127.0.0.1", 9300) #the admin socket
if admin_conn.is_connected():
break
else
sleep(conn_attempt_pause_seconds)
admin_conn_attempts += 1
if admin_conn_attempts == 2:
# run external program to start IQFeed.exe
run.program(IQFeed.exe)
else if admin_conn_attempts > 5:
print("ERROR: Unable to connect to IQFeed")
exit -1


If i get this far in the code and it didn't exit, that means I'm connected.

I'm aware IQFeed should just start automatically if it's not running but I'm running under Wine on Linux and I have not observed that behavior. I call a shell script to run it (instead of the executable itself) because I set some additional environment things up before running -- such as pinning IQFeed to a certain set of cores on my multi-core processor.


-Mark D. Valor
Edited by mkvalor on Feb 10, 2024 at 07:31 PM
 

 

Time: Sun July 21, 2024 5:46 AM CFBB v1.2.0 7 ms.
© AderSoftware 2002-2003