Golang API wrapper of OkEX

okex

Go Reference GitHub go.mod Go version of a Go module GoReportCard example GitHub license GitHub release PRs Welcome CI CodeQL AutoRelease

NOTICE:

PACKAGE IS CURRENTLY UNDER HEAVY DEVELOPMENT AND THERE IS NO GUARANTY FOR STABILITY UNTIL V1 RELEASE.

Okex V5 Golang API

A complete golang wrapper for Okex V5 API. Pretty simple and easy to use. For more info about Okex V5 API read here.

Installation

go get github.com/amir-the-h/[email protected]

Usage

package main

import (
	"context"
	"github.com/amir-the-h/okex"
	"github.com/amir-the-h/okex/api"
	"github.com/amir-the-h/okex/events"
	"github.com/amir-the-h/okex/events/private"
	ws_private_requests "github.com/amir-the-h/okex/requests/ws/private"
	ws_public_requests "github.com/amir-the-h/okex/requests/ws/public"
	"log"
)

func main() {
	apiKey := "YOUR-API-KEY"
	secretKey := "YOUR-SECRET-KEY"
	passphrase := "YOUR-PASS-PHRASE"
	dest := okex.NormalServer // The main API server
	ctx := context.Background()
	client, err := api.NewClient(ctx, apiKey, secretKey, passphrase, &dest)
	if err != nil {
		log.Fatalln(err)
	}

	response, err := client.Rest.Account.GetConfig()
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("Account Config %+v", response)

	errChan := make(chan *events.Error)
	subChan := make(chan *events.Subscribe)
	uSubChan := make(chan *events.Unsubscribe)
	lCh := make(chan *events.Login)
	oCh := make(chan *private.Order)
	iCh := make(chan *public.Instruments)

	// to receive unique events individually in separated channels
	client.Ws.SetChannels(errChan, subChan, uSubChan, lCh)

	// subscribe into orders private channel
	// it will do the login process and wait until authorization confirmed
	err = client.Ws.Private.Order(ws_private_requests.Order{
		InstType: okex.SwapInstrument,
	}, oCh)
	if err != nil {
		log.Fatalln(err)
	}

	// subscribe into instruments public channel
	// it doesn't need any authorization
	err = client.Ws.Public.Instruments(ws_public_requests.Instruments{
		InstType: okex.SwapInstrument,
	}, iCh)
	if err != nil {
		log.Fatalln("Instruments", err)
	}

	// starting on listening 
	for {
		select {
		case <-lCh:
			log.Print("[Authorized]")
		case sub := <-subChan:
			channel, _ := sub.Arg.Get("channel")
			log.Printf("[Subscribed]\t%s", channel)
		case uSub := <-uSubChan:
			channel, _ := uSub.Arg.Get("channel")
			log.Printf("[Unsubscribed]\t%s", channel)
		case err := <-client.Ws.ErrChan:
			log.Printf("[Error]\t%+v", err)
		case o := <-oCh:
			log.Print("[Event]\tOrder")
			for _, p := range o.Orders {
				log.Printf("\t%+v", p)
			}
		case i := <-iCh:
			log.Print("[Event]\tInstrument")
			for _, p := range i.Instruments {
				log.Printf("\t%+v", p)
			}
		case e := <-client.Ws.StructuredEventChan:
			log.Printf("[Event] STRUCTED:\t%+v", e)
			v := reflect.TypeOf(e)
			switch v {
			case reflect.TypeOf(events.Error{}):
				log.Printf("[Error] STRUCTED:\t%+v", e)
			case reflect.TypeOf(events.Subscribe{}):
				log.Printf("[Subscribed] STRUCTED:\t%+v", e)
			case reflect.TypeOf(events.Unsubscribe{}):
				log.Printf("[Unsubscribed] STRUCTED:\t%+v", e)
			}
		case e := <-client.Ws.RawEventChan:
			log.Printf("[Event] RAW:\t%+v", e)
		case b := <-client.Ws.DoneChan:
			log.Printf("[End]:\t%v", b)
			return
		}
	}
}

Supporting APIs

Features

  • All requests, responses, and events are well typed and will convert into the language built-in types instead of using API's strings. Note that zero values will be replaced with non-existing data.
  • Fully automated authorization steps for both REST and WS
  • To receive websocket events you can choose RawEventChan , StructuredEventChan, or provide your own channels. More info
Owner
Amir
A person who converts teas into the codes. Technology lover, Former PHP expert, Golang hunger.
Amir
Comments
  • WS orderBook method does not return data

    WS orderBook method does not return data

    from v1.0.7-alpha version stopped receiving orderBook via web socket up to v1.0.6-alpha version inclusive method client.Ws.Public.OrderBook(reqWS, obCh) returns data to the channel so far I haven't looked deeper, maybe I'm doing something wrong

  • [BUG] Wrong json field value in public market API

    [BUG] Wrong json field value in public market API

    Describe the bug I can't fetch tickers because of wrong JSON field declaration

    To Reproduce Steps to reproduce the behavior:

    1. I took your readme example
    2. I wrote some go code
    client.Rest.Market = rest.NewMarket(client.Rest)
    
    getSwapTickers := market.GetTickers{
    	InstType: okex.SwapInstrument,
    }
    swapTickers, err := client.Rest.Market.GetTickers(getSwapTickers)
    if err != nil {
    	log.Fatalln(err)
    }
    
    1. I saw the error json: invalid use of ,string struct tag, trying to unmarshal "SWAP" into okex.InstrumentType

    Additional information Actually I have fixed it already, so it's just representative issue to make a PR

  • When the method is post, the data can definitely be passed in

    When the method is post, the data can definitely be passed in

    If it is an array, this can only go back to the first data(https://github.com/amir-the-h/okex/blob/eb593335af79923723db716bf2d76b92ba4fdcf6/api/rest/client.go#L81) If it is an array, okex.S2M(req) will also be empty when parsing

  • nil pointer dereference

    nil pointer dereference

    Hello @amir-the-h! /github.com/amir-the-h/[email protected]/api/ws/client.go:238

    conn, res, err := websocket.DefaultDialer.Dial(string(c.url[p]), nil) defer res.Body.Close()

    panic: runtime error: invalid memory address or nil pointer dereference

    Can this problem be caused due to res nil? Thanks!

  • Place Order Error

    Place Order Error

    @amir-the-h i am unable to place the order. in response of Place order function i found below error with status 50101 Msg:Broker id of APIKey does not match current environment. check API key and secret the value of Key and secret is correct. Important Point I am using testmod of API.

  • Duplicated Mutex

    Duplicated Mutex

    Hi, why we need two mutex mu and rmu? if mu stand for write lock and rmu stand for read lock, why don't we simply use one single sync.RWMutex instead?

  • fix:placeOrder struct field

    fix:placeOrder struct field

  • [BUG] GetOrderDetail 方法传错 request type

    [BUG] GetOrderDetail 方法传错 request type

    https://github.com/amir-the-h/okex/blob/4b18bcde84b497aa88c81b3f581f0fd0e6c9293c/api/rest/trade.go#L140

    应该传入 requests.OrderDetails 而不是 requests.OrderList

  • [BUG] /api/v5/public/time return empty response and nil err

    [BUG] /api/v5/public/time return empty response and nil err

    method /api/v5/public/time and and others public methods return empty response and nil err on version v1.0.30-alpha, but v1.0.29-alpha is OK.

    • Package Version: v1.0.30-alpha and higher
A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

Mar 5, 2022
The NVD API is an unofficial Go wrapper around the NVD API.

NVD API The NVD API is an unofficial Go wrapper around the NVD API. Supports: CVE CPE How to use The following shows how to basically use the wrapper

Jan 7, 2023
A Wrapper Client for Google Spreadsheet API (Sheets API)

Senmai A Wrapper Client for Google Spreadsheet API (Sheets API) PREPARATION Service Account and Key File Create a service account on Google Cloud Plat

Nov 5, 2021
Simple golang airtable API wrapper

Golang Airtable API A simple #golang package to access the Airtable API. Table of contents Golang Airtable API Table of contents Installation Basic us

Jan 5, 2023
This is a Golang wrapper for working with TMDb API. It aims to support version 3.
This is a Golang wrapper for working with TMDb API. It aims to support version 3.

This is a Golang wrapper for working with TMDb API. It aims to support version 3. An API Key is required. To register for one, head over to themoviedb

Dec 27, 2022
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)

Gosip - SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang) Main features Unattended authentication using different strategies

Jan 2, 2023
A small, fast, reliable pastemyst API wrapper written in Golang

A small, fast, reliable pastemyst API wrapper written in Golang. Official pastemyst API docs found here.

Dec 12, 2022
SpamProtection-Go is an Official golang wrapper for Intellivoid SpamProtection API
SpamProtection-Go is an Official golang wrapper for Intellivoid SpamProtection API

SpamProtection-Go is an Official golang wrapper for Intellivoid SpamProtection API, which is fast, secure and requires no additional packages to be installed.

Feb 26, 2022
Unofficial Anilist.co GraphQL API wrapper for GoLang.

anilistWrapGo Unofficial Anilist.co GraphQL API wrapper for GoLang. Examples All examples are present as tests in test directory. Below are a few snip

Dec 20, 2022
Pterodactyl API wrapper written in Golang

WARNING That repository isn't available for production environment. Many endpoints aren't yet implemented. Be careful if you are using that module. pt

Oct 4, 2022
A Wrapper of the Piston API in Golang

Go-Piston! This is a Go wrapper for working with the Piston API. It supports both the endpoints, namely runtimes and execute, mentioned here. ?? Insta

Aug 28, 2022
Golang wrapper for the FiveM natives API

Golang wrapper for the FiveM natives API

Dec 2, 2022
Golang wrapper for the Sylviorus antispam API for telegram

Syl-Go Golang wrapper for the Sylviorus antispam API for telegram package test

Jan 2, 2022
Gocaptcha - An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

Nov 1, 2022
Trello API wrapper for Go
Trello API wrapper for Go

Go Trello API A #golang package to access the Trello API. Nearly 100% of the read-only surface area of the API is covered, as is creation and modifica

Jan 4, 2023
Nov 28, 2022
The fantastic Reddit API wrapper for gophers
The fantastic Reddit API wrapper for gophers

mira is a Reddit Api Wrapper written in beautiful Go. It is super simple to use the bot as we also provide you with simple but fully extensive interfaces. Currently, mira is a project that is considered more or less complete.

Dec 18, 2022
A Telegraph API wrapper in Go

Telegra.ph is a minimalist publishing tool that allows you to create richly formatted posts and push them to the Web in just a click. Telegraph posts also get beautiful Instant View pages on Telegram. So, this Go wrapper enables you to do all that easily.

Oct 29, 2022
💻 Quotable.io API Wrapper + CLI App
💻 Quotable.io API Wrapper + CLI App

?? Quotable.io API Wrapper + CLI App

Sep 27, 2022