Python function call in Matlab, 'ENUM' argument issue?

8 views (last 30 days)
Hi, I'm using Matlab R2019b, Python 3.7 and I can't to understand why I receive these errors when I call the Python function 'create_order'/'create_test_order' associated to the Binance library (https://python-binance.readthedocs.io/en/latest/account.html). Consider the method 'create_test_order', 3 arguments are mandatory: create_test_order(string symbol,enum side,enum type). 'side' and 'type' associate strings to the enum.
Calling the function with only one argument: create_test_order(pyargs('symbol','BNBBTC')), I get back obviously the error:
Error using client>_handle_response (line 230)
Python Error: BinanceAPIException: APIError(code=-1102): Mandatory parameter 'side' was not sent, was empty/null, or
malformed.
Error in client>_request (line 197)
Error in client>_request_api (line 202)
Error in client>_post (line 240)
Error in client>create_test_order (line 1578)
'side' is missing, and calling the function with the second argument: create_test_order(pyargs('symbol','BNBBTC'),pyargs('side','BUY')), I get back:
Unrecognized method, property, or field 'create_test_order' for class
'py.binance.client.Client'.
Error in cryTestOrder (line 8)
BIN.Client.create_test_order(pyargs('symbol','BNBBTC'),pyargs('side','BUY'))
That's quite strange since the method exists, as I showed before, receiving the first error... I tried also to call che function with: create_test_order(pyargs('symbol','BNBBTC'),pyargs('side',py.enumerate('BUY'))) or BIN.Client.create_test_order(pyargs('symbol','BNBBTC'),pyargs('side',py.enumerate(py.str('BUY')))), and all the possible combinations but nothing change...
Do you know why I'm facing this issue with this Python function call? Maybe the enum type is not supported for the Python integration with Matlab? How can I fix the problem?
Thank you so much

Answers (1)

Bjørn Rudi Dahl
Bjørn Rudi Dahl on 28 Jun 2021
I ran into a similar(ish) issue when communicating with an oscilloscope via python.
In python I enumerated the trigger modes:
class TriggerMode(Enum):
auto = "AUTO"
normal = "NORM"
single = "SINGLE"
stop = "STOP"
In Matlab I had to do the below [with the module named OscCtrl] to get a hold of the enum to pass into my set_trigger_mode- method in python (Matlab-code below):
py.OscCtrl.TriggerMode("AUTO")
to pass the correct parameter to my set-method (Matlab-code below):
oscillosope.set_trigger_mode(py.OscCtrl.TriggerMode("AUTO"))
So it seems to me, that if you know the value(s) of the enumeration you need to use, you can access it like I did to use as input to your method call.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!