mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
exchanges: Add OKX support (#1005)
* public endpoints methods added * Completing mapping REST endpoints * Binanceus Wrapper methods -Partially * Binanceus Wrapper methods -Partially * BinaWra functions with test funs; Not Completed * Finalizing wrapper methods & test * Fix & Complete wrapper functions * Finalizing wrapper methods & test * Adding Stream Datas * WS Test functions * CI: Fix golangci-lint linter issues * CI: Fix reverting unnessesary changes and type conversion issues * CI: Fix reverting unnessesary changes and type conversion issues * Adding Public endpoints and tests * Adding Market and Public Endpoints * Adding Public endoints * Public Trading Endpoints & Authenticated Trade order methods * Adding Authenticated Methods and Tests * Adding algo and Funding Authenticated endpoints * Adding funding trading endpoints and correspondint tests * adding authenticated endpoints * Completing Block Trading endpoints and added subaccount endpoints * Completing sub account and grid Trading endpoints * Adding Rate Limit and missing endpoints * Wrapper and Websocket handlers * Fixing Websocket Test and Push Data Handler Issues * Fixing Websocket Test and Push Data Handler Issues * Fixing linter issues, package dependency, and other slight tempos * Fixing linter and slight tempos * Update on test functions, and Rest and Websocket Endpoint handlers * Remove okex, adding comments, and slight fixes on endpoints. * Fixing linter issues and adding comments * Slight code changes, updating documentation, and n and linter issues * Fix context and configuration endpoint issues * slight fixes on config and test files * adding some missing test and fix linter issues * fix linter issue * Slight fixes on code structure, shorthand exp,and ot and other * Fix slight linter issue * Slight code fixes and fixing linter issues * fixing linter iissues * fixing linter iissues * slight linter issue fix * slight linter issue fix * Fix on models, type convert funcs and endpoints * Adding Error messages map and update of models * Fix on error message string and linter issues * Fix slight linter issue * Fix slight linter issue * Fixing type converts, models, and linter issues * Adding Ws fixes * Slight fix on websocket and other issues * Adding slight websocket fixes * Remove 'books5' channel default subscription * Small changes on default subscription and checksum * Fix slight websocket tempos * Fix Wrapper function tempost and linter issues * Resolving slight naming and other issues * Resolve slight pointer issues * resolve slight linter issues * Resolve config files issue * Update websocket and wrapper funcs with test and docs * fixs on websocket multiplexer, types, and other slight issues * fix slight linter issues * slight update on web-socket orderbook and tickers * fix slight issues and websocket runtime errors * Slight unit test fix and assing simple semaphore * FIx race issue * Update on authenticated endpoints * Fix wsSetupRun check in websocket 'setupWsAuth' func * Update wsSetupRun check in websocket 'setupWsAuth' func * Slight update on websocket handling * Fix some race conditions * fix slight tempos * fix authenticated test issues * Update on conditional statements * slight update on unit test * fix unit test tempos * Fix slight tempos * Change check map from struct valued to bool valued * slight fix trial * Slight unit test update * Fix websocket timeout error * Updating websocket subscription endpoints, and unit tests * update unit tests * Slight issue on wrapper method 'GetActiveOrders' * Overall code update * Addressing missing review comments * Fix unit test tempo and linter issue * Monor fix * Slight update * Slight unit test fix * Slight fixes * Slight fixes * Fixing on missing review comments * Adding WS Fixes * slight fix * Monor fix on unit test * Minor convert issue * Minor change on WS * Monor logic fix * Fix code structure and logic issues * Fixing small typos * fix slight data format issue * Update on trade and order wrapper methods * Adding slight update * fix on order detail * Slight update on FetchTradablePairs wrapper method * Slight update on wrapper * Update on deserialization and other slight issues * Final update * Resolve missing review comments * Slight update on config and unit test * minor fix on GetDepositAddress param * Minor fix
This commit is contained in:
@@ -2,9 +2,11 @@ package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -32,6 +34,13 @@ const (
|
||||
defaultTimeout = time.Second * 15
|
||||
)
|
||||
|
||||
// Strings representing the full lower, upper case English character alphabet and base-10 numbers for generating a random string.
|
||||
const (
|
||||
SmallLetters = "abcdefghijklmnopqrstuvwxyz"
|
||||
CapitalLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
NumberCharacters = "0123456789"
|
||||
)
|
||||
|
||||
var (
|
||||
// emailRX represents email address matching pattern
|
||||
emailRX = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||
@@ -470,6 +479,30 @@ func StartEndTimeCheck(start, end time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateRandomString generates a random string provided a length and list of Character types { SmallLetters, CapitalLetters, NumberCharacters}.
|
||||
// if no characters are provided, the function uses a NumberCharacters(string of numeric characters).
|
||||
func GenerateRandomString(length uint, characters ...string) (string, error) {
|
||||
if length == 0 {
|
||||
return "", errors.New("invalid length, length must be non-zero positive integer")
|
||||
}
|
||||
b := make([]byte, length)
|
||||
chars := strings.Replace(strings.Join(characters, ""), " ", "", -1)
|
||||
if chars == "" && len(characters) != 0 {
|
||||
return "", errors.New("invalid characters, character must not be empty")
|
||||
} else if chars == "" {
|
||||
chars = NumberCharacters
|
||||
}
|
||||
for i := range b {
|
||||
nBig, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
n := nBig.Int64()
|
||||
b[i] = chars[n]
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// GetAssertError returns additional information for when an assertion failure
|
||||
// occurs.
|
||||
func GetAssertError(required string, received interface{}) error {
|
||||
|
||||
@@ -721,3 +721,34 @@ func TestMatchesEmailPattern(t *testing.T) {
|
||||
t.Error("MatchesEmailPattern() unexpected test validation result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateRandomString(t *testing.T) {
|
||||
t.Parallel()
|
||||
sample, err := GenerateRandomString(5, NumberCharacters)
|
||||
if err != nil {
|
||||
t.Errorf("GenerateRandomString() %v", err)
|
||||
}
|
||||
value, err := strconv.Atoi(sample)
|
||||
if len(sample) != 5 || err != nil || value < 0 {
|
||||
t.Error("GenerateRandomString() unexpected test validation result")
|
||||
}
|
||||
sample, err = GenerateRandomString(5)
|
||||
if err != nil {
|
||||
t.Errorf("GenerateRandomString() %v", err)
|
||||
}
|
||||
values, err := strconv.ParseInt(sample, 10, 64)
|
||||
if len(sample) != 5 || err != nil || values < 0 {
|
||||
t.Error("GenerateRandomString() unexpected test validation result")
|
||||
}
|
||||
_, err = GenerateRandomString(1, "")
|
||||
if err == nil {
|
||||
t.Errorf("GenerateRandomString() expecting %s, but found %v", "invalid characters, character must not be empty", err)
|
||||
}
|
||||
sample, err = GenerateRandomString(0, "")
|
||||
if err != nil && !strings.Contains(err.Error(), "invalid length") {
|
||||
t.Errorf("GenerateRandomString() %v", err)
|
||||
}
|
||||
if sample != "" {
|
||||
t.Error("GenerateRandomString() unexpected test validation result")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user