Giter Site home page Giter Site logo

andreyleskov / api-gatecoin-dotnet Goto Github PK

View Code? Open in Web Editor NEW
4.0 5.0 8.0 159 KB

api-gatecoin-dotnet is a library for accessing the HTTP REST API of Gatecoin using C# or other .NET languages

Home Page: https://gatecoin.com/api

License: MIT License

C# 98.78% Shell 1.22%
gatecoin api-gatecoin-dotnet

api-gatecoin-dotnet's Introduction

API Client CSharp

GatecoinServiceInterface is a toolkit for accessing the Http API, in C#

It can be installed as a nuget package from https://gds.myget.org/feed/public/package/nuget/api-gatecoin-dotnet

Usage example:

using System;
using System.Linq;

using GatecoinServiceInterface.Client;
using GatecoinServiceInterface.Model;
using GatecoinServiceInterface.Response;
using GatecoinServiceInterface.Request;

namespace GatecoinApiClientExample
{
    class Program
    {
        static void Main(string[] args)
        {
            const string publicApiKey = "PUBLIC_API_KEY";
            const string privateApiKey = "PRIVATE_API_KEY";

            var GatecoinClient = new ServiceClient();
            GatecoinClient.SetApiKey(publicApiKey, privateApiKey);

            var balances = GatecoinClient.Get<BalancesResponse>("/Balance/Balances").Balances;
            var availableHkdBalance = 
                balances.SingleOrDefault(b => b.Currency == "HKD").AvailableBalance;

            var buyBtcOrder = new AddOrder()
            {
                Code = "BTCHKD",
                Way = "Bid",
                Amount = 0.25m,
                Price = 50000m,
            };

            var placedOrderId = GatecoinClient.Post<AddOrderResponse>("/Trade/Orders/", buyBtcOrder).ClOrderId;
            Console.WriteLine($"Sucessfully created Order {placedOrderId}");

            var cancelOrder = GatecoinClient.Delete<CommonResponse>($"/Trade/Orders/{placedOrderId}");
            if (cancelOrder.ResponseStatus.Message == "OK") 
            {
                Console.WriteLine($"Sucessfully cancelled order {placedOrderId}");
            }
        }
    }
}

API Streaming client

This is a set of classes that enables clients to use public websocket Gatecoin channels.

Using currency pairs, the client can subscribe to special events from Gatecoin exchange. Events are defined by the following DTO data types:

  • TraderDto
  • TickerDto
  • MarketDepthDto

For a description of each DTO and the fields they include please refer to our Official API and Streaming documentation.

To subscribe to all events, the SubscribeAll method should be invoked.
To unsubscribe from all events the Dispose method should be invoked.

public static async Task Start()
{
    var builder = new StreamingClientBuilder("https://streaming.gatecoin.com");

    using (var client = await builder.BuildTraderClient().Start())
    {
        void TradeHandler(TradeDto arg) => Console.WriteLine(JsonConvert.SerializeObject(arg));

        var subscription = client.SubscribeAll(TradeHandler);
        var subscriptionBtcUsd = client.Subscribe("BTCUSD", TradeHandler);

        Console.WriteLine("Waiting for events");
        Console.ReadLine();

        subscription.Dispose();
        subscriptionBtcUsd.Dispose();
    }
}

api-gatecoin-dotnet's People

Contributors

a-gtc avatar andreyleskov avatar dmdv avatar knocte avatar meebey avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.