Skip to content

Commit

Permalink
Update with usage instructions
Browse files Browse the repository at this point in the history
Signed-off-by: camille-bouvy-frequenz <camille.bouvy@frequenz.com>
  • Loading branch information
camille-bouvy-frequenz committed Aug 15, 2024
1 parent f9435b8 commit 8a03f1a
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
## Introduction

Electricity Trading API client for Python
The Frequenz Electricity Trading API client for Python is an easy-to-use Python interface built to interact with the Frequenz Electricity Trading API. It allows you to create orders, get market data, and manage your orders.

## Features
* **Create and manage gridpool orders**: Place new orders, update existing ones, and cancel orders when necessary.
* **Stream live data**: Get real-time updates on market data, including order books, trades, and market prices.
* **Retrieve historical data**: Access historical data on market trades.

## Supported Platforms

Expand All @@ -16,6 +22,101 @@ The following platforms are officially supported (tested):
- **Operating System:** Ubuntu Linux 20.04
- **Architectures:** amd64, arm64

## Usage

### Installation

You can install the Frequenz Electricity Trading API client via pip. Replace `VERSION` with the specific version you wish to install.

```
# Choose the version you want to install
VERSION=0.1.0
pip install frequenz-client-electricity-trading==$VERSION
```

### Initialization

First, initialize the client with the appropriate server URL and API key.
```python
from frequenz.client.electricity_trading import Client

# Change server address if needed
SERVICE_URL = "electricity-trading-testing.api.frequenz.com:443"
API_KEY = open('api_key.txt').read().strip()
client = Client(
server_url=SERVICE_URL,
auth_key=API_KEY
)
```

### Create an Order

Here's an example of how one can create a limit order to buy energy.
```python
from frequenz.client.electricity_trading import (
Currency,
DeliveryArea,
DeliveryPeriod,
Energy,
EnergyMarketCodeType,
MarketSide,
OrderType,
Price,
)
from datetime import datetime, timedelta
from decimal import Decimal

# Define order parameters
gridpool_id = 1
delivery_area = DeliveryArea(
code="10YDE-EON------1", # TenneT
code_type=EnergyMarketCodeType.EUROPE_EIC
)
delivery_period = DeliveryPeriod(
start=datetime.fromisoformat("2024-05-01T00:00:00"),
duration=datetime.timedelta(minutes=15)
)
price = Price(amount=Decimal("50.0"), currency=Currency.EUR)
quantity = Energy(mwh=Decimal("0.1"))
order = await client.create_gridpool_order(
gridpool_id=gridpool_id,
delivery_area=delivery_area,
delivery_period=delivery_period,
order_type=OrderType.LIMIT,
side=MarketSide.BUY,
price=quantity,
quantity=quantity,
)
```

### List Orders for a Gridpool

Orders for a given gridpool can be listed using various filters.

```python
from frequenz.client.electricity_trading import MarketSide

# List all orders for a given gridpool
orders = await self._client.list_gridpool_orders(
gridpool_id=gridpool_id,
)

# List only the buy orders for a given gridpool
buy_orders = await self._client.list_gridpool_orders(
gridpool_id=gridpool_id,
side=MarketSide.BUY,
)
```

### Streaming Public Trades

To get real-time updates on market trades, one can use the following code snippet.

```python
async for order_detail in client.stream_public_trades():
print(f"Received public trade trade: {order_detail}")
```

## Contributing

If you want to know how to build this project and contribute to it, please
Expand Down

0 comments on commit 8a03f1a

Please sign in to comment.