An open API service indexing awesome lists of open source software.

https://github.com/ninjastacktech/opensea-net

.NET 6 C# SDK for the OpenSea marketplace.
https://github.com/ninjastacktech/opensea-net

csharp httpclient net6 opensea sdk

Last synced: 5 months ago
JSON representation

.NET 6 C# SDK for the OpenSea marketplace.

Awesome Lists containing this project

README

          


---
[![NuGet](https://img.shields.io/nuget/v/OpenSeaClient)](https://www.nuget.org/packages/OpenSeaClient/)
[![GitHub](https://img.shields.io/github/license/ninjastacktech/opensea-net)](https://github.com/ninjastacktech/opensea-net/blob/master/LICENSE)

.NET 6 C# SDK for the OpenSea marketplace API.

The API docs can be found here: https://docs.opensea.io/reference/api-overview

Demo API swagger: https://ninja-opensea.azurewebsites.net/swagger/index.html

# install
```xml
PM> Install-Package OpenSeaClient -Version 1.0.7
```
# snippets

### DI configuration:
```C#
builder.Services.AddHttpClient(config =>
{
config.DefaultRequestHeaders.Add("X-Api-Key", "");
});
```

### Get assets in batches of 50 with 1s delay between API calls to avoid throttling:
```C#
var client = new OpenSeaHttpClient(apiKey: "");

var queryParams = new GetAssetsQueryParams
{
CollectionSlug = collectionSlug,
};
var count = 0;
var limit = 50;
var it = 0;

var assetsList = new List();

do
{
queryParams.Offset = limit * it;
queryParams.Limit = limit;

var assets = await client.GetAssetsAsync(queryParams);

if (assets != null)
{
if (assets.Count > 0)
{
assetsList.AddRange(assets);
}
}
else
{
break;
}

await Task.Delay(1000);
}
while (count == 50);
```

### Get the price of a token's sale order:
Note that the listing price of an asset is equal to the currentPrice of the lowest valid sell order on the asset.
Users can lower their listing price without invalidating previous sell orders, so all get shipped down until they're canceled, or one is fulfilled.
```C#
var client = new OpenSeaHttpClient(apiKey: "");

var orders = await client.GetOrdersAsync(new GetOrdersQueryParams
{
AssetContractAddress = contractAddress,
TokenId = tokenId,
Side = 1,
SaleKind = 0,
});

if (orders?.Any() == true)
{
var order = orders.Where(x => x.Cancelled == false).OrderBy(x => x.CurrentPriceEth).FirstOrDefault();

if (order != null)
{
Console.WriteLine($"Token {tokenId} has a sell order of {order.CurrentPriceEth} ETH");
}
}
```

---

### MIT License