-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7eb6e40
commit e63536b
Showing
8 changed files
with
578 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package v3 | ||
|
||
import ( | ||
"github.com/c9s/requestgen" | ||
|
||
"github.com/c9s/bbgo/pkg/exchange/bybit/bybitapi" | ||
) | ||
|
||
type APIResponse = bybitapi.APIResponse | ||
|
||
type Client struct { | ||
Client requestgen.AuthenticatedAPIClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package v3 | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/c9s/bbgo/pkg/exchange/bybit/bybitapi" | ||
"github.com/c9s/bbgo/pkg/testutil" | ||
) | ||
|
||
func getTestClientOrSkip(t *testing.T) *bybitapi.RestClient { | ||
if b, _ := strconv.ParseBool(os.Getenv("CI")); b { | ||
t.Skip("skip test for CI") | ||
} | ||
|
||
key, secret, ok := testutil.IntegrationTestConfigured(t, "BYBIT") | ||
if !ok { | ||
t.Skip("BYBIT_* env vars are not configured") | ||
return nil | ||
} | ||
|
||
client, err := bybitapi.NewClient() | ||
assert.NoError(t, err) | ||
client.Auth(key, secret) | ||
return client | ||
} | ||
|
||
func TestClient(t *testing.T) { | ||
client := getTestClientOrSkip(t) | ||
v3Client := Client{Client: client} | ||
ctx := context.Background() | ||
|
||
t.Run("GetTradeRequest", func(t *testing.T) { | ||
startTime := time.Date(2023, 7, 27, 16, 13, 9, 0, time.UTC) | ||
apiResp, err := v3Client.NewGetTradesRequest().Symbol("BTCUSDT").StartTime(startTime).Do(ctx) | ||
assert.NoError(t, err) | ||
t.Logf("apiResp: %+v", apiResp) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package v3 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/c9s/requestgen" | ||
|
||
"github.com/c9s/bbgo/pkg/fixedpoint" | ||
"github.com/c9s/bbgo/pkg/types" | ||
) | ||
|
||
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result | ||
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result | ||
|
||
type TradesResponse struct { | ||
List []Trade `json:"list"` | ||
} | ||
|
||
type Trade struct { | ||
Symbol string `json:"symbol"` | ||
Id string `json:"id"` | ||
OrderId string `json:"orderId"` | ||
TradeId string `json:"tradeId"` | ||
OrderPrice fixedpoint.Value `json:"orderPrice"` | ||
OrderQty fixedpoint.Value `json:"orderQty"` | ||
ExecFee fixedpoint.Value `json:"execFee"` | ||
FeeTokenId string `json:"feeTokenId"` | ||
CreatTime types.MillisecondTimestamp `json:"creatTime"` | ||
IsBuyer Side `json:"isBuyer"` | ||
IsMaker OrderType `json:"isMaker"` | ||
MatchOrderId string `json:"matchOrderId"` | ||
MakerRebate fixedpoint.Value `json:"makerRebate"` | ||
ExecutionTime types.MillisecondTimestamp `json:"executionTime"` | ||
BlockTradeId string `json:"blockTradeId"` | ||
} | ||
|
||
//go:generate GetRequest -url "/spot/v3/private/my-trades" -type GetTradesRequest -responseDataType .TradesResponse | ||
type GetTradesRequest struct { | ||
client requestgen.AuthenticatedAPIClient | ||
|
||
symbol *string `param:"symbol,query"` | ||
orderId *string `param:"orderId,query"` | ||
// Limit default value is 50, max 50 | ||
limit *uint64 `param:"limit,query"` | ||
startTime *time.Time `param:"startTime,query,milliseconds"` | ||
endTime *time.Time `param:"endTime,query,milliseconds"` | ||
fromTradeId *string `param:"fromTradeId,query"` | ||
toTradeId *string `param:"toTradeId,query"` | ||
} | ||
|
||
func (c *Client) NewGetTradesRequest() *GetTradesRequest { | ||
return &GetTradesRequest{ | ||
client: c.Client, | ||
} | ||
} |
238 changes: 238 additions & 0 deletions
238
pkg/exchange/bybit/bybitapi/v3/get_trades_request_requestgen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package v3 | ||
|
||
type Side string | ||
|
||
const ( | ||
SideBuy Side = "0" | ||
SideSell Side = "1" | ||
) | ||
|
||
type OrderType string | ||
|
||
const ( | ||
OrderTypeMaker OrderType = "0" | ||
OrderTypeTaker OrderType = "1" | ||
) |
Oops, something went wrong.