Merge pull request #9 from wuhewuhe/master

asset
This commit is contained in:
CommaHunger 2023-11-06 00:45:23 +01:00 committed by GitHub
commit 478f0c0421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 723 additions and 0 deletions

443
asset.go Normal file
View File

@ -0,0 +1,443 @@
package bybit_connector
import (
"context"
"encoding/json"
"net/http"
)
type AssetClient struct {
c *Client
params map[string]interface{}
}
func (s *AssetClient) GetAssetOrderRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/exchange/order-record",
secType: secTypeSigned,
}
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 *AssetClient) GetAssetInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-asset-info",
secType: secTypeSigned,
}
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 *AssetClient) GetDeliveryRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/delivery-record",
secType: secTypeSigned,
}
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 *AssetClient) GetUsdcSettlement(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/settlement-record",
secType: secTypeSigned,
}
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 *AssetClient) GetAllCoinsBalance(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-account-coins-balance",
secType: secTypeSigned,
}
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 *AssetClient) GetSingleCoinsBalance(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-account-coin-balance",
secType: secTypeSigned,
}
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 *AssetClient) GetTransferableCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-transfer-coin-list",
secType: secTypeSigned,
}
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 *AssetClient) CreateInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/transfer/inter-transfer",
secType: secTypeSigned,
}
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 *AssetClient) CreateUniversalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/transfer/universal-transfer",
secType: secTypeSigned,
}
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 *AssetClient) SetDepositAccount(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/deposit/deposit-to-account",
secType: secTypeSigned,
}
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 *AssetClient) WithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/withdraw/create",
secType: secTypeSigned,
}
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 *AssetClient) CancelWithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/withdraw/cancel",
secType: secTypeSigned,
}
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 *AssetClient) GetInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-inter-transfer-list",
secType: secTypeSigned,
}
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 *AssetClient) GetUniversalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-universal-transfer-list",
secType: secTypeSigned,
}
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 *AssetClient) GetSubUids(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-sub-member-list",
secType: secTypeSigned,
}
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 *AssetClient) GetAllowedDepositCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-allowed-list",
secType: secTypeSigned,
}
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 *AssetClient) GetDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-record",
secType: secTypeSigned,
}
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 *AssetClient) GetSubDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-sub-member-record",
secType: secTypeSigned,
}
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 *AssetClient) GetInternalDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-internal-record",
secType: secTypeSigned,
}
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 *AssetClient) GetMasterDepositAddress(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-address",
secType: secTypeSigned,
}
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 *AssetClient) GetSubDepositAddress(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/deposit/query-sub-member-address",
secType: secTypeSigned,
}
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 *AssetClient) GetCoinInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/coin/query-info",
secType: secTypeSigned,
}
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 *AssetClient) GetWithdrawalAmount(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/withdraw/withdrawable-amount",
secType: secTypeSigned,
}
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 *AssetClient) GetWithdrawalRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/withdraw/query-record",
secType: secTypeSigned,
}
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

@ -268,3 +268,9 @@ func (c *Client) NewAccountServiceNoParams() *AccountClient {
c: c, c: c,
} }
} }
func (c *Client) NewAssetService(params map[string]interface{}) *AssetClient {
return &AssetClient{
c: c,
}
}

View File

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

View File

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

View File

@ -0,0 +1 @@
package user

View File

@ -32,3 +32,226 @@ type SettlementEntry struct {
RealisedPnl string `json:"realisedPnl"` RealisedPnl string `json:"realisedPnl"`
CreatedTime string `json:"createdTime"` CreatedTime string `json:"createdTime"`
} }
type AssetInfo struct {
Spot SpotInfo `json:"spot"`
}
type SpotInfo struct {
Status string `json:"status"`
Assets []AssetItem `json:"assets"`
}
type AssetItem struct {
Coin string `json:"coin"`
Frozen string `json:"frozen"`
Free string `json:"free"`
Withdraw string `json:"withdraw"`
}
type AllCoinsBalance struct {
AccountType string `json:"accountType"`
MemberId string `json:"memberId"`
Balance []BalanceDetail `json:"balance"`
}
type BalanceDetail struct {
Coin string `json:"coin"`
WalletBalance string `json:"walletBalance"`
TransferBalance string `json:"transferBalance"`
Bonus string `json:"bonus"`
}
type SingleCoinBalance struct {
AccountType string `json:"accountType"`
BizType int `json:"bizType"`
AccountId string `json:"accountId"`
MemberId string `json:"memberId"`
Balance CoinBalance `json:"balance"`
}
type CoinBalance struct {
Coin string `json:"coin"`
WalletBalance string `json:"walletBalance"`
TransferBalance string `json:"transferBalance"`
Bonus string `json:"bonus"`
TransferSafeAmount string `json:"transferSafeAmount"`
LtvTransferSafeAmount string `json:"ltvTransferSafeAmount"`
}
type TransferResult struct {
TransferId string `json:"transferId"`
}
type InternalTransferInfo struct {
List []TransferDetail `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}
type TransferDetail struct {
TransferId string `json:"transferId"`
Coin string `json:"coin"`
Amount string `json:"amount"`
FromAccountType string `json:"fromAccountType"`
ToAccountType string `json:"toAccountType"`
Timestamp string `json:"timestamp"`
Status string `json:"status"`
}
type SubUidsInfo struct {
SubMemberIds []string `json:"subMemberIds"`
TransferableSubMemberIds []string `json:"transferableSubMemberIds"`
}
type UniversalTransferInfo struct {
List []UniversalTransferDetail `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}
type UniversalTransferDetail struct {
TransferId string `json:"transferId"`
Coin string `json:"coin"`
Amount string `json:"amount"`
FromMemberId string `json:"fromMemberId"`
ToMemberId string `json:"toMemberId"`
FromAccountType string `json:"fromAccountType"`
ToAccountType string `json:"toAccountType"`
Timestamp string `json:"timestamp"`
Status string `json:"status"`
}
type WithdrawAssetResult struct {
Id string `json:"id"`
}
type CancelWithdrawAssetResult struct {
Status string `json:"status"`
}
type SetDepositAccountResult struct {
Status string `json:"status"`
}
type AllowDepositCoinInfo struct {
ConfigList []DepositCoinConfig `json:"configList"`
NextPageCursor string `json:"nextPageCursor"`
}
type DepositCoinConfig struct {
Coin string `json:"coin"`
Chain string `json:"chain"`
CoinShowName string `json:"coinShowName"`
ChainType string `json:"chainType"`
BlockConfirmNumber int `json:"blockConfirmNumber"`
MinDepositAmount string `json:"minDepositAmount"`
}
type DepositRecords struct {
Rows []DepositRecord `json:"rows"`
NextPageCursor string `json:"nextPageCursor"`
}
type DepositRecord struct {
Coin string `json:"coin"`
Chain string `json:"chain"`
Amount string `json:"amount"`
TxID string `json:"txID"`
Status int `json:"status"`
ToAddress string `json:"toAddress"`
Tag string `json:"tag"`
DepositFee string `json:"depositFee"`
SuccessAt string `json:"successAt"`
Confirmations string `json:"confirmations"`
TxIndex string `json:"txIndex"`
BlockHash string `json:"blockHash"`
BatchReleaseLimit string `json:"batchReleaseLimit"`
DepositType int `json:"depositType"`
}
type SubDepositResult struct {
Coin string `json:"coin"`
Chains []DepositChainInfo `json:"chains"`
}
// MasterDepositResult represents the structure for master deposit results.
type MasterDepositResult struct {
Coin string `json:"coin"`
Chains []DepositChainInfo `json:"chains"`
}
// DepositChainInfo represents the shared structure for deposit chain information.
type DepositChainInfo struct {
ChainType string `json:"chainType"`
AddressDeposit string `json:"addressDeposit"`
TagDeposit string `json:"tagDeposit"`
Chain string `json:"chain"`
BatchReleaseLimit string `json:"batchReleaseLimit"`
}
// CoinInfoResult represents the structure for coin info results.
type CoinInfoResult struct {
Rows []CoinInfoRow `json:"rows"`
}
// CoinInfoRow represents the structure for each row of coin information.
type CoinInfoRow struct {
Name string `json:"name"`
Coin string `json:"coin"`
RemainAmount string `json:"remainAmount"`
Chains []CoinChainInfo `json:"chains"`
}
// CoinChainInfo represents the structure for each chain's information for a coin.
type CoinChainInfo struct {
Chain string `json:"chain"`
ChainType string `json:"chainType"`
Confirmation string `json:"confirmation"`
WithdrawFee string `json:"withdrawFee"`
DepositMin string `json:"depositMin"`
WithdrawMin string `json:"withdrawMin"`
MinAccuracy string `json:"minAccuracy"`
ChainDeposit string `json:"chainDeposit"`
ChainWithdraw string `json:"chainWithdraw"`
WithdrawPercentageFee string `json:"withdrawPercentageFee"`
}
// WithdrawRecords represents the structure for withdrawal records.
type WithdrawRecords struct {
Rows []WithdrawRecord `json:"rows"`
NextPageCursor string `json:"nextPageCursor"`
}
// WithdrawRecord represents the structure for each withdrawal record.
type WithdrawRecord struct {
WithdrawID string `json:"withdrawId"`
TxID string `json:"txID"`
WithdrawType string `json:"withdrawType"`
Coin string `json:"coin"`
Chain string `json:"chain"`
Amount string `json:"amount"`
WithdrawFee string `json:"withdrawFee"`
Status string `json:"status"`
ToAddress string `json:"toAddress"`
Tag string `json:"tag"`
CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"`
}
// WithdrawableAmount represents the structure for information about withdrawable amounts.
type WithdrawableAmount struct {
LimitAmountUsd string `json:"limitAmountUsd"`
WithdrawableAmounts []WithdrawableAsset `json:"withdrawableAmount"`
}
// WithdrawableAsset represents the structure for withdrawable amounts for each wallet type.
type WithdrawableAsset struct {
SPOT *WalletInfo `json:"SPOT,omitempty"` // Omitted if empty
FUND *WalletInfo `json:"FUND,omitempty"` // Omitted if empty
}
// WalletInfo represents the wallet information for withdrawable assets.
type WalletInfo struct {
Coin string `json:"coin"`
WithdrawableAmount string `json:"withdrawableAmount"`
AvailableBalance string `json:"availableBalance"`
}

6
user.go Normal file
View File

@ -0,0 +1,6 @@
package bybit_connector
type UserServiceClient struct {
c *Client
params map[string]interface{}
}