"""Bundled dashboard: markets."""
import json


def register(ctx):
    from dashboard_bundled.feeds import feed_stocks

    ctx.register_dashboard_tile(
        {
            "id": "markets",
            "title": "Markets",
            "path": "/tile",
            "refresh_seconds": 300,
            "priority": 5,
        }
    )

    def route_handler(req):
        body = json.dumps(feed_stocks(), ensure_ascii=False)
        return {
            "status": 200,
            "headers": {"Content-Type": "application/json; charset=utf-8"},
            "body": body,
        }

    ctx.register_route_handler(route_handler)
