Golang API wrapper of OkEX

Overview

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
Issues
  • 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

    wontfix 
    opened by renat1015 5
  • 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

    opened by LINJINTIANDE 4
  • 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!

    bug 
    opened by renat1015 3
  • 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.

    opened by afzalabbasi 3
  • fix:placeOrder struct field

    fix:placeOrder struct field

    opened by 404er 1
  • [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

    opened by CallMeMhz 1
Releases(v1.0.29-alpha)
Owner
Amir
A person who converts teas into the codes. Technology lover, Former PHP expert, Golang hunger.
Amir
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!

null 1 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

Lucas TESSON 4 Jun 30, 2022
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

ytnobody / satoshi azuma 0 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

mehanizm 40 Jun 21, 2022
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

Cyro Dubeux 53 Jun 25, 2022
⚡️ 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

Andrew Koltyakov 79 Jun 18, 2022
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.

null 11 Nov 18, 2021
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.

Intellivoid 0 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

ダンクデル (Sayan Biswas) 14 Feb 17, 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

Luiz Otávio de Farias Correa 3 Mar 28, 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

null 7 Feb 20, 2022
Golang wrapper for the FiveM natives API

Golang wrapper for the FiveM natives API

normalM 3 Jun 28, 2022
Golang wrapper for the Sylviorus antispam API for telegram

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

Pranav Ajay 1 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

null 17 Jun 17, 2022
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

Aaron Longwell 199 Jun 15, 2022
null 88 Jun 15, 2022
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.

Sandy 54 Apr 2, 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.

Anony 22 Jun 10, 2022
💻 Quotable.io API Wrapper + CLI App

?? Quotable.io API Wrapper + CLI App

Eliaz Bobadilla 10 May 31, 2022