I’m brand new to Alpaca and using an API, but I was thinking of reviving an old Access database I used to use to play around with day trading strategies. While I realize I may have to rewrite all that VBA into something else like Java or Python (also new to me), I first wanted to see if there’s a way to send POST messages from Access to the API.
I’ve found some general tips on Access and POST methods, but my initial attempts get a “not found” error when sending to the API url.
Here was one attempt using a JSON string: https://paper-api.alpaca.markets/v2/orders/ {“symbol”: “UVXY”, “qty”: 500, “side”: “sell”, “type”: “market”, “time_in_force”: “cls”, “client_order_id”: “123456”}
I’m really just looking to revive this Access database with its VBA code to generate order ideas and send those orders to the Alpaca API (paper trading only). Years ago when I first used the db, I had access to a Bloomberg terminal and could easily import real-time prices to simulate order fills. Now I’d like to have Access send the order message to Alpaca, get the response/fill back, and then track positions as it goes along.
Getting the POST from Access to actually reach the API!
Here’s the VBA function:
Public Function HTTP_RESP(ByVal sReq As String) As String
Dim byteData() As Byte
Dim XMLHTTP As Object
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "POST", sReq, False
XMLHTTP.send
byteData = XMLHTTP.responseBody
Set XMLHTTP = Nothing
HTTP_RESP = StrConv(byteData, vbUnicode)
End Function
And here’s the URL and JSON string I’m trying to pass into the function and through to Alpaca: https://paper-api.alpaca.markets/v2/orders {“symbol”: “UVXY”, “qty”: 500, “side”: “sell”, “type”: “market”, “time_in_force”: “cls”, “client_order_id”: “123456”}
I’m getting this error in response:
{“code”:40410000,“message”:“endpoint not found”}
I had a similar issue with integrating Access to SendGrid. Don’t include the braces in the endpoint. Try removing the braces in your JSON (its really not json). In my experience, the XMLHTTP object is better created as “MSXML2.ServerXMLHTTP”. I would also check XMLHTTP.Status after sending along with the responseBody.
I have the code for POSTING. You can email me at odiephd@gmail.com and I will give you the code. I can’t post it here. Alpaca limits new users to the number of postings.
I think it’s discourse’s limit to avoid potential spam but over the time as a membership duration increases such limit goes away. Apologies for inconvenience.