Qluxzz / avanza

A Python library for the unofficial Avanza API
https://qluxzz.github.io/avanza/
MIT License
85 stars 40 forks source link

Extension request: Ability to get info about ETFs #87

Open tsjk opened 10 months ago

tsjk commented 10 months ago

I'm a new user of this package and think it's awesome. I'd like to have details on ETFs, though. Currently, there is no route defined for ETFs, and just translating to enum to text yields the wrong url. I currently hack my way around this (I <3 Python's stance here and allowing this) by doing like

avanza_._Avanza__call(HttpMethod.GET, '/_api/market-guide/exchangetradedfund/<id>')

and

avanza_._Avanza__call(HttpMethod.GET, '/_api/market-guide/exchangetradedfund/<id>/details')

where avanza is my Avanza object and HttpMethod.GET is from avanza.constants. But it'd be nice to at least have a working route and some helper functions.

tsjk commented 10 months ago

/_api/market-guide/exchangetradedfund/<id> returns:

{
  "orderbookId": str,
  "name": str,
  "isin": str,
  "tradable": str,
  "listing": {
    "shortName": str,
    "tickerSymbol": str,
    "countryCode": str,
    "currency": str,
    "marketPlaceCode": str,
    "marketPlaceName": str,
    "tickSizeListId": str,
    "marketTradesAvailable": bool
  },
  "historicalClosingPrices": {
    "oneDay": float,
    "oneWeek": float,
    "oneMonth": float,
    "threeMonths": float,
    "startOfYear": float,
    "oneYear": float,
    "threeYears": float,
    "fiveYears": float,
    "tenYears": float,
    "start": float,
    "startDate": str
  },
  "keyIndicators": {
    "direction": str,
    "leverage": float,
    "numberOfOwners": int,
    "historicYield": float,
    "historicYieldDate": str
  },
  "quote": {
    "buy": float,
    "sell": float,
    "last": float,
    "highest": float,
    "lowest": float,
    "change": float,
    "changePercent": float,
    "spread": float,
    "timeOfLast": int,
    "totalValueTraded": float,
    "totalVolumeTraded": int,
    "updated": int,
    "volumeWeightedAveragePrice": float
  },
  "type": str
}
tsjk commented 10 months ago

...and avanza_._Avanza__call(HttpMethod.GET, '/_api/market-guide/exchangetradedfund/<id>/details') returns:

{
  "assetCategory": str,
  "category": str,
  "issuer": str,
  "description": str,
  "documents": {
    "kid": str,
    "prospectus": str
  },
  "orderDepthLevels": [
    {
      "buySide": {
        "price": float,
        "priceString": str,
        "volume": int
      },
      "sellSide": {
        "price": float,
        "priceString": str,
        "volume": int
      }
    },
    ...
  ],
  "brokerTradeSummaries": [
    {
      "brokerCode": str,
      "sellVolume": int,
      "buyVolume": int,
      "netBuyVolume": int,
      "brokerName": str
    },
    ...
  ],
  "fee": {
    "totalMonetaryFee": float,
    "totalPercentageFee": float
  },
  "trades": [
    {
      "buyer": str,
      "buyerName": str,
      "seller": str,
      "dealTime": int,
      "price": float,
      "volume": int,
      "matchedOnMarket": bool,
      "cancelled": bool
    },
    ...
  ],
  "tradingUnit": int,
  "collateralValue": float,
  "introDate": str,
  "ordersAndDeals": {
    "orders": [],
    "deals": [],
    "hasStoplossOrders": bool,
    "accounts": [
      {
        "accountId": str,
        "accountName": str,
        "accountType": str
      },
      ...
    ]
  },
  "dividends": {
    "events": [],
    "pastEvents": [
      {
        "exDate": str,
        "paymentDate": str,
        "amount": float,
        "currencyCode": str,
        "dividendType": str
      },
      ...
    ]
  },
  "fundExposures": [
    {
      "orderbookId": str,
      "name": str,
      "exposure": float,
      "instrumentType": str,
      "countryCode": str,
      "hasPosition": bool
    },
    ...
  ],
  "riskScore": str,
  "holdingPeriod": str,
  "countryExposures": {
    "updated": str,
    "exposures": [
      {
        "countryCode": str,
        "countryName": str,
        "weight": float
      },
      ...
    ]
  },
  "sectorExposures": {
    "updated": str,
    "exposures": [
      {
        "sector": str,
        "weight": float
      },
      ...
    ]
  },
  "portfolioDate": str,
  "esgView": {
    "euArticleType": str
  },
  "superInterestApproved": bool
}