broker c2c

This commit is contained in:
wuhewuhe 2023-11-06 01:08:54 +01:00
parent 9302096f59
commit e78bfa1d40
10 changed files with 633 additions and 1 deletions

35
broker.go Normal file
View File

@ -0,0 +1,35 @@
package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)
type BrokerServiceClient struct {
c *Client
params map[string]interface{}
}
func (s *BrokerServiceClient) GetBrokerEarning(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/broker/earning-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}

View File

@ -274,3 +274,21 @@ func (c *Client) NewAssetService(params map[string]interface{}) *AssetClient {
c: c, c: c,
} }
} }
func (c *Client) NewUserService(params map[string]interface{}) *UserServiceClient {
return &UserServiceClient{
c: c,
}
}
func (c *Client) NewBrokerService(params map[string]interface{}) *BrokerServiceClient {
return &BrokerServiceClient{
c: c,
}
}
func (c *Client) NewLendingService(params map[string]interface{}) *LendingServiceClient {
return &LendingServiceClient{
c: c,
}
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceTrade()
}
func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{}
orderResult, err := client.NewBrokerService(params).GetBrokerEarning(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceTrade()
}
func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"coin": "USDT"}
orderResult, err := client.NewLendingService(params).GetC2cLendingCoinInfo(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

View File

@ -1 +1,22 @@
package user package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceTrade()
}
func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"username": "wuhe06112023Vic", "memberType": 1}
userResult, err := client.NewUserService(params).CreateSubMember(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(userResult))
}

145
lending.go Normal file
View File

@ -0,0 +1,145 @@
package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)
type LendingServiceClient struct {
c *Client
params map[string]interface{}
}
func (s *LendingServiceClient) GetC2cLendingCoinInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/lending/info",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *LendingServiceClient) GetC2cLendingOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/lending/history-order",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *LendingServiceClient) GetC2cLendingAccountInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/lending/account",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *LendingServiceClient) C2cDepositFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/lending/purchase",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *LendingServiceClient) C2cRedeemFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/lending/redeem",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *LendingServiceClient) C2cCancelRedeemFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/lending/redeem-cancel",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}

18
models/brokerResponse.go Normal file
View File

@ -0,0 +1,18 @@
package models
// BrokerEarningInfo represents an individual record of broker earnings.
type BrokerEarningInfo struct {
UserId string `json:"userId"`
BizType string `json:"bizType"`
Symbol string `json:"symbol"`
Coin string `json:"coin"`
Earning string `json:"earning"`
OrderId string `json:"orderId"`
ExecTime string `json:"execTime"`
}
// BrokerEarningResult represents the paginated result of broker earnings.
type BrokerEarningResult struct {
List []BrokerEarningInfo `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}

62
models/lendingResponse.go Normal file
View File

@ -0,0 +1,62 @@
package models
// LendingCoin represents information about a specific coin available for lending.
type LendingCoin struct {
Coin string `json:"coin"`
MaxRedeemQty string `json:"maxRedeemQty"`
MinPurchaseQty string `json:"minPurchaseQty"`
Precision string `json:"precision"`
Rate string `json:"rate"`
LoanToPoolRatio string `json:"loanToPoolRatio"`
ActualApy string `json:"actualApy"`
}
// LendingCoinInfoResult represents the list of coins available for lending.
type LendingCoinInfoResult struct {
List []LendingCoin `json:"list"`
}
// DepositFund represents the status of a deposit into a lending product.
type DepositFund struct {
Coin string `json:"coin"`
CreatedTime string `json:"createdTime"`
OrderId string `json:"orderId"`
Quantity string `json:"quantity"`
SerialNo string `json:"serialNo"`
Status string `json:"status"`
UpdatedTime string `json:"updatedTime"`
}
// RedeemFund represents the status of a redemption request from a lending product.
type RedeemFund struct {
Coin string `json:"coin"`
CreatedTime string `json:"createdTime"`
OrderId string `json:"orderId"`
PrincipalQty string `json:"principalQty"`
SerialNo string `json:"serialNo"`
Status string `json:"status"`
UpdatedTime string `json:"updatedTime"`
}
// CancelRedeemFund represents the status of a cancelled redemption request from a lending product.
type CancelRedeemFund struct {
OrderId string `json:"orderId"`
SerialNo string `json:"serialNo"`
UpdatedTime string `json:"updatedTime"`
}
// LendingOrderRecord represents an individual lending order record.
type LendingOrderRecord struct {
Coin string `json:"coin"`
CreatedTime string `json:"createdTime"`
OrderId string `json:"orderId"`
Quantity string `json:"quantity"`
SerialNo string `json:"serialNo"`
Status string `json:"status"`
UpdatedTime string `json:"updatedTime"`
}
// LendingOrdersRecordsResult represents the result of a query for lending order records.
type LendingOrdersRecordsResult struct {
List []LendingOrderRecord `json:"list"`
}

18
models/userResponse.go Normal file
View File

@ -0,0 +1,18 @@
package models
// UserVolumeInfo represents the structure for a user's trading and deposit volume information.
type UserVolumeInfo struct {
UID string `json:"uid"`
VipLevel string `json:"vipLevel"`
TakerVol30Day string `json:"takerVol30Day"`
MakerVol30Day string `json:"makerVol30Day"`
TradeVol30Day string `json:"tradeVol30Day"`
DepositAmount30Day string `json:"depositAmount30Day"`
TakerVol365Day string `json:"takerVol365Day"`
MakerVol365Day string `json:"makerVol365Day"`
TradeVol365Day string `json:"tradeVol365Day"`
DepositAmount365Day string `json:"depositAmount365Day"`
TotalWalletBalance string `json:"totalWalletBalance"` // This should be an integer value representing a range, not a string.
DepositUpdateTime string `json:"depositUpdateTime"`
VolUpdateTime string `json:"volUpdateTime"`
}

271
user.go
View File

@ -1,6 +1,277 @@
package bybit_connector package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)
type UserServiceClient struct { type UserServiceClient struct {
c *Client c *Client
params map[string]interface{} params map[string]interface{}
} }
func (s *UserServiceClient) CreateSubMember(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/create-sub-member",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) CreateSubApiKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/create-sub-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) FreezeSubUID(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/frozen-sub-member",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) ModifyMasterAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/update-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) ModifySubAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/update-sub-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) DeleteSubUID(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/del-submember",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) DeleteMasterAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/delete-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) DeleteSubAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/delete-sub-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) GetSubUidList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/query-sub-members",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) GetAPIKeyInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/query-api",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) GetUidWalletType(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/get-member-type",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *UserServiceClient) GetAffiliateUserInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/user/aff-customer-info",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}