You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
The signals are available in the scripting language which is part of the charting software. I can write them to a file, or call a DLL.
I would probably create a named Windows Event and signal it. You may have to create a DLL to hold a procedure to call the OpenEvent(), SetEvent() sequence but this is really straightforward. Now your PB program can set up a separate thread of execution to wait on that event being signaled.
I'm sure I have demos in the source code forum. Search on my name as thread starter and "event" in the thread title and you should find some good starter code.
"IOW, the website is probably not going to work with WinHTTP."
It would be easier to check if we had the actual web site link, I can understand not giving the "token" and "varname", but we could get more precise info from the actual server. Now we are just guessing.
Thanks for the explanation.
I remember not having any luck, but hoped somebody else would.
I'd probably repurchase sockettools with a PowerBASIC example of client/server.
I've wanted to put TLS support into SQLitening for years.
Have code to tap into .NET from PowerBASIC, but haven't yet used since not a .NET person.
Probably shouldn't have mentioned this, but in the right hands could be very useful.
See Post 8 and : "URL does not use an authorized protocol" suggests that the website either required HTTP/2 or HTTP3 and or requires TLS1.2
Then note from your link above:
The following features have been added in version 5.1 of WinHTTP:
HTTP/1.0 protocol, including support for keep-alive (persistent) connections and session cookies.
HTTP/1.1 chunked transfer support for HTTP responses
...
Secure Sockets Layer (SSL) functionality, including client certificates. Supported SSL protocols include the following: SSL 2.0, SSL 3.0, and Transport Layer Security (TLS) 1.0.
IOW, the website is probably not going to work with WinHTTP.
Have code to tap into .NET from PowerBASIC, but haven't yet used since not a .NET person.
Probably shouldn't have mentioned this, but in the right hands could be very useful.
Michael, thank you for taking interest. I have been reading and following you here for many years!
The signals are available in the scripting language which is part of the charting software. I can write them to a file, or call a DLL.
This was never the problem.
I wished to know how to send an URL to the big web.
This is the python code that does that. (I gave this code earlier).
I have made a workaround:
In the charting software I write to a file. This is done every 30 minutes.
A small python code reads the file every 30 minutes and then sends the URL using the code mentioned above.
I wanted to know how to send this URL in PB. I could not understand the answers.
added through edit: I use Windows 11. I am not windows programmer by any chance!
Charting software creates Signals -----> PB code receives the signals, uploads to web ------------------> Trading software on web receives the signals, executes the trade.
How do I communicate from my charting software to PB? through a DLL (not possible) or through writing the signals in a file which PB can pick up.
The question I asked here was how to upload to the web using PB. This was achieved with a few lines of python code which I shared in my posts.
While Stuart did try to help a lot, my limited understanding could not grasp the subject. My fault.
I sincerely apologize for having asked what now appears to have been an incomplete or even foolish question.
Can your charting software read from the clipboard, a file or get a windows message?
Went from trading software to charting software. Also, it appears https security is needed.
Also suddenly introduced DLL from a 64bit application
Can your charting software read from the clipboard, a file or get a windows message?
Went from trading software to charting software. Also, it appears https security is needed.
Stuart, Thank you for your time and effort. I really appreciate it. It now appears that I cannot run a 32-bit DLL from my 64-bit charting software. Therefore, even if I did get PB to get the URL I would not be able to call it from my software.
Opens port 80, but URL is to HTTPS: which is port 443 (if I remember correctly) It adds a security layer.
,
There's a lot more th HTTPS than just changing the oprt. The system needs to establish a secure, encrypted connection before exchanging any other data. There are a number of other issues with that TCP code that I won't bother to go into since it won't work with HTTPS
As for POST v GET, you can't just replace th GET with POST in the previous code. If you read the link in Post5, you will see that you need to handle POST ini an entirely idfferent way - the paramters are NOT part of the URL with a POST.
"URL does not use an authorized protocol" suggests that the website either required HTTP/2 or HTTP3 and or requires TLS1.2 and WInHTTP is connecting with a lower protocol What version of Windows are you using?
Using WinHTTP, you probably need to use WINHTTP_OPTION_ENABLE_HTTP_PROTOCOL and/or WINHTTP_OPTION_SECURE_PROTOCOLS
The following option flags are supported by [**WinHttpQueryOption**](/windows/win32/api/Winhttp/nf-winhttp-winhttpqueryoption) and [**WinHttpSetOption**](/windows/win32/api/Winhttp/nf-winhttp-winhttpsetoption).
Alternatively, search the forums for one of the examples of using "MsXml2.ServerXMLHTTP.6.0"
I picked up some Python code from the web and it worked the first time. The code sent the appropriate message to the trading website, which did the required paper trade.
the following PB code gives error: URL does not use an authorized protocol
Code:
FUNCTION GetURL (strName AS STRING,strVal AS STRING) AS STRING
LOCAL pWHttp AS IWinHttpRequest
LOCAL strBuffer AS STRING
LOCAL strToken AS STRING
LOCAL strURL AS STRING
LOCAL iSucceeded AS INTEGER
strToken="dummy"
strURL = "https://api.website.com/api?auth-token=" & strToken & "&key=" & strName & "&value=" & strVal
'strURL = "http://powerbasic.com"
pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
TRY
pWHttp.Open "POST", strURL ' tried with GET also. same error
pWHttp.Send
iSucceeded = pWHttp.WaitForResponse(5)
strbuffer = pWHttp.Responsetext
CATCH
OleShowErrorInfo OBJRESULT
END TRY
FUNCTION = strBuffer
END FUNCTION
An example given in the samples section also gives an error:
Code:
FUNCTION PBMAIN() AS LONG
LOCAL Buffer$, Site$, File$
LOCAL Entire_page$, Htmlfile$, Link$
LOCAL Pos&, Length&
LOCAL token AS STRING, varname AS STRING, myval AS STRING, myurl AS STRING
token="Dummy"
varname = "Dummy"
myval = "1"
myurl = "https://api.website.com/api?auth-token=" & token & "&key=" & varname & "&value=" & myval
Site$ = myurl
' Connecting...
TCP OPEN "http" AT Site$ AS #1 TIMEOUT 60000
' Could we connect to site?
IF ERR THEN
MSGBOX "error"
EXIT FUNCTION
END IF
MSGBOX "opened"
' Close the TCP/IP port...
TCP CLOSE #1
END FUNCTION
Thanks, Stuart. The code is complete. The URL refers to a trading website where I have an account. I pass on a unique token + Key + value and the website executes a trade mentioned in the key. The value is usually 1- for buy, 2 for sell. Thank you for your help. I will work on it.
In that case, it should really be using a POST, not a GET!
You need to read the details of GET and POST here:
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
I tried searching for these 2 files but did not locate them in the forum. Please give me directions on where to get them
"httprequest.inc"
"ole2utils.inc"
Okay, I got these files from the Roca download section in this forum.
Thanks, Stuart. The code is complete. The URL refers to a trading website where I have an account. I pass on a unique token + Key + value and the website executes a trade mentioned in the key. The value is usually 1- for buy, 2 for sell. Thank you for your help. I will work on it.
Looks like a simple HTTP Get, but there seems to be some code missing.
I don't see what that sub does with the response from the web server and you are not doing anything with oStream.
You should be able to replace that VBScript with something like the following PowerBASIC code:
'
Code:
#COMPILE EXE ' Roca Includes!
#DIM ALL
#INCLUDE ONCE "httprequest.inc"
#INCLUDE ONCE "ole2utils.inc"
...
FUNCTION GetURL (strName AS STRING,strVal AS STRING) AS STRING
LOCAL pWHttp AS IWinHttpRequest
LOCAL strBuffer AS STRING
LOCAL strToken STRING
LOCAL sURL AS STRING
LOCAL iSucceeded AS INTEGER
strToken ="xxmmfkfh58547n5ign"
strURL = url = "https://api.xx.xx/api?auth-token=" & strToken & "&key=" & strName & "&value=" & strVal
pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
TRY
pWHttp.Open "GET", strURL
pWHttp.Send
iSucceeded = pWHttp.WaitForResponse(5)
buffer = pWHttp.Responsetext
CATCH
OleShowErrorInfo OBJRESULT
END TRY
FUNCTION = strBuffer
END FUNCTION
'
A forum search on "MsXml2.ServerXMLHTTP.6.0 will also give you a number of code examples using that rather than the WinHttp.WinHttpRequest.5.1 above.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: