I'm with the rest. Please consider using python. I can use julia but python is more fun.
so in purebasic you'd
; PureBasic example for connecting to IB API and requesting account details
#PORT = 7497 ; TWS or Gateway default port
#HOST = "127.0.0.1"
; Establish a socket connection
If OpenNetworkConnection(#HOST, #PORT)
Debug "Connected to IB TWS/Gateway"
; Send handshake message (TWS Protocol version)
SendNetworkString(0, "API\0")
Delay(100)
; Request account details (e.g., account summary request)
requestID = 1
version = 1
message = "9" + Chr(0) + Str(version) + Chr(0) + Str(requestID) + Chr(0) + "All" + Chr(0)
SendNetworkString(0, message)
Delay(200)
; Receive and parse response
Repeat
buffer = ReceiveNetworkData(0, *memory, 4096)
If buffer > 0
result$ = PeekS(*memory, buffer)
Debug result$
EndIf
Until buffer <= 0
CloseNetworkConnection(0)
Else
Debug "Failed to connect to IB TWS/Gateway"
EndIf
and in python you'd
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
class IBApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId, errorCode, errorString):
print(f"Error: {reqId}, {errorCode}, {errorString}")
def accountSummary(self, reqId, account, tag, value, currency):
print(f"Account Summary. ID: {reqId}, Account: {account}, {tag}: {value} {currency}")
def accountSummaryEnd(self, reqId):
print(f"Account Summary End for request ID: {reqId}")
self.disconnect()
def main():
app = IBApp()
app.connect("127.0.0.1", 7497, clientId=1)
# Wait for the connection to establish
app.run()
# Request account summary
app.reqAccountSummary(9001, "All", "NetLiquidation,AvailableFunds")
if __name__ == "__main__":
main()