MCPcopy Index your code
hub / github.com/amir-the-h/okex

github.com/amir-the-h/okex @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
499 symbols 915 edges 43 files 157 documented · 31%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

DISCLAIMER:

This package is provided as-is, without any express or implied warranties. The user assumes all risks associated with the use of this package. The author and contributors to this package shall not be held liable for any damages arising from the use of this package, including but not limited to direct, indirect, incidental, or consequential damages. This package is not intended to be used as a substitute for professional financial advice. Users are responsible for verifying the accuracy and reliability of the data generated by this package. Use of this package constitutes acceptance of these terms and conditions.

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/okex@v1.1.4-alpha

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/public"
  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)
  }


  log.Println("Starting")
  errChan := make(chan *events.Error)
  subChan := make(chan *events.Subscribe)
  uSubChan := make(chan *events.Unsubscribe)
  logChan := make(chan *events.Login)
  sucChan := make(chan *events.Success)
  client.Ws.SetChannels(errChan, subChan, uSubChan, logChan, sucChan)

  obCh := make(chan *public.OrderBook)
  err = client.Ws.Public.OrderBook(ws_public_requests.OrderBook{
    InstID: "BTC-USD-SWAP",
    Channel: "books",
  }, obCh)
  if err != nil {
    log.Fatalln(err)
  }

  for {
    select {
    case <-logChan:
      log.Print("[Authorized]")
    case success := <-sucChan:
      log.Printf("[SUCCESS]\t%+v", success)
    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)
      for _, datum := range err.Data {
        log.Printf("[Error]\t\t%+v", datum)
      }
    case i := <-obCh:
      ch, _ := i.Arg.Get("channel")
      log.Printf("[Event]\t%s", ch)
      for _, p := range i.Books {
        for i := len(p.Asks) - 1; i >= 0; i-- {
          log.Printf("\t\tAsk\t%+v", p.Asks[i])
        }
        for _, bid := range p.Bids {
          log.Printf("\t\tBid\t%+v", bid)
        }
      }
    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

Core symbols most depended-on inside this repo

Shape

Struct 279
Method 164
TypeAlias 41
Function 15

Languages

Go100%

Modules by API surface

definitions.go53 symbols
api/ws/public.go31 symbols
models/account/account_models.go20 symbols
models/publicdata/publicdata_models.go19 symbols
api/rest/account.go19 symbols
api/ws/client.go17 symbols
responses/account/account_responses.go16 symbols
responses/public_data/public_data_responses.go15 symbols
models/tradedata/tradedata_models.go15 symbols
api/rest/trade.go15 symbols
api/rest/public_data.go15 symbols
requests/ws/public/public_requests.go14 symbols

For agents

$ claude mcp add okex \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page