{% macro order_tr(order, type='', timestamp='', sim_or_real='Simulated') -%}
    <tr>
        <td scope="row">
            {% if sim_or_real == 'Simulated' %}
                {{ sim_or_real }}
            {% else %}
                {% if order.order_id is none %}
                    {{ sim_or_real }} (virtual)
                {% else %}
                    {{ sim_or_real }} ({{ order.order_id }})
                {% endif %}
            {% endif %}
        </td>
        <td>{{ timestamp }}</td>
        <td>{{ order.get_exchange().get_name() }}</td>
        <td>{{ order.get_order_symbol() }}</td>
        <td class="text-center">{{ type }}</td>
        <td>{{ order.get_origin_price() }}</td>
        <td>{{ order.get_origin_quantity() }}</td>
        <td class="text-right">{{ order.get_origin_price() * order.get_origin_quantity() | round(8) }}  {{ order.market }}</td>
        <td class="text-center py-1">
            <button type="button" class="btn btn-sm btn-outline-danger waves-effect" action="cancel_order" order_desc="{{ order.get_description() }}" update-url="{{ url_for('api.orders', action='cancel_order') }}"><i class="fas fa-ban"></i></button>
        </td>
    </tr>
{%- endmacro %}

{% macro trades_tr(trade, type='', timestamp='', sim_or_real='Simulated') -%}
    <tr>
        <td scope="row">
            {% if sim_or_real == 'Simulated' %}
                {{ sim_or_real }}
            {% else %}
                {% if trade.order_id is none %}
                    {{ sim_or_real }} (virtual)
                {% else %}
                    {{ sim_or_real }} ({{ trade.order_id }})
                {% endif %}
            {% endif %}
        </td>
        <td>{{ trade.exchange.get_name() }}</td>
        <td>{{ trade.symbol }}</td>
        <td class="text-center">{{ type }}</td>
        <td>{{ trade.price }}</td>
        <td>{{ trade.quantity }}</td>
        <td class="text-right">{{ trade.cost }} {{ trade.market }}</td>
        <td class="text-right">{{ trade.fee['cost'] }} {{ trade.fee['currency'] }}</td>
        <td class="text-right">{{ timestamp }}</td>
    </tr>
{%- endmacro %}

{% macro logs_tr(log) -%}
    <tr
    {% if "ERROR" in log["Level"] %}
        class="bg-danger"
    {% endif %}
    {% if "WARNING" in log["Level"] %}
        class="bg-warning-dark"
    {% endif %}
    >
        <td scope="row">{{ log["Time"] }}</td>
        <td>{{ log["Level"] }}</td>
        <td>{{ log["Source"] }}</td>
        <td>{{ log["Message"] }}</td>
    </tr>
{%- endmacro %}

{% macro top_tr(item) -%}
    <tr
    {% if item["rank"] == 1 %}
        class="unique-color-dark"
    {% elif item["rank"] == 2 %}
        class="unique-color"
    {% elif item["rank"] == 3 %}
        class="special-color"
    {% endif %}
    >
        <td scope="row">{{ item["rank"] }}</td>
        <td class="text-capitalize">{{ item["name"] }}</td>
        <td>{{ item["count"] }}</td>
    </tr>
{%- endmacro %}