> For the complete documentation index, see [llms.txt](https://developer.switchmarket.se/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.switchmarket.se/getting-started/guides/market-operations.md).

# Market operations

This guide will show you how to use the Switch API to trade with flexibility products on the market.

To automate certain actions such as creating offers for availability orders, you can fetch and send data to specific endpoints of the Switch API.

{% hint style="info" %}
Trading also depends on real-time meter data, which you send as readings through the Metering API — see [How to send readings](/getting-started/guides/how-to-send-readings.md). The Metering API and the Switch API each need their own [API client](/getting-started/api-clients.md), so the client you use for readings cannot be reused for the steps below.
{% endhint %}

## 1. Getting Started

First of all, you'll need to be set up and accustomed to working with the [Switch API](/switch-api/overview.md). Next you need to create an [API client](/getting-started/api-clients.md) with the **Switch API** audience and note the client ID and secret, since you will need them further on.

## 2. Get Access Token

In order to be able to fetch or send market data, you first need a valid access token that will be used to authorize your request to the Switch API.

Use the client ID and client secret you noted to fetch a token, following the [Client Credentials Flow](/getting-started/client-credentials-flow.md). The token URL and the audience for the environment you are working against are on [Authentication](/switch-api/authentication.md).

When you have your access token ready, proceed with the next step.

## 3. Get Resource Information

You can use the [Get resources](/switch-api/api-reference/test/resource.md#get-api-grid-resource) endpoint to find information about the resources available in your organization. The ID of a specific resource is needed to fetch availability orders and create offers. It's also possible to view the resource information in the Switch app, as described in the [Concepts](/getting-started/concepts.md#less-than-resourceid-greater-than) section.

If a resource has forecasted demand notifications enabled, you can use the [Get resource forecasted demands](/switch-api/api-reference/test/product.md#get-api-product-resource-resourceid-forecasted-demands) endpoint to check whether a breach has been forecasted for its substation — useful if you want to factor that into your own trading logic before creating offers.

See also the user guide description: [Forecasted demand](https://user.switchmarket.se/english/flexibility-provider-fsp/forecasted-demand)

## 4. Get Availability Orders

For the products "Tillgänglighetsordrar" (`productType LfmA`) and "Direktordrar" (`productType LfmD`), the markets use availability orders to request quantities of potential flexibility that may be activated for delivery. Once availability orders are cleared on the market (at expiry), any accepted offer will lead to awarded availability and corresponding flexibility orders being created by Switch.

You need to use a resource ID in your API request to fetch availability orders with the [Get resource availability orders endpoint](/switch-api/api-reference/test/product.md#get-api-product-order-availability-resource-resourceid). This ensures that the correct availability quantity and price is calculated for that specific resource (including impact factor\*), which can be used to create corresponding offers on the market. For each availability order you will also get an ID which must be provided in the create offer POST request.

\*For each availability order and resource pairing, there's a configured impact factor towards the electrical grid. It's a value between 0 and 1 (e.g. 0.62) that indicates the percentage of power that will impact the grid when a resource delivers flexibility. The factor is applied on quantity (lower impact = higher quantity needed to fulfill demand) and price (higher impact = higher availability remuneration).

## 5. Create Availability Offers

When creating offers with the [Create availability offers endpoint](/switch-api/api-reference/test/product.md#post-api-product-offer-availability-resource-resourceid) you need to specify availability order ID, quantity and activation price, i.e. what you want to be paid in addition to the availability price. This must be done before order expiry and market clearing:

* D-2 10:00 for "Tillgänglighetsordrar"
* D-1 09:00 for "Direktordrar DayAhead"
* H-3 for "Direktordrar IntraDay"

Before clearing occurs it's also possible to either update an existing offer or remove it entirely by using the [Update availability offers](/switch-api/api-reference/test/product.md#put-api-product-offer-availability-resource-resourceid) and [Delete availability offers](/switch-api/api-reference/test/product.md#delete-api-product-offer-availability-resource-resourceid) endpoints, respectively.

{% hint style="info" %}
**Market rules for trading**

* Minimum allowed quantity is 0,1 MW
* Quantity resolution is 0,01 MW (10 kW)
* Quantity can be set as a range (e.g. min 0,1 MW and max 1 MW) or fixed (e.g. min 1 MW and max 1 MW), specified in the base unit of W
* Prices are in SEK and per MWh
* Reference data valid for all hours where flexibility may be delivered must be [uploaded](/switch-api/api-reference/test/resource.md#post-api-grid-resource-resourceid-readings-reference) no later than
  * 09:30 D-1 for "Tillgänglighetsordrar" and "Direktordrar DayAhead"
  * H-4 for "Direktordrar IntraDay"
* Real-time resource meter data must be [sent as readings](/getting-started/guides/how-to-send-readings.md) for all hours where flexibility may be delivered
  {% endhint %}

## 6. Get Availability Transactions

If you want to see awarded availability quantities, i.e. what offers were accepted on the market, you can use the [Get availability transactions endpoint](/switch-api/api-reference/test/product.md#get-api-product-transaction-availability) to fetch the transactions related to an availability order. Data is available D-2 10:30 at the latest for "Tillgänglighetsordrar" and D-1 09:30 for "Direktordrar DayAhead". Most of the information such as quantity and delivery time period will be duplicated in a corresponding flexibility order, created by Switch.

## 7. Get Flexibility Transactions

If you want to see activated quantities, i.e. what you need to deliver with your flexibility resources, you can use the [Get flexibility transactions endpoint](/switch-api/api-reference/test/product.md#get-api-product-transaction-flexibility) to fetch the transactions related to a flexibility order. Data is available D-1 10:35 at the latest for day-ahead activation. Note that if no transaction data is returned, you can assume that no delivery of flexibility is expected.
