Skip to content

Commit

Permalink
Updated webapi project and readme document
Browse files Browse the repository at this point in the history
  • Loading branch information
ernitingarg committed Oct 10, 2022
1 parent 9f2dc5d commit 08bc9fc
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Overview

This project has a console application [also a web api, mentioned below] written in c# which connects to the `Uniswap API v3` and collects the liquidity positions
of both the cryptocurrencies of a user defined liquidity pool.

Below are the information it fetches and shows them on console (in addition to writting them in log files).

- Position of token0 (USDC in this example)
- Position of token1 (ETH in this example)
- Current price of token0:token1 (USDC per ETH in this example)

Example: Lets say, you want to fetch the below highlighted information for pool id [245953](https://app.uniswap.org/#/pool/245953).

![Uniswap Interface](./images/245953.png)

Run the application and here is the output information fetched from `Uniswap API v3`.

![Console output](./images/output.png)

**Note:**
- You can set the pool id, precisions and also the interval after which the application should fetch the information from `Uniswap API v3`.

```
# app.config
<appSettings>
<add key="PoolId" value="245953" />
<add key="PrecisionForPosition0" value="3" />
<add key="PrecisionForPosition1" value="6" />
<add key="PrecisionForCurrentPrice" value="2" />
<add key="IntervalInSeconds" value="60" />
</appSettings>
```
- You can also control the output by customizing configuration in `log4net.config`. (eg.: change the log directory, pattern, rolling style etc.)

```
# log4net.config
<root>
<level value="ALL" />
<!--<appender-ref ref="console" />-->
<appender-ref ref="file" />
</root>
```
- When network is disconnected/fluctuated, It retries in a smart way which automatically calculates the number of retries to be done exponentially based on `IntervalInSeconds` provided
in `app.config`. For example: for a given interval 60 seconds, lets say first trigger is at `10:30`. If Uniswap API can not be connected, then there will be maximum 4 retries (auto calculated).
- First retry will be done after 5 seconds `[10:30:05]`
- 2nd retry will be done after 10 seconds `[10:30:15]`
- 3rd retry will be done after 15 seconds `[10:30:30]`
- 4th retry will be done after 20 seconds `[10:30:50]`
- If API still can not be connected, then send error `Unable to retrieve the data from server after 4 retries.`
- A new timer will be triggered at `[10:31:00]`.

- There is also an webapi project, which exposes endpoint `positions` to allow you fetch the same information. Please check [demo](https://uniswap-v3.vercel.app/positions/245953) url.

![API output](./images/api.png)

**Note:**
- Format of api is `positions/<pool_id>/<token0_precision>/<token1_precision>/<currentprice_precision>`. Few examples:
- https://uniswap-v3.vercel.app/positions/245953 => Shows the information with no truncation.
- https://uniswap-v3.vercel.app/positions/245953/3 => Truncates only token0 position with 3 decimal precision
- https://uniswap-v3.vercel.app/positions/245953/3/6 => Truncates token0 position with 3 decimal precisions and token1 position with 6 precision.
- https://uniswap-v3.vercel.app/positions/245953/null/null/2 => Truncate only current price with 2 decimal precision.
6 changes: 3 additions & 3 deletions Uniswap.Client/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<appSettings>
<add key="PoolId" value="245953" />
<add key="PrecisionForPosition0" value="5" />
<add key="PrecisionForPosition1" value="3" />
<add key="PrecisionForCurrentPrice" value="9" />
<add key="PrecisionForPosition0" value="3" />
<add key="PrecisionForPosition1" value="5" />
<add key="PrecisionForCurrentPrice" value="2" />
<add key="IntervalInSeconds" value="60" />
</appSettings>

Expand Down
2 changes: 1 addition & 1 deletion Uniswap.Client/log4net.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="console" />
<!--<appender-ref ref="console" />-->
<appender-ref ref="file" />
</root>
<appender name="console" type="log4net.Appender.ConsoleAppender">
Expand Down
16 changes: 10 additions & 6 deletions Uniswap.WebApi/Controllers/PositionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@ public PositionsController()
}

[HttpGet]
[Route("positions/{id}/{precision0?}/{precision1?}")]
[Route("positions/{id}/{precision0?}/{precision1?}/{precisionForCurrentPrice?}")]
public async Task<IHttpActionResult> GetPosition(
int id,
int? precision0 = null,
int? precision1 = null)
int? precision1 = null,
int? precisionForCurrentPrice = null)
{
var result = await _uniswapGraphQl.GetLiquidityPosition(
id,
3,
precision0,
precision1);
precision1,
precisionForCurrentPrice);

var ret = new
{
Token0 = new
{
result.Position.Token0.Symbol,
Amount = result.Position.Amount0
Amount = result.Position.Position0Amount
},
Token1 = new
{
result.Position.Token1.Symbol,
Amount = result.Position.Amount1
}
Amount = result.Position.Position1Amount
},
CurrentPrice = result.Position.Price0Amount
};

return Ok(ret);
Expand Down
Binary file added images/245953.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 08bc9fc

@vercel
Copy link

@vercel vercel bot commented on 08bc9fc Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.