Skip to content

v20.instrument.orderBook not implemented #29

Closed

Description

@dcolley

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?

Activity

  1. hootnot commented on Sep 28, 2018

    @hootnot

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

  2. dcolley commented on Sep 28, 2018

    @dcolley
    Author

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

  3. hootnot commented on Sep 28, 2018

    @hootnot

    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.

  4. dcolley commented on Sep 28, 2018

    @dcolley
    Author

    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"}
    }```
  5. dmpettyp commented on Sep 28, 2018

    @dmpettyp

    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.

  6. dmpettyp commented on Sep 28, 2018

    @dmpettyp

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

  7. dcolley commented on Sep 28, 2018

    @dcolley
    Author

    @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?

  8. dcolley commented on Sep 28, 2018

    @dcolley
    Author

    PR #30 created

  9. dmpettyp commented on Sep 28, 2018

    @dmpettyp

    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

  10. dcolley commented on Sep 28, 2018

    @dcolley
    Author

    Sweet! 👍

  11. dcolley commented on Sep 28, 2018

    @dcolley
    Author

    PS: you should also do this for position_book()

  12. dmpettyp commented on Sep 28, 2018

    @dmpettyp
  13. asasa293 commented on Jan 22, 2023

    @asasa293

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

  14. cadwallader commented on Jan 22, 2023

    @cadwallader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions