Skip to content

Commit

Permalink
Add new endpoint for current values (w/o round id)
Browse files Browse the repository at this point in the history
  • Loading branch information
adg-flare committed Jun 7, 2024
1 parent b564787 commit 60d2e09
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,57 @@ However, for testing it can be configured to return a fixed or random values by
Starting provider:
```
docker run --rm -it --publish "0.0.0.0:3101:3101" ghcr.io/flare-foundation/ftso-v2-example-value-provider
```

## Obtaining feed values

There are two API endpoints: `/feed-values/<votingRound>` and `/feed-values/`, to be used by FTSO Scaling data provider and Fast Updates client respectively. In this (basic) example implementation, however, both endpoints map to the same service logic and return the latest feed values.

## Sample usage

Feed values for voting round id:
```bash
curl -X 'POST' \
'http://localhost:3101/feed-values/0' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"feeds": [
{ "category": 1, "name" : "BTC/USD" }
]
}'
```

Response:
```json
{
"votingRoundId": 0,
"data": [
{ "feed": { "category": 1, "name": "BTC/USD" }, "value": 71287.34508311428 }
]
}

```
---
Current values:
```bash
curl -X 'POST' \
'http://localhost:3101/feed-values/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"feeds": [
{ "category": 1, "name" : "BTC/USD" }
]
}'
```

Response:
```json
{
"data": [
{ "feed": { "category": 1, "name": "BTC/USD" }, "value": 71285.74004472858 }
]
}

```
13 changes: 11 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Param, ParseIntPipe, Post, Inject, Logger } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { ExampleProviderService } from "./app.service";
import { FeedValuesRequest, FeedValuesResponse } from "./dto/provider-requests.dto";
import { FeedValuesRequest, FeedValuesResponse, RoundFeedValuesResponse } from "./dto/provider-requests.dto";

@ApiTags("Feed Value Provider API")
@Controller()
Expand All @@ -13,12 +13,21 @@ export class ExampleProviderController {
async getFeedValues(
@Param("votingRoundId", ParseIntPipe) votingRoundId: number,
@Body() body: FeedValuesRequest
): Promise<FeedValuesResponse> {
): Promise<RoundFeedValuesResponse> {
const values = await this.providerService.getValues(body.feeds);
this.logger.log(`Feed values for voting round ${votingRoundId}: ${JSON.stringify(values)}`);
return {
votingRoundId,
data: values,
};
}

@Post("feed-values/")
async getCurrentFeedValues(@Body() body: FeedValuesRequest): Promise<FeedValuesResponse> {
const values = await this.providerService.getValues(body.feeds);
this.logger.log(`Current feed values: ${JSON.stringify(values)}`);
return {
data: values,
};
}
}
6 changes: 5 additions & 1 deletion src/dto/provider-requests.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class FeedValueData {
value: number;
}

export class FeedValuesResponse {
export class RoundFeedValuesResponse {
votingRoundId: number;
data: FeedValueData[];
}

export class FeedValuesResponse {
data: FeedValueData[];
}

0 comments on commit 60d2e09

Please sign in to comment.