Giter Site home page Giter Site logo

nexapi's Introduction

NexAPI โ€“ N EXchanges API Library

NexAPI is a GO library that integrates official APIs from many well-known cryptocurrency exchanges.

Go Report Card License: MIT GitHub go.mod Go version Join Linsto Telegram

๐Ÿคทโ€ What is NexAPI?

The NexAPI library is a collection of APIs from many well-known cryptocurrency exchanges. It provides quick access to market data for storage, analysis, visualization, indicator development, algorithmic trading, strategy backtesting, bot programming, and related software engineering.

It is intended to be used by coders, developers, technically-skilled traders, data-scientists and financial analysts for building trading algorithms.

๐Ÿ”Ž Usage

Binance Example

Example 1: REST API

package main

import (
	"context"
	"encoding/json"
	"fmt"

	bnspotmd "github.com/linstohu/nexapi/binance/spot/marketdata"
	bnspottypes "github.com/linstohu/nexapi/binance/spot/marketdata/types"
	bnspotutils "github.com/linstohu/nexapi/binance/spot/utils"
)

func main() {
	cli, err := bnspotmd.NewSpotMarketDataClient(&bnspotutils.SpotClientCfg{
		Debug:   true,
		BaseURL: bnspotutils.BaseURL,
	})
	if err != nil {
		panic(err)
	}

	orderbook, err := cli.GetOrderbook(context.TODO(), bnspottypes.GetOrderbookParams{
		Symbol: "BTCUSDT",
		Limit:  5,
	})
	if err != nil {
		panic(err)
	}

	limit := orderbook.Http.ApiRes.Header.Get("X-Mbx-Used-Weight-1m")

	fmt.Printf("Current used request weight: %v\n", limit)

	bytes, err := json.MarshalIndent(orderbook.Body, "", "\t")
	if err != nil {
		panic(err)
	}

	fmt.Println(string(bytes))
}

Example 2: Websocket

package main

import (
	"fmt"
	"time"

	spotws "github.com/linstohu/nexapi/binance/spot/websocketmarket"
	"github.com/linstohu/nexapi/binance/spot/websocketmarket/types"
)

func main() {
	cli, err := spotws.NewSpotMarketStreamClient(&spotws.SpotMarketStreamCfg{
		Debug:         true,
		BaseURL:       spotws.SpotMarketStreamBaseURL,
		AutoReconnect: true,
	})
	if err != nil {
		panic(err)
	}

	err = cli.Open()
	if err != nil {
		panic(err)
	}

	topic, err := cli.GetAggTradeTopic("btcusdt")
	if err != nil {
		panic(err)
	}

	cli.AddListener(topic, func(e any) {
		trade, ok := e.(*types.AggregateTrade)
		if !ok {
			return
		}

		fmt.Printf("Topic: %s, Symbol: %v, Price: %v, Quantity: %v, Time: %v\n",
			topic, trade.Symbol, trade.Price, trade.Quantity, trade.EventTime)
	})

	cli.Subscribe([]string{topic})

	time.Sleep(20 * time.Second)

	cli.Close()

	select {}
}

โญ Give a Star!

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

nexapi's People

Contributors

linstohu avatar slangmens 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.