Position Data for Binance
Closed this issue · 6 comments
I remember reading, somewhere in here, that you planned on some day adding support for pulling data related to open positions. I utilize your program for trading on Binance, but kind of have to drive blind when it comes to the program knowing if I have open positions or not.
If some code for grabbing open position (trades) data were added, that would be an amazing icing on the cake. Thank you for all of your work on this.
Hi @ITJusus
do check out the current example with the current code (I updated it over the past months). For Binance this is the API documentation:
https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
For openorders they give:
GET /api/v3/openOrders (HMAC SHA256)
So in VBA code that would be (make sure your api key is in Cred, like the examples in the file):
Dim ParamsT As New Dictionary
ParamsT.Add "timestamp", GetBinanceTime()
JsonResult = PrivateBinance("openOrders", "GET", Cred, ParamsT)
That should give you back your open orders.
Does that help?
Cheers,
Koen
Yes, thank you. I'll give it a shot.
Hello again. I'm trying to work my way through this, but I seem to be getting stuck.
When I run the following, I get a nice clean plethora of values between { }...
Debug.Print PrivateBinance("account", "GET", Cred, ParamsT)
When I run the openorders equivalent, I just get an empty [ ]...
Debug.Print PrivateBinance("openOrders", "GET", Cred, ParamsT)
Am I just not able to print an array and that's why this is happening? Or do you know if I'm doing something else wrong? I know I have 3 open orders currently. But it just comes back with [ ].
Hi there,
okay, maybe the following helps:
-make sure the API key has the proper rights (might require trade permission)
-you could try "allOrders" instead, that requires a symbol
Dim ParamsT As New Dictionary
ParamsT.Add "timestamp", GetBinanceTime()
ParamsT.Add "symbol", "LTCBTC"
JsonResult = PrivateBinance("allOrders", "GET", Cred, ParamsT)
-try either "order" or "openOrders" with a symbol (all variations are in the Binance API docs)
The data that is returned is JSON, but it is also simply text, the next steps of the code transform that text into something that you can loop through etc. So a debug.print should give you the whole reply (no hidden parts of an array). Hope any of those options work?
Thank you for the sage advice.
I was at least able to get some progress. When I add a specif symbol to the ParamsT and then utilize "allOrders"...I actually get results back.
Debug.Print PrivateBinance("allOrders", "GET", Cred, ParamsT)
Unfortunately, when I try the same, except changing "allOrders" to "openOrders"...it just returns [ ]. No data.
Debug.Print PrivateBinance("openOrders", "GET", Cred, ParamsT)
So, it's able to pull my order history (allOrders) but not my currently active orders (openOrders). Odd.
I did try replacing "openOrders" with "orders" and "order", but it just fails with the following error in either case...
{"error_nr":404,"error_txt":"HTTP-Not Found","response_txt":0}
I do have trading enabled in my api key. I've also been reading through the Binance API page and trying different options much of the day yesterday.
Problem with using "allOrders" is it pulls all active, cancelled, or filled orders...and only for 1 symbol. Since I really only want to know what orders (trades) I currently have open for any symbols...this would be much more difficult to use to try to grab only the data I need.
The "openOrders" would hit the spot, but it just doesn't seem to want to work. Crazy I can just replace "openOrders" with "allOrders" and I do get results. What does that isolate to be the problem then, is what I'm trying to figure out now.
Hi there,
did you update the ModWeb module, as I improved the way the code processes the feedback the API gives?
I'm not actively using Binance, so have no orders nor coins to test, but these are my results:
allOrders: {"error_nr":400,"error_txt":"HTTP-Bad Request","response_txt":{"code":-1121,"msg":"Invalid symbol."}}
openOrders: []
order: {"error_nr":400,"error_txt":"HTTP-Bad Request","response_txt":{"code":-1102,"msg":"Mandatory parameter 'symbol' was not sent, was empty/null, or malformed."}}
That should help you finding out which parameters the API needs/expects. Otherwise you might want to ask around in their Telegram API group: https://t.me/binance_api_english
Cheers