meburgess / CoinSpotDotNet

CoinSpot API Wrapper for .NET Standard 2.0

Home Page:https://docs.lilypod.tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CoinSpotDotNet

Nuget Badge License: MIT

A .NET Standard 2.0 compatible class library for CoinSpot API. Supports API versions 1 and 2

Contents

Features

  • Well documented with a full suite of examples
  • .NET Standard 2.0 target
  • No 3rd-party dependencies (no Newtonsoft.Json, this library uses the System.Text.Json serialiser out of the box), only Microsoft and System namespaced dependecies required
  • Supports both Console and ASP.NET web application scenarios, and probably loads of others.
  • Modern fully async C# library
  • Currently supports CoinSpot all public and read-only API v1 and API v2 (beta) endpoints:
  • Write endpoints are currently not implemented but planned for 1.3.0 release

Documentation

This source code has been documented extensively and the full API documentation is a available here.

Additionally a Demo project is included in this repo and contains Swagger/Open API documentation for all of the supported CoinSpot API endpoints that you can easily set up and try out CoinSpotDotNet

Demo

There is a Sample ASP.NET Web API project with a swagger you can use to test out the library and as a usage example.

Demo setup instructions

  1. Clone the project
    git clone https://github.com/liamwhan/CoinSpotDotNet
  2. Add your CoinSpot read-only API key and secret as a user secret with the dotnet CLI
    cd CoinSpotDotNet/CoinSpotDotNet.Samples
    dotnet user-secrets init
    dotnet user-secrets set "CoinSpot:ReadOnlyKey" "{YOUR_READ_ONLY_KEY}"
    dotnet user-secrets set "CoinSpot:ReadOnlySecret" "{YOUR_READ_ONLY_SECRET}"
  3. Open the solution in Visual Studio and start debugging the CoinSpotDotNet.Samples project
  4. Start debugging/run the project and open a browser to http://localhost:5000/swagger/index.html

Getting Started

Installation

Nuget

Install-Package CoinSpotDotNet -Version 1.0.5

dotnet CLI

dotnet add package CoinSpotDotNet --version 1.0.5

Usage

ASP.NET Web Application

NOTE: Both V1 and V2 clients are used side-by-side in the examples below to demonstrate usage, while this won't cause any problems, in practice you would probably only want one or the other.

If you're building an ASP.NET Web application then getting started is as simple as:

  1. Add your CoinSpot API credentials to the applications IConfiguration under the section CoinSpot

    This can be done in any way you like, (i.e. User secrets, secure storage etc.) but we recommend you read up on safe storage of secrets in ASP.NET

    For example, here is what the credentials would look like in an appsettings.json file (which we don't recommend, but are using here to demonstrate the structure that CoinSpotDotNet expects):

     {
         "CoinSpot": 
         {
             "ReadOnlyKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
             "ReadOnlySecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
         }
     }
  2. Register CoinSpotDotNet in the .NET DI Container. Example Startup.cs class

     using CoinSpotDotNet;
    
     namespace MyProject 
     {
         public class Startup 
         {
             public IConfiguration Configuration { get; set; }
             
             public Startup(IConfiguration config)
             {
                 Configuration = config;
             }
    
             public void ConfigureServices(IServiceCollection services)
             {
                 // ... Standard .NET service setup
                 services.AddCoinSpotV1(Configuration); // Registers ICoinSpotClient for CoinSpot v1 API;
                 services.AddCoinSpotV2(Configuration); // Registers ICoinSpotClientV2 for CoinSpot v2 API;
    
             }
         }
     }

    This will register a typed HttpClient into the DI Container. See the CoinSpotClient DI constructor API documentation for more information.

  3. Inject ICoinSpotClient or ICoinSpotClientV2 into your consuming services.

     using CoinSpotDotNet;
     namespace MyProject.Services 
     {
    
         public class MyService 
         {
             private readonly ICoinSpotClient clientV1;
             private readonly ICoinSpotClientV2 clientV2;
    
             public MyService(ICoinSpotClient clientV1, ICoinSpotClientV2 clientV2)
             {
                 this.clientV1 = clientV1;
                 this.clientV2 = clientV2;
             }
    
             public async Task MyMethod()
             {
                 var balancesV1 = await clientV1.ListMyBalances();
                 var balancesV2 = await clientV2.ListMyBalances();
    
             }
         }
    
     }

Console applications and other scenarios

If you're not using ASP.NET then constructing a Client is arguably even simpler:

using CoinSpotDotNet;

namespace MyConsoleApp 
{

    public class Program
    {
        public static Main(string[] args)
        {
            CoinSpotSettings settings = new()
            {
                ReadOnlyKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                ReadOnlySecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            };
            var clientV1 = new CoinSpotClient(settings);
            var clientV2 = new CoinSpotClientV2(settings);
        }
    }

}

General Notes

API Support

The current CoinSpot API documentation and developer tools are limited and this library is not officially supported by, or affiliated with CoinSpot in any way. This makes some parts of the API very difficult to test, especially where my personal account does not have any data to test with, e.g. the affiliate and referral payments endpoints. As a result this library currently only supports:

CoinSpotClient classes

CoinSpotDotNet exposes 2 primary classes of interest to consuming applications:

  • ICoinSpotClient - calls CoinSpot API v1 endpoints
  • ICoinSpotClientV2 - calls CoinSpot API v2 endpoints

They are independent classes and can be used interchangably and they expose mostly the same methods at the moment (the v2 API has more endpoints so the client has more corresponding methods).

Dependencies

The target framework is .NET Standard 2.0 and the only dependencies are Microsoft .NET libraries. There are no 3rd-party dependencies.

You can use this library in a console app (or other non-ASP environment) by using the simple constructor

License

MIT License

Copyright (c) 2021 Liam Whan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

CoinSpot API Wrapper for .NET Standard 2.0

https://docs.lilypod.tools


Languages

Language:HTML 70.2%Language:CSS 11.0%Language:C# 9.4%Language:JavaScript 9.3%Language:Batchfile 0.0%