Skip to content

Commit

Permalink
Release: v1.0.32-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-the-h committed Mar 17, 2023
1 parent 72f25a3 commit 593fb14
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 108 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ Changelog
=========
All notable changes to this project will be documented in this file.

v1.0.32-alpha
-------------

### Changed

- Fixed `OrderBookWs` struct `Checksum` field by removing string json tag
- Added `InstID` to `OrderBook` event struct

v1.0.31-alpha
-------------

### Changed

- Migrated to `okx.com`
- Migrated to `okx.com`

v1.0.30-alpha
-------------
Expand Down
190 changes: 84 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ okex
[![AutoRelease](https://github.com/amir-the-h/okex/actions/workflows/release.yml/badge.svg)](https://github.com/amir-the-h/okex/actions/workflows/release.yml)

*NOTICE:*
> PACKAGE IS CURRENTLY UNDER HEAVY DEVELOPMENT AND THERE IS NO GUARANTY FOR STABILITY UNTIL V1 RELEASE.
> 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

Expand All @@ -22,7 +25,7 @@ Installation
-----------------

```bash
go get github.com/amir-the-h/[email protected].28-alpha
go get github.com/amir-the-h/[email protected].31-alpha
```

Usage
Expand All @@ -32,124 +35,99 @@ 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"
"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)
}

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
}
}
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
---------------

* [Rest](https://www.okex.com/docs-v5/en/#rest-api)
* [Trade](https://www.okex.com/docs-v5/en/#rest-api-trade) (except demo special trading endpoints)
* [Funding](https://www.okex.com/docs-v5/en/#rest-api-funding)
* [Account](https://www.okex.com/docs-v5/en/#rest-api-account)
* [SubAccount](https://www.okex.com/docs-v5/en/#rest-api-subaccount)
* [Market Data](https://www.okex.com/docs-v5/en/#rest-api-market-data)
* [Public Data](https://www.okex.com/docs-v5/en/#rest-api-public-data)
* [Trading Data](https://www.okex.com/docs-v5/en/#rest-api-trading-data)
* [Trade](https://www.okex.com/docs-v5/en/#rest-api-trade) (except demo special trading endpoints)
* [Funding](https://www.okex.com/docs-v5/en/#rest-api-funding)
* [Account](https://www.okex.com/docs-v5/en/#rest-api-account)
* [SubAccount](https://www.okex.com/docs-v5/en/#rest-api-subaccount)
* [Market Data](https://www.okex.com/docs-v5/en/#rest-api-market-data)
* [Public Data](https://www.okex.com/docs-v5/en/#rest-api-public-data)
* [Trading Data](https://www.okex.com/docs-v5/en/#rest-api-trading-data)

[comment]: <> ( * [Status]&#40;https://www.okex.com/docs-v5/en/#rest-api-status&#41;)

* [Ws](https://www.okex.com/docs-v5/en/#websocket-api)
* [Private Channel](https://www.okex.com/docs-v5/en/#websocket-api-private-channel) (except demo special trading
endpoints)
* [Public Channel](https://www.okex.com/docs-v5/en/#websocket-api-public-channels)
* [Trade](https://www.okex.com/docs-v5/en/#websocket-api-trade)
* [Private Channel](https://www.okex.com/docs-v5/en/#websocket-api-private-channel) (except demo special trading
endpoints)
* [Public Channel](https://www.okex.com/docs-v5/en/#websocket-api-public-channels)
* [Trade](https://www.okex.com/docs-v5/en/#websocket-api-trade)

Features
--------
Expand Down
1 change: 1 addition & 0 deletions events/public/public_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type (
}
OrderBook struct {
Arg *events.Argument `json:"arg"`
InstID string `json:"instId"`
Books []*market.OrderBookWs `json:"data"`
Action string `json:"action"`
}
Expand Down
2 changes: 1 addition & 1 deletion models/market/market_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type (
OrderBookWs struct {
Asks []*OrderBookEntity `json:"asks"`
Bids []*OrderBookEntity `json:"bids"`
Checksum int `json:"checksum,string"`
Checksum int `json:"checksum"`
TS okex.JSONTime `json:"ts"`
}
OrderBookEntity struct {
Expand Down

0 comments on commit 593fb14

Please sign in to comment.