oanda / v20-python

OANDA v20 bindings for Python
MIT License
225 stars 91 forks source link

v20.instrument.orderBook not implemented #29

Closed dcolley closed 6 years ago

dcolley commented 6 years ago

http://developer.oanda.com/rest-live-v20/instrument-ep/ refers an orderBook action, but this is not available in v20

api = v20.Context(
    hostname=config["hostname"],
    port=config["port"],
    token=config["token"],
    datetime_format=config["datetime_format"]
)
params = {
    "time": "2018-09-28T12:00:00:00Z"
}
response = api.instrument.orderBook(instrument, **params)
orderBook = response.get("orderBook", 200)
print(orderBook)

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-47-355910ca7359> in <module>()
      3     "time": "2018-09-28T12:00:00:00Z"
      4 }
----> 5 response = api.instrument.orderBook(instrument, **params)
      6 orderBook = response.get("orderBook", 200)
      7 print(orderBook)

AttributeError: 'EntitySpec' object has no attribute 'orderBook'

Is this a bug?

hootnot commented 6 years ago

I don't use this lib,, but sources contain OrderBook, so does it fail with a capital 'O' also ?

dcolley commented 6 years ago

I tried that. OrderBook exists, but does not work as the REST API is documented.

hootnot commented 6 years ago

You can use make use of oandapyV20 instead, it supports that. You can use v20 and oandapyV20 parallel, so for a quick hack you use only oandapyV20 for the orderbook info.

dcolley commented 6 years ago

from command line:

curl \
  --compressed \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
  "https://api-fxtrade.oanda.com/v3/instruments/USD_JPY/orderBook"

returns:


{"orderBook":{
"instrument":"USD_JPY","time":"2018-09-28T12:40:00Z","unixTime":"1538138400","price":"113.437","bucketWidth":"0.050",
"buckets":[
  {"price":"0.000","longCountPercent":"0.0071","shortCountPercent":"0.0000"},
  {"price":"0.100","longCountPercent":"0.0214","shortCountPercent":"0.0214"},
  {"price":"0.150","longCountPercent":"0.0071","shortCountPercent":"0.0285"},
  {"price":"0.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.300","longCountPercent":"0.0000","shortCountPercent":"0.0142"},
  {"price":"0.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.500","longCountPercent":"0.0071","shortCountPercent":"0.0071"},
  {"price":"0.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"0.700","longCountPercent":"0.0214","shortCountPercent":"0.0071"},
  {"price":"0.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.850","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"0.900","longCountPercent":"0.0000","shortCountPercent":"0.0142"}, 
  {"price":"0.950","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.000","longCountPercent":"0.1638","shortCountPercent":"0.0783"}, 
  {"price":"1.050","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.100","longCountPercent":"0.0071","shortCountPercent":"0.0142"}, 
  {"price":"1.150","longCountPercent":"0.0071","shortCountPercent":"0.0000"}, 
  {"price":"1.200","longCountPercent":"0.0142","shortCountPercent":"0.0071"}, 
  {"price":"1.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.750","longCountPercent":"0.0142","shortCountPercent":"0.0000"}, 
  {"price":"1.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.000","longCountPercent":"0.0000","shortCountPercent":"0.0214"}, 
  {"price":"2.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.000","longCountPercent":"0.0000","shortCountPercent":"0.0142"}, 
  {"price":"3.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.000","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}
}```
dmpettyp commented 6 years ago

It looks like the enpoint that is used to fetch the orderbooks wasn't set up correctly to have an API call auto-generated for it. I'll get that added and published shortly. The API call will indeed be "api.instrument.orderBook()" as you had predicted.

dmpettyp commented 6 years ago

actually, since it's python, the API call will be order_book()

dcolley commented 6 years ago

@dmpettyp the code is littered with camelCase... hence I was following that convention. I have a PR that solves the problem for me - should I submit it?

dcolley commented 6 years ago

PR https://github.com/oanda/v20-python/pull/30 created

dmpettyp commented 6 years ago

Hmm, while there is camel case in the code, I believe that it mostly is used to access data from the JSON responses, which is all camel case. I think that most of the python variables and function names use snake case.

Thanks for the PR, however all of the code in the library is auto-generated and we're not set-up to merge code into the library. You should be able to find the order_book() call is in the latest build.

https://github.com/oanda/v20-python/blob/master/src/v20/instrument.py#L932

dcolley commented 6 years ago

Sweet! :thumbsup:

dcolley commented 6 years ago

PS: you should also do this for position_book()

dmpettyp commented 6 years ago

scroll!

https://github.com/oanda/v20-python/blob/master/src/v20/instrument.py#L1038

asasa293 commented 1 year ago

Can someone explain to me please, what does shortCountPercent and longCountPercent mean? how can I interpret this information?

cadwallader commented 1 year ago

The percentage of standing orders to sell and buy (respectively) at price points within the corresponding price bucket. The bucket’s lower bound is the price given and its upper bound is the price plus the bucket width, not inclusive, if I recall correctly.On Jan 22, 2023, at 1:16 PM, Santiago Ruiz Zuluaga @.***> wrote: Can someone explain to me please, what does shortCountPercent and longCountPercent mean? how can I interpret this information?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>