mazmex7 / BitMEX-API-python

A lightweight script to connect BitMEX REST API.
52 stars 22 forks source link

Function locations? #2

Open Indiana3714 opened 6 years ago

Indiana3714 commented 6 years ago

Hi @mazmex7

Wondering if you can let me know how to find the relevant functions? Swagger python client confuses me a lot.

Eg your sample file shows: orders = bitmex_cli.Order.Order_getOrders(symbol='XBTUSD', reverse=True).result()

How did you know it was done in Order.Order_getOrders()?

Looking at bitmex doesnt really indicate this

I've been trying to scan the bravado file etc to no avail too.

I've managed to get "active_positions = client.Position.Position_get().result()" but that was purely by guessing sadly

I'm looking at the auto generated docs for python:

This should work but doesn't (even though it is shown in UserApi.md) a = client.User.user_get_margin().result()

macd2 commented 5 years ago

have a look here: https://www.bitmex.com/api/explorer/

bitRomney commented 5 years ago

Hi @mazmex7

Wondering if you can let me know how to find the relevant functions? Swagger python client confuses me a lot.

Eg your sample file shows: orders = bitmex_cli.Order.Order_getOrders(symbol='XBTUSD', reverse=True).result()

How did you know it was done in Order.Order_getOrders()?

Looking at bitmex doesnt really indicate this

I've been trying to scan the bravado file etc to no avail too.

I've managed to get "active_positions = client.Position.Position_get().result()" but that was purely by guessing sadly

I'm looking at the auto generated docs for python:

This should work but doesn't (even though it is shown in UserApi.md) a = client.User.user_get_margin().result()

I know the swagger.json file is totally confusing! You can implement your strategy using any endpoint/operationId found in BitMEX’s swagger.json by using the following naming convention.

Above, we see the ‘operationId’ is “Order.new”, so the correct naming convention in your python would be derived as

client.Order.Order_new(symbol=symbol, orderQty=qty, price=price).result()

So if you wanted to see your open orders and the ‘operationId’ was Order.getOrders

Your python script would look like this:

print client.Order.Order_getOrders().result()

Every ‘operationId’ looks like this. ‘Order.something’ or, more generically, ‘Operation.something’. You can use this pattern of renaming from

‘Operation.something’

to

‘client.Operation.Operation_something’

to call any ‘operationId’ listed in the swagger.json file (eg client.Order.Order_getOrders().result() to see orders, and client.Order.Order_new(symbol=symbol, orderQty=qty, price=price).result() to make orders) . Don’t ask me why they throw the extra ‘Operation’ in after client every time but at the very least they are consistent. The most complete list of endpoints/operationIds is in the swagger.json file