hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
402 stars 107 forks source link

question for Feite #197

Closed traveller1011 closed 1 year ago

traveller1011 commented 1 year ago

hootnot,

question about the orders in import oandapyV20.endpoints.orders as orders

Context

i seem to NOT get a complete list of orders back. and i cannot figure out why.

params = {}
r = OrderList(accountID, params=params)
rv = CLIENT.request(r)
print(rv)

... i get a healthy, but empty, response:

{'orders': [], 'lastTransactionID': '89'}

the Oanda endpoint in question is here:

https://developer.oanda.com/rest-live-v20/order-ep/

image

How I have been getting Orders in the interim

So I queried for Transactions list, which worked great. Then, from transactions, i deduced a list of order IDs that "must" exist. And queried for order details by individual pk.. You can see some orders here:

image

... But i want to query a list of my orders directly, instead of approaching it from the backdoor. I think I am just missing something dumb.

Question/Ask

Do you see where I might have gone wrong? If you just give me an inkling of idea, it would be appreciated. Also - i really love this package. And the style of code. Thank you for publishing this.

hootnot commented 1 year ago

Make sure you enter a limit order. Market orders will get executed directly and therefore not show up in the orderlist since that one does PENDING by default.

So, in your case, without specifying params, you only will see PENDING orders, and there will be none if you only issue MARKET orders.

I've just entered a limit sell EUR_JPY @145 and it gives me:

{
  "orders": [
    {
      "id": "387093",
      "createTime": "2023-01-06T08:28:04.607826616Z",
      "type": "LIMIT",
      "instrument": "EUR_JPY",
      "units": "-500000",
      "timeInForce": "GTD",
      "price": "145.000",
      "gtdTime": "2023-01-13T08:27:48.000000000Z",
      "triggerCondition": "DEFAULT",
      "partialFill": "DEFAULT_FILL",
      "positionFill": "DEFAULT",
      "state": "PENDING"
    }
  ],
  "lastTransactionID": "387093"
}

In your case you need to pass:

params = {"state": "FILLED"}

Or use the definitions: oandapyV20.definitions.orders

import oandapyV20.definitions.orders as od
...
params = {"state": od.OrderState.FILLED}

... and then your MARKET orders will show up.