Unclear error and crash

Hello! Does anybody know what this error means? It happens during analysis that I auto-repeat every 2 seconds. It works fine 99.9% of the time, but sometimes, Amibroker crashes and suggests to Exit or Recover, If I click on recover this error appears. I click on OK and it continues as normal, but the error reoccurs twice per day. If relevant, my AFL includes:

EnableScript("VBScript");

error

This is Microsoft VBScript engine error. Can't do much if it happens 0.01% of time. VBScripting is generally ancient technology. I suggest replacing the code with native AFL. There is almost no reason to use VBScript.

Tomasz, thank you for your reply. The crash recovery system produces the following report:

AmiBroker version 6.28.0.6280
( 64-bit, cooltool.dll 6.28.0,  mfc42.dll 6.28.0,  msvcrt.dll 7.0.18362 )

Microsoft Windows 10 version 10.0 (Build 18363) 
Service Pack 0.0, Common Controls: 6.16

Unhandled exception
Type:	CSysException
Code:	c0000005
Description:	ACCESS VIOLATION
Address:	0000000000000000

EnableScript("VBScript"); 
 
<
^
File: 'Formulas\Custom\INTRADE.afl', Ln: 5, Col: 1
Error 47.
Exception occurred during AFL formula execution at address: 0000000000000000, code: C0000005
Call Stack:
00007FFA17747813 (module-name not available), (function-name not available)() +0 byte(s)
0000000000000001 (module-name not available), (function-name not available)() +0 byte(s)
00007FFA1774C204 (module-name not available), (function-name not available)() +0 byte(s)
000000049C3FD5D2 (module-name not available), (function-name not available)() +0 byte(s)
0000000000000950 (module-name not available), (function-name not available)() +0 byte(s)


Additional information:

Multi-threaded charts - ENABLED

Number of stock loaded: 11173
Currently selected stock: VXRT
Number of quotes (current stock): 7850

Workspace:
Data source = IBRK, Data local mode = 1, NumBars = 14000

Preferences:
Data source = (local), Data local mode = 1, NumBars = 10000

Command history:

Cache manager stats:
Number of list elements: 18
Number of map elements: 18
Hash table size: 16001

Memory status:
  MemoryLoad: 64 %
  TotalPhys:     16661804K  AvailPhys:      5876724K
  TotalPageFile: 33439020K  AvailPageFile: 17437840K
  TotalVirtual:  4294967168K  AvailVirtual:  4289519528K

The respective part of the AFL that the error refers is to is this:

EnableScript("VBScript");

<% 

Public Sub pushbullet(Message_Text)
Dim Message 

'Your Message 
Message = Message_Text

Dim objXmlHttpMain , URL

strJSONToSend = "{""type"": ""note"", ""title"": """ &Message_Text&""", ""body"":""""}"

URL="https://api.pushbullet.com/v2/pushes" 
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP") 
on error resume next 
objXmlHttpMain.open "POST",URL, False 
objXmlHttpMain.setRequestHeader "Authorization", "Bearer o.XXXXXXXXXXXXX"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing 
set objResult = nothing

'Store response 
'msgbox(objXmlHttpMain.responseText)
'response.Write (objXmlHttpMain.responseText) 
alert("Hi")
End Sub 

%>

pb = GetScriptObject();

This code allows Amibroker to sendPushbullet messages and I don't think it can be rewritten in AFL completely. The error occurs rarely but usually twice per day on auto-repeat.

One interesting thing is that this error did not occur when I used eSignal as data source. It started after I switched to IB.

As I said - the only solution is to get rid of Microsoft VBScript completely. You are using VBScript AND COM/OLE inside. Both are old and not really multi-threading friendly.

You do NOT need them. Everything you do here can be done in PURE AFL.

HTTP POST requests can now be sent directly from AFL http://www.amibroker.com/guide/afl/internetpostrequest.html

3 Likes

Would appreciate it if you could advise how to write the same HTTP POST request using the new InternetPostRequest function with the access token and json. Unfortunately there are hardly any examples on the forum and elsewhere that have similar requests.

PushBullet suggests to use the following structure:

curl --header 'Access-Token: <your_access_token_here>' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'

Not sure how to translate this into AFL with InternetPostRequest.

Tried this, but no success:

post = "--header Access-Token: 'XXXXXXXXX' --header Content-Type 'application/json' --data-binary '{\"type\": \"note\", \"title\":\"test\", \"body\": \"test\"}'";

InternetPostRequest( "https://api.pushbullet.com/v2/pushes", post);

This is not curl.

Docs are here: http://www.amibroker.com/f?internetpostrequest

InternetPostRequest expects POST DATA in the argument. Also it sends data using Content-Type: application/x-www-form-urlencoded. This is internally set and you can't change it at the moment.

If you to use curl, use ShellExecute instead http://www.amibroker.com/f?shellexecute to call curl.

Curl is not an option as I'd like to send messages from AFL. Since it will not be possible to use InternetPostRequest with json as Content-Type, it seems that my only option is to stay with the previous approach which crashes Amibroker periodically? This error still occurs with the latest version 6.35.1.

You can send messages from AFL using curl and ShellExecute. ShellExecute allows to use ANY external program. Or you should ask API vendor to send authorization WITHOUT using headers. Or you can build local proxy in php that will set the header. You can also call COM directly from AFL (CreateObject is in pure AFL http://www.amibroker.com/f?createobject). There are dozens of options, all without VBScript.

Furthermore next version will provide a way to set your custom headers.

6 Likes

Hello Tomasz,

Will the ability to set custom headers be available in version 6.38?

Thank you!