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

Direction of the trade is not available #136

Closed 98thpixel closed 5 years ago

98thpixel commented 5 years ago

Thanks for the amazing library.

However, I just ran the sample code for fetching the list of open trades and noticed that the response does not include the direction of the trade (i.e BUY or SELL).

Is this how it is supposed to be or a bug? Are there any other workarounds to find whether a trade is a sell trade or a buy trade?

hootnot commented 5 years ago

it is pretty simple: a negative number of units is a short position, positive is long. See: https://github.com/hootnot/oandapyV20-examples/blob/master/src/market_orders_requests.py, it shows how to place a market order LONG. If you change the units to -100 it will be a SHORT order.

If you are LONG 100 and you place a SHORT order -200 you will end up with a net SHORT of -100. (asuming hedging is not activated)

So, this is not a bug, checkout the docs of oanda too: developer.oanda.com. Their specific example: http://developer.oanda.com/rest-live-v20/order-ep/#collapse_2_example_curl_2