Compare commits
No commits in common. "main" and "VictorWuBranche" have entirely different histories.
main
...
VictorWuBr
|
@ -0,0 +1,28 @@
|
|||
# This workflow will build a golang project
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
||||
|
||||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/bybit.go.api.iml" filepath="$PROJECT_DIR$/.idea/bybit.go.api.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type AccountClient struct {
|
||||
|
|
4
asset.go
4
asset.go
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type AssetClient struct {
|
||||
|
@ -472,7 +471,6 @@ func (s *AssetClient) GetWithdrawalAmount(ctx context.Context, opts ...RequestOp
|
|||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *AssetClient) GetWithdrawalRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
|
||||
r := &request{
|
||||
method: http.MethodGet,
|
||||
|
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type BrokerServiceClient struct {
|
||||
|
|
|
@ -14,9 +14,9 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
"github.com/bitly/go-simplejson"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
@ -199,7 +199,9 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
|
|||
c.debug("response status code: %d", res.StatusCode)
|
||||
|
||||
if res.StatusCode >= http.StatusBadRequest {
|
||||
apiErr := new(handlers.APIError)
|
||||
var (
|
||||
apiErr = new(handlers.APIError)
|
||||
)
|
||||
e := json.Unmarshal(data, apiErr)
|
||||
if e != nil {
|
||||
c.debug("failed to unmarshal json: %s", e)
|
||||
|
@ -308,6 +310,7 @@ func (c *Client) NewPositionService(params map[string]interface{}) *PositionClie
|
|||
c: c,
|
||||
params: params,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) NewPreUpgradeService(params map[string]interface{}) *PreUpgradeClient {
|
||||
|
|
|
@ -5,30 +5,28 @@ import (
|
|||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/websocket"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type MessageHandler func(message string) error
|
||||
|
||||
func (b *WebSocket) handleIncomingMessages() error {
|
||||
func (b *WebSocket) handleIncomingMessages() {
|
||||
for {
|
||||
_, message, err := b.conn.ReadMessage()
|
||||
if err != nil {
|
||||
fmt.Println("Error reading:", err)
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if b.onMessage != nil {
|
||||
err := b.onMessage(string(message))
|
||||
if err != nil {
|
||||
fmt.Println("Error handling message:", err)
|
||||
return err
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,49 +112,35 @@ func (b *WebSocket) Connect(args []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
eg := errgroup.Group{}
|
||||
go b.handleIncomingMessages()
|
||||
|
||||
b.ctx, b.cancel = context.WithCancel(context.Background())
|
||||
Ping(b)
|
||||
|
||||
eg.Go(b.Ping)
|
||||
eg.Go(b.handleIncomingMessages)
|
||||
|
||||
if err := b.sendSubscription(args); err != nil {
|
||||
return fmt.Errorf("failed to send subscription: %w", err)
|
||||
}
|
||||
|
||||
if err := eg.Wait(); err != nil {
|
||||
b.Disconnect()
|
||||
return fmt.Errorf("failed to handle message: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return b.sendSubscription(args)
|
||||
}
|
||||
|
||||
var ErrPingFailed = errors.New("failed to send ping")
|
||||
|
||||
func (b *WebSocket) Ping() error {
|
||||
func Ping(b *WebSocket) {
|
||||
ticker := time.NewTicker(time.Duration(b.pingInterval) * time.Second)
|
||||
go func() {
|
||||
defer ticker.Stop() // Ensure the ticker is stopped when this goroutine ends
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C: // Wait until the ticker sends a signal
|
||||
if err := b.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
|
||||
fmt.Println("Failed to send ping:", err)
|
||||
return ErrPingFailed
|
||||
}
|
||||
case <-b.ctx.Done():
|
||||
fmt.Println("Exit ping")
|
||||
return nil
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (b *WebSocket) Disconnect() error {
|
||||
b.cancel()
|
||||
err := b.conn.Close()
|
||||
fmt.Println("WebSocket disconnected, err =", err)
|
||||
return err
|
||||
return b.conn.Close()
|
||||
}
|
||||
|
||||
func (b *WebSocket) Send(message string) error {
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
bybit "gitea.computernetthings.ru/yash/bybit.go.api"
|
||||
bybit "github.com/wuhewuhe/bybit.go.api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
bybit "gitea.computernetthings.ru/yash/bybit.go.api"
|
||||
bybit "github.com/wuhewuhe/bybit.go.api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
bybit "gitea.computernetthings.ru/yash/bybit.go.api"
|
||||
bybit "github.com/wuhewuhe/bybit.go.api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
bybit "gitea.computernetthings.ru/yash/bybit.go.api"
|
||||
bybit "github.com/wuhewuhe/bybit.go.api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -13,8 +12,7 @@ func main() {
|
|||
|
||||
func PlaceBatchTrade() {
|
||||
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
|
||||
params := map[string]interface{}{
|
||||
"category": "option",
|
||||
params := map[string]interface{}{"category": "option",
|
||||
"request": []map[string]interface{}{
|
||||
{
|
||||
"category": "option",
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
bybit "gitea.computernetthings.ru/yash/bybit.go.api"
|
||||
bybit "github.com/wuhewuhe/bybit.go.api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
3
go.mod
3
go.mod
|
@ -1,4 +1,4 @@
|
|||
module gitea.computernetthings.ru/yash/bybit.go.api
|
||||
module github.com/wuhewuhe/bybit.go.api
|
||||
|
||||
go 1.21
|
||||
|
||||
|
@ -8,7 +8,6 @@ require (
|
|||
github.com/gorilla/websocket v1.5.1
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/sync v0.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
3
go.sum
3
go.sum
|
@ -10,6 +10,7 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/
|
|||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
|
@ -30,8 +31,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
|
|||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type LendingServiceClient struct {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/models"
|
||||
"github.com/wuhewuhe/bybit.go.api/models"
|
||||
)
|
||||
|
||||
// MarketKlinesService Market Kline (GET /v5/market/kline)
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/models"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/wuhewuhe/bybit.go.api/models"
|
||||
)
|
||||
|
||||
type marketTestSuite struct {
|
||||
|
@ -128,7 +128,6 @@ func (s *marketTestSuite) assertMarketKlineEqual(expected, actual *models.Market
|
|||
r.Equal(len(expected.List), len(actual.List), "List")
|
||||
r.Equal(expected.List, actual.List)
|
||||
}
|
||||
|
||||
func (s *marketTestSuite) TestMarketMarkPriceKline() {
|
||||
data := []byte(`{
|
||||
"retCode": 0,
|
||||
|
@ -1297,7 +1296,6 @@ func (s *marketTestSuite) assertMarketLongShortRatioInfoEqual(expected, actual *
|
|||
r := s.r()
|
||||
r.Equal(expected.List, actual.List, "List")
|
||||
}
|
||||
|
||||
func (s *marketTestSuite) TestGetServerTime() {
|
||||
data := []byte(`{
|
||||
"retCode": 0,
|
||||
|
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type PositionClient struct {
|
||||
|
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type PreUpgradeClient struct {
|
||||
|
|
|
@ -2,9 +2,8 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type SpotLeverageClient struct {
|
||||
|
|
|
@ -3,9 +3,8 @@ package bybit_connector
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
)
|
||||
|
||||
type SpotMarginClient struct {
|
||||
|
|
5
trade.go
5
trade.go
|
@ -2,10 +2,9 @@ package bybit_connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wuhewuhe/bybit.go.api/handlers"
|
||||
"github.com/wuhewuhe/bybit.go.api/models"
|
||||
"net/http"
|
||||
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/handlers"
|
||||
"gitea.computernetthings.ru/yash/bybit.go.api/models"
|
||||
)
|
||||
|
||||
type TradeClient struct {
|
||||
|
|
Loading…
Reference in New Issue