bybit_connector

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 21 Imported by: 0

README

bybit-go-api

GO 1.21.0 Contributor Victor

Table of Contents

About

The Official Go Lang API connector for Bybit's HTTP and WebSocket APIs.

Dive into a plethora of functionalities:

  • Market Data Retrieval
  • Trade Execution
  • Position Management
  • Account and Asset Info Retrieval
  • User and Upgrade Management
  • Public Websocket Streaming
  • Private Websocket Streaming
  • Lending Institution and Client
  • Broker Earning Data

bybit-go-api provides an official, robust, and high-performance go connector to Bybit's trading APIs.

Initially conceptualized by go developer Victor, this module is now maintained by Bybit's in-house go experts.

Your contributions are most welcome!

Development

bybit-go-api is under active development with the latest features and updates from Bybit's API implemented promptly. The module utilizes minimal external libraries to provide a lightweight and efficient experience. If you've made enhancements or fixed bugs, please submit a pull request.

Installation

Ensure you have go 1.21.0 or higher. And use dependencies as below

require (
	github.com/google/uuid v1.4.0
	github.com/gorilla/websocket v1.5.1
	github.com/stretchr/testify v1.8.4
)

To import my package you need just to put the link to your go mode file github.com/wuhewuhe/bybit.go.api

Usage

Note: Replace placeholders (like YOUR_API_KEY, links, or other details) with the actual information. You can also customize this template to better fit the actual state and details of your Java API.

Rest API
  • Place an order by Map
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "linear", "symbol": "BTCUSDT", "side": "Buy", "positionIdx": 0, "orderType": "Limit", "qty": "0.001", "price": "10000", "timeInForce": "GTC"}
orderResult, err := client.NewTradeService(params).PlaceOrder(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(bybit.PrettyPrint(orderResult))
  • Place an order by Trade Class
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
orderResult, err := client.NewPlaceOrderService("linear", "XRPUSDT", "Buy", "Market", "10").Do(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(bybit.PrettyPrint(orderResult))
  • Place batch order
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "option",
	"request": []map[string]interface{}{
		{
			"category":    "option",
			"symbol":      "BTC-10FEB23-24000-C",
			"orderType":   "Limit",
			"side":        "Buy",
			"qty":         "0.1",
			"price":       "5",
			"orderIv":     "0.1",
			"timeInForce": "GTC",
			"orderLinkId": "9b381bb1-401",
			"mmp":         false,
			"reduceOnly":  false,
		},
		{
			"category":    "option",
			"symbol":      "BTC-10FEB23-24000-C",
			"orderType":   "Limit",
			"side":        "Buy",
			"qty":         "0.1",
			"price":       "5",
			"orderIv":     "0.1",
			"timeInForce": "GTC",
			"orderLinkId": "82ee86dd-001",
			"mmp":         false,
			"reduceOnly":  false,
		},
	},
}
orderResult, err := client.NewTradeService(params).PlaceBatchOrder(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(bybit.PrettyPrint(orderResult))
  • Get Position
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "linear", "settleCoin": "USDT", "limit": 10}
orderResult, err := client.NewPositionService(params).GetPositionList(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(bybit.PrettyPrint(orderResult))
  • Get Transaction Log
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"accountType": "UNIFIED", "category": "linear"}
accountResult, err := client.NewAccountService(params).GetTransactionLog(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(bybit.PrettyPrint(accountResult))
Websocket public channel
  • Order book Subscribe
ws := bybit.NewBybitPublicWebSocket("wss://stream.bybit.com/v5/public/spot", func(message string) error {
fmt.Println("Received:", message)
return nil
})
_ = ws.Connect([]string{"orderbook.1.BTCUSDT"})
select {}
Websocket private channel
ws := bybit.NewBybitPrivateWebSocket("wss://stream-testnet.bybit.com/v5/private", "YOUR_API_KEY", "YOUR_API_SECRET", func(message string) error {
	fmt.Println("Received:", message)
	return nil
})
_ = ws.Connect([]string{"order"})
select {}

Contact

For support, join our Bybit API community on Telegram.

Contributors

List of other contributors


Victor

💻 📖

Documentation

Index

Constants

View Source
const (
	Name    = "bybit.api.go"
	Version = "1.0.2"
	// Https
	MAINNET       = "https://api.bybit.com"
	MAINNET_BACKT = "https://api.bytick.com"
	TESTNET       = "https://api-testnet.bybit.com"
	// WebSocket public channel - Mainnet
	SPOT_MAINNET    = "wss://stream.bybit.com/v5/public/spot"
	LINEAR_MAINNET  = "wss://stream.bybit.com/v5/public/linear"
	INVERSE_MAINNET = "wss://stream.bybit.com/v5/public/inverse"
	OPTION_MAINNET  = "wss://stream.bybit.com/v5/public/option"

	// WebSocket public channel - Testnet
	SPOT_TESTNET    = "wss://stream-testnet.bybit.com/v5/public/spot"
	LINEAR_TESTNET  = "wss://stream-testnet.bybit.com/v5/public/linear"
	INVERSE_TESTNET = "wss://stream-testnet.bybit.com/v5/public/inverse"
	OPTION_TESTNET  = "wss://stream-testnet.bybit.com/v5/public/option"

	// WebSocket private channel
	WEBSOCKET_PRIVATE_MAINNET = "wss://stream.bybit.com/v5/private"
	WEBSOCKET_PRIVATE_TESTNET = "wss://stream-testnet.bybit.com/v5/private"

	// V3
	V3_CONTRACT_PRIVATE = "wss://stream.bybit.com/contract/private/v3"
	V3_UNIFIED_PRIVATE  = "wss://stream.bybit.com/unified/private/v3"
	V3_SPOT_PRIVATE     = "wss://stream.bybit.com/spot/private/v3"
)

Variables

View Source
var ErrPingFailed = errors.New("failed to send ping")

Functions

func FormatTimestamp

func FormatTimestamp(t time.Time) int64

FormatTimestamp formats a time into Unix timestamp in milliseconds, as requested by Binance.

func GetCurrentTime

func GetCurrentTime() int64

func PrettyPrint

func PrettyPrint(i interface{}) string

Types

type AccountClient

type AccountClient struct {
	// contains filtered or unexported fields
}

func (*AccountClient) GetAccountInfo

func (s *AccountClient) GetAccountInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetAccountWallet

func (s *AccountClient) GetAccountWallet(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetBorrowHistory

func (s *AccountClient) GetBorrowHistory(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetCoinGreeks

func (s *AccountClient) GetCoinGreeks(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetCollateralInfo

func (s *AccountClient) GetCollateralInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetFeeRates

func (s *AccountClient) GetFeeRates(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetMMPState

func (s *AccountClient) GetMMPState(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) GetTransactionLog

func (s *AccountClient) GetTransactionLog(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) ResetMarketMakerProtection

func (s *AccountClient) ResetMarketMakerProtection(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) SetCollateralCoin

func (s *AccountClient) SetCollateralCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) SetMarginMode

func (s *AccountClient) SetMarginMode(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) SetMarketMakerProtection

func (s *AccountClient) SetMarketMakerProtection(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) SetSpotHedgeMode

func (s *AccountClient) SetSpotHedgeMode(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AccountClient) UpgradeToUTA

func (s *AccountClient) UpgradeToUTA(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type AssetClient

type AssetClient struct {
	// contains filtered or unexported fields
}

func (*AssetClient) CancelWithdrawAsset

func (s *AssetClient) CancelWithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) CreateInternalTransfer

func (s *AssetClient) CreateInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) CreateUniversalTransfer

func (s *AssetClient) CreateUniversalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetAllCoinsBalance

func (s *AssetClient) GetAllCoinsBalance(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetAllowedDepositCoin

func (s *AssetClient) GetAllowedDepositCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetAssetInfo

func (s *AssetClient) GetAssetInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetAssetOrderRecord

func (s *AssetClient) GetAssetOrderRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetCoinInfo

func (s *AssetClient) GetCoinInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetDeliveryRecord

func (s *AssetClient) GetDeliveryRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetDepositRecords

func (s *AssetClient) GetDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetInternalDepositRecords

func (s *AssetClient) GetInternalDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetInternalTransfer

func (s *AssetClient) GetInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetMasterDepositAddress

func (s *AssetClient) GetMasterDepositAddress(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetSingleCoinsBalance

func (s *AssetClient) GetSingleCoinsBalance(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetSubDepositAddress

func (s *AssetClient) GetSubDepositAddress(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetSubDepositRecords

func (s *AssetClient) GetSubDepositRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetSubUids

func (s *AssetClient) GetSubUids(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetTransferableCoin

func (s *AssetClient) GetTransferableCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetUniversalTransfer

func (s *AssetClient) GetUniversalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetUsdcSettlement

func (s *AssetClient) GetUsdcSettlement(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetWithdrawalAmount

func (s *AssetClient) GetWithdrawalAmount(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) GetWithdrawalRecords

func (s *AssetClient) GetWithdrawalRecords(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) SetDepositAccount

func (s *AssetClient) SetDepositAccount(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*AssetClient) WithdrawAsset

func (s *AssetClient) WithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type BrokerServiceClient

type BrokerServiceClient struct {
	// contains filtered or unexported fields
}

func (*BrokerServiceClient) GetBrokerAccountInfo

func (s *BrokerServiceClient) GetBrokerAccountInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*BrokerServiceClient) GetBrokerEarning

func (s *BrokerServiceClient) GetBrokerEarning(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type Client

type Client struct {
	APIKey     string
	APISecret  string
	BaseURL    string
	HTTPClient *http.Client
	Debug      bool
	Logger     *log.Logger
	// contains filtered or unexported fields
}

Client define API client

func NewBybitHttpClient

func NewBybitHttpClient(apiKey string, APISecret string, options ...ClientOption) *Client

NewBybitHttpClient NewClient Create client function for initialising new Bybit client

func (*Client) NewAccountService

func (c *Client) NewAccountService(params map[string]interface{}) *AccountClient

func (*Client) NewAccountServiceNoParams

func (c *Client) NewAccountServiceNoParams() *AccountClient

func (*Client) NewAssetService

func (c *Client) NewAssetService(params map[string]interface{}) *AssetClient

func (*Client) NewBrokerService

func (c *Client) NewBrokerService(params map[string]interface{}) *BrokerServiceClient

func (*Client) NewFundingTatesService

func (c *Client) NewFundingTatesService() *MarketFundingRatesService

func (*Client) NewGetDeliveryPriceService

func (c *Client) NewGetDeliveryPriceService() *GetDeliveryPriceService

GetDeliveryPriceService

func (*Client) NewGetHistoricalVolatilityService

func (c *Client) NewGetHistoricalVolatilityService() *GetHistoricalVolatilityService

GetHistoricalVolatilityService

func (*Client) NewGetInsuranceInfoService

func (c *Client) NewGetInsuranceInfoService() *GetInsuranceInfoService

GetInsuranceInfoService

func (*Client) NewGetMarketLSRatioService

func (c *Client) NewGetMarketLSRatioService() *GetMarketLSRatioService

GetMarketLSRatioService

func (*Client) NewGetOpenInterestsService

func (c *Client) NewGetOpenInterestsService() *GetOpenInterestsService

GetOpenInterestsServicdde

func (*Client) NewGetPublicRecentTradesService

func (c *Client) NewGetPublicRecentTradesService() *GetPublicRecentTradesService

func (*Client) NewGetRiskLimitService

func (c *Client) NewGetRiskLimitService() *GetRiskLimitService

GetRiskLimitService

func (*Client) NewGetServerTimeService

func (c *Client) NewGetServerTimeService() *GetServerTimeService

GetServerTimeService

func (*Client) NewInstrumentsInfoService

func (c *Client) NewInstrumentsInfoService() *InstrumentsInfoService

func (*Client) NewLendingService

func (c *Client) NewLendingService(params map[string]interface{}) *LendingServiceClient

func (*Client) NewLendingServiceNoParams

func (c *Client) NewLendingServiceNoParams() *LendingServiceClient

func (*Client) NewMarketIndexPriceKlineService

func (c *Client) NewMarketIndexPriceKlineService() *MarketIndexPriceKlineService

NewMarketIndexPriceKlineService Market Index Price Kline Endpoints

func (*Client) NewMarketKlineService

func (c *Client) NewMarketKlineService() *MarketKlinesService

NewMarketKlineService Market Kline Endpoints

func (*Client) NewMarketMarkPriceKlineService

func (c *Client) NewMarketMarkPriceKlineService() *MarketMarkPriceKlineService

NewMarketMarkPriceKlineService Market Mark Price Kline Endpoints

func (*Client) NewMarketPremiumIndexPriceKlineService

func (c *Client) NewMarketPremiumIndexPriceKlineService() *MarketPremiumIndexPriceKlineService

NewMarketPremiumIndexPriceKlineService Market Premium Index Price Kline Endpoints

func (*Client) NewOrderBookService

func (c *Client) NewOrderBookService() *MarketOrderBookService

func (*Client) NewPlaceOrderService

func (c *Client) NewPlaceOrderService(category, symbol, side, orderType, qty string) *Order

NewPlaceOrderService Trade Endpoints

func (*Client) NewPositionService

func (c *Client) NewPositionService(params map[string]interface{}) *PositionClient

func (*Client) NewPreUpgradeService

func (c *Client) NewPreUpgradeService(params map[string]interface{}) *PreUpgradeClient

func (*Client) NewSpotLeverageService

func (c *Client) NewSpotLeverageService(params map[string]interface{}) *SpotLeverageClient

func (*Client) NewSpotMarginDataService

func (c *Client) NewSpotMarginDataService(params map[string]interface{}, isUta bool) *SpotMarginClient

func (*Client) NewTickersService

func (c *Client) NewTickersService() *MarketTickersService

func (*Client) NewTradeService

func (c *Client) NewTradeService(params map[string]interface{}) *TradeClient

func (*Client) NewUserService

func (c *Client) NewUserService(params map[string]interface{}) *UserServiceClient

func (*Client) NewUserServiceNoParams

func (c *Client) NewUserServiceNoParams() *UserServiceClient

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL is a client option to set the base URL of the Bybit HTTP client.

func WithDebug

func WithDebug(debug bool) ClientOption

WithDebug print more details in debug mode

type GetDeliveryPriceResponse

type GetDeliveryPriceResponse struct {
	RetCode    int                      `json:"retCode"`
	RetMsg     string                   `json:"retMsg"`
	Result     models.DeliveryPriceInfo `json:"result"`
	RetExtInfo struct{}                 `json:"retExtInfo"`
	Time       int64                    `json:"time"`
}

type GetDeliveryPriceService

type GetDeliveryPriceService struct {
	// contains filtered or unexported fields
}

func (*GetDeliveryPriceService) BaseCoin

func (*GetDeliveryPriceService) Category

func (*GetDeliveryPriceService) Cursor

func (*GetDeliveryPriceService) Do

func (*GetDeliveryPriceService) Limit

func (*GetDeliveryPriceService) Symbol

type GetHistoricalVolatilityService

type GetHistoricalVolatilityService struct {
	// contains filtered or unexported fields
}

func (*GetHistoricalVolatilityService) BaseCoin

func (*GetHistoricalVolatilityService) Category

func (*GetHistoricalVolatilityService) Do

func (*GetHistoricalVolatilityService) EndTime

func (*GetHistoricalVolatilityService) Period

func (*GetHistoricalVolatilityService) StartTime

type GetInsuranceInfoResponse

type GetInsuranceInfoResponse struct {
	RetCode    int                        `json:"retCode"`
	RetMsg     string                     `json:"retMsg"`
	Result     models.MarketInsuranceInfo `json:"result"`
	RetExtInfo struct{}                   `json:"retExtInfo"`
	Time       int64                      `json:"time"`
}

type GetInsuranceInfoService

type GetInsuranceInfoService struct {
	// contains filtered or unexported fields
}

func (*GetInsuranceInfoService) Coin

func (*GetInsuranceInfoService) Do

type GetMarketLSRatioResponse

type GetMarketLSRatioResponse struct {
	RetCode    int                             `json:"retCode"`
	RetMsg     string                          `json:"retMsg"`
	Result     models.MarketLongShortRatioInfo `json:"result"`
	RetExtInfo struct{}                        `json:"retExtInfo"`
	Time       int64                           `json:"time"`
}

type GetMarketLSRatioService

type GetMarketLSRatioService struct {
	// contains filtered or unexported fields
}

func (*GetMarketLSRatioService) BaseCoin

func (*GetMarketLSRatioService) Category

func (*GetMarketLSRatioService) Do

func (*GetMarketLSRatioService) Limit

func (*GetMarketLSRatioService) Period

type GetOpenInterestsResponse

type GetOpenInterestsResponse struct {
	RetCode    int                     `json:"retCode"`
	RetMsg     string                  `json:"retMsg"`
	Result     models.OpenInterestInfo `json:"result"`
	RetExtInfo struct{}                `json:"retExtInfo"`
	Time       int64                   `json:"time"`
}

type GetOpenInterestsService

type GetOpenInterestsService struct {
	// contains filtered or unexported fields
}

func (*GetOpenInterestsService) Category

func (*GetOpenInterestsService) Cursor

func (*GetOpenInterestsService) Do

func (*GetOpenInterestsService) EndTime

func (*GetOpenInterestsService) IntervalTime

func (s *GetOpenInterestsService) IntervalTime(intervalTime string) *GetOpenInterestsService

func (*GetOpenInterestsService) Limit

func (*GetOpenInterestsService) StartTime

func (s *GetOpenInterestsService) StartTime(startTime uint64) *GetOpenInterestsService

func (*GetOpenInterestsService) Symbol

type GetPublicRecentTradesResponse

type GetPublicRecentTradesResponse struct {
	RetCode    int                             `json:"retCode"`
	RetMsg     string                          `json:"retMsg"`
	Result     models.PublicRecentTradeHistory `json:"result"`
	RetExtInfo struct{}                        `json:"retExtInfo"`
	Time       int64                           `json:"time"`
}

type GetPublicRecentTradesService

type GetPublicRecentTradesService struct {
	// contains filtered or unexported fields
}

func (*GetPublicRecentTradesService) BaseCoin

func (*GetPublicRecentTradesService) Category

func (*GetPublicRecentTradesService) Do

func (*GetPublicRecentTradesService) Limit

func (*GetPublicRecentTradesService) OptionType

func (*GetPublicRecentTradesService) Symbol

type GetRiskLimitResponse

type GetRiskLimitResponse struct {
	RetCode    int                        `json:"retCode"`
	RetMsg     string                     `json:"retMsg"`
	Result     models.MarketRiskLimitInfo `json:"result"`
	RetExtInfo struct{}                   `json:"retExtInfo"`
	Time       int64                      `json:"time"`
}

type GetRiskLimitService

type GetRiskLimitService struct {
	// contains filtered or unexported fields
}

func (*GetRiskLimitService) Category

func (s *GetRiskLimitService) Category(category models.Category) *GetRiskLimitService

func (*GetRiskLimitService) Do

func (*GetRiskLimitService) Symbol

func (s *GetRiskLimitService) Symbol(symbol string) *GetRiskLimitService

type GetServerTimeResponse

type GetServerTimeResponse struct {
	RetCode    int                     `json:"retCode"`
	RetMsg     string                  `json:"retMsg"`
	Result     models.ServerTimeResult `json:"result"`
	RetExtInfo struct{}                `json:"retExtInfo"`
	Time       int64                   `json:"time"`
}

type GetServerTimeService

type GetServerTimeService struct {
	// contains filtered or unexported fields
}

func (*GetServerTimeService) Do

type InstrumentsInfoService

type InstrumentsInfoService struct {
	// contains filtered or unexported fields
}

func (*InstrumentsInfoService) BaseCoin

func (s *InstrumentsInfoService) BaseCoin(baseCoin string) *InstrumentsInfoService

BaseCoin set baseCoin

func (*InstrumentsInfoService) Category

Category set category

func (*InstrumentsInfoService) Cursor

Cursor set cursor

func (*InstrumentsInfoService) Do

func (*InstrumentsInfoService) Limit

Limit set limit

func (*InstrumentsInfoService) Status

Status set status

func (*InstrumentsInfoService) Symbol

Symbol set symbol

type LendingServiceClient

type LendingServiceClient struct {
	// contains filtered or unexported fields
}

func (*LendingServiceClient) C2cCancelRedeemFunds

func (s *LendingServiceClient) C2cCancelRedeemFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) C2cDepositFunds

func (s *LendingServiceClient) C2cDepositFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) C2cRedeemFunds

func (s *LendingServiceClient) C2cRedeemFunds(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetC2cLendingAccountInfo

func (s *LendingServiceClient) GetC2cLendingAccountInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetC2cLendingCoinInfo

func (s *LendingServiceClient) GetC2cLendingCoinInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetC2cLendingOrders

func (s *LendingServiceClient) GetC2cLendingOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetInsLoanInfo

func (s *LendingServiceClient) GetInsLoanInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetInsLoanOrders

func (s *LendingServiceClient) GetInsLoanOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetInsLoanToValue

func (s *LendingServiceClient) GetInsLoanToValue(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetInsMarginCoinInfo

func (s *LendingServiceClient) GetInsMarginCoinInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*LendingServiceClient) GetInsRepayOrders

func (s *LendingServiceClient) GetInsRepayOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type MarketFundingRatesResponse

type MarketFundingRatesResponse struct {
	RetCode    int                `json:"retCode"`
	RetMsg     string             `json:"retMsg"`
	Result     models.FundingRate `json:"result"`
	RetExtInfo struct{}           `json:"retExtInfo"`
	Time       int64              `json:"time"`
}

type MarketFundingRatesService

type MarketFundingRatesService struct {
	// contains filtered or unexported fields
}

func (*MarketFundingRatesService) Category

func (*MarketFundingRatesService) Do

func (*MarketFundingRatesService) EndTime

func (*MarketFundingRatesService) Limit

func (*MarketFundingRatesService) StartTime

func (*MarketFundingRatesService) Symbol

type MarketIndexPriceKlineService

type MarketIndexPriceKlineService struct {
	// contains filtered or unexported fields
}

MarketIndexPriceKlineService Market index price kline (GET /v5/market/index-price-kline)

func (*MarketIndexPriceKlineService) Category

Category set category

func (*MarketIndexPriceKlineService) Do

func (*MarketIndexPriceKlineService) End

End set endTime

func (*MarketIndexPriceKlineService) Interval

Interval set interval

func (*MarketIndexPriceKlineService) Limit

Limit set limit

func (*MarketIndexPriceKlineService) Start

Start set startTime

func (*MarketIndexPriceKlineService) Symbol

Symbol set symbol

type MarketKlinesService

type MarketKlinesService struct {
	// contains filtered or unexported fields
}

MarketKlinesService Market Kline (GET /v5/market/kline)

func (*MarketKlinesService) Category

func (s *MarketKlinesService) Category(category models.Category) *MarketKlinesService

Category set category

func (*MarketKlinesService) Do

func (*MarketKlinesService) End

End set endTime

func (*MarketKlinesService) Interval

func (s *MarketKlinesService) Interval(interval string) *MarketKlinesService

Interval set interval

func (*MarketKlinesService) Limit

func (s *MarketKlinesService) Limit(limit int) *MarketKlinesService

Limit set limit

func (*MarketKlinesService) Start

func (s *MarketKlinesService) Start(startTime uint64) *MarketKlinesService

Start set startTime

func (*MarketKlinesService) Symbol

func (s *MarketKlinesService) Symbol(symbol string) *MarketKlinesService

Symbol set symbol

type MarketMarkPriceKlineService

type MarketMarkPriceKlineService struct {
	// contains filtered or unexported fields
}

MarketMarkPriceKlineService Market mark price kline (GET /v5/market/mark-price-kline)

func (*MarketMarkPriceKlineService) Category

Category set category

func (*MarketMarkPriceKlineService) Do

func (*MarketMarkPriceKlineService) End

End set endTime

func (*MarketMarkPriceKlineService) Interval

Interval set interval

func (*MarketMarkPriceKlineService) Limit

Limit set limit

func (*MarketMarkPriceKlineService) Start

Start set startTime

func (*MarketMarkPriceKlineService) Symbol

Symbol set symbol

type MarketOrderBookResponse

type MarketOrderBookResponse struct {
	RetCode    int                  `json:"retCode"`
	RetMsg     string               `json:"retMsg"`
	Result     models.OrderBookInfo `json:"result"`
	RetExtInfo struct{}             `json:"retExtInfo"`
	Time       int64                `json:"time"`
}

type MarketOrderBookService

type MarketOrderBookService struct {
	// contains filtered or unexported fields
}

func (*MarketOrderBookService) Category

Category set category

func (*MarketOrderBookService) Do

func (*MarketOrderBookService) Limit

func (*MarketOrderBookService) Symbol

Symbol set symbol

type MarketPremiumIndexPriceKlineService

type MarketPremiumIndexPriceKlineService struct {
	// contains filtered or unexported fields
}

MarketPremiumIndexPriceKlineService Market premium index price kline (GET /v5/market/premium-index-price-kline)

func (*MarketPremiumIndexPriceKlineService) Category

Category set category

func (*MarketPremiumIndexPriceKlineService) Do

func (*MarketPremiumIndexPriceKlineService) End

End set endTime

func (*MarketPremiumIndexPriceKlineService) Interval

Interval set interval

func (*MarketPremiumIndexPriceKlineService) Limit

Limit set limit

func (*MarketPremiumIndexPriceKlineService) Start

Start set startTime

func (*MarketPremiumIndexPriceKlineService) Symbol

Symbol set symbol

type MarketTickersResponse

type MarketTickersResponse struct {
	RetCode    int                  `json:"retCode"`
	RetMsg     string               `json:"retMsg"`
	Result     models.MarketTickers `json:"result"`
	RetExtInfo struct{}             `json:"retExtInfo"`
	Time       int64                `json:"time"`
}

type MarketTickersService

type MarketTickersService struct {
	// contains filtered or unexported fields
}

func (*MarketTickersService) BaseCoin

func (s *MarketTickersService) BaseCoin(baseCoin string) *MarketTickersService

func (*MarketTickersService) Category

func (*MarketTickersService) Do

func (*MarketTickersService) ExpDate

func (s *MarketTickersService) ExpDate(expDate string) *MarketTickersService

func (*MarketTickersService) Symbol

type MessageHandler

type MessageHandler func(message string) error

type Order

type Order struct {
	// contains filtered or unexported fields
}

func (*Order) CloseOnTrigger

func (order *Order) CloseOnTrigger(close bool) *Order

func (*Order) Do

func (order *Order) Do(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*Order) IsLeverage

func (order *Order) IsLeverage(isLeverage int) *Order

func (*Order) Mmp

func (order *Order) Mmp(mmp bool) *Order

func (*Order) OrderFilter

func (order *Order) OrderFilter(filter string) *Order

func (*Order) OrderIv

func (order *Order) OrderIv(iv string) *Order

func (*Order) OrderLinkId

func (order *Order) OrderLinkId(orderLinkId string) *Order

func (*Order) PositionIdx

func (order *Order) PositionIdx(idx int) *Order

func (*Order) Price

func (order *Order) Price(price string) *Order

func (*Order) ReduceOnly

func (order *Order) ReduceOnly(reduce bool) *Order

func (*Order) SlLimitPrice

func (order *Order) SlLimitPrice(price string) *Order

func (*Order) SlOrderType

func (order *Order) SlOrderType(orderType string) *Order

func (*Order) SlTriggerBy

func (order *Order) SlTriggerBy(triggerBy string) *Order

func (*Order) SmpType

func (order *Order) SmpType(smp string) *Order

func (*Order) StopLoss

func (order *Order) StopLoss(loss string) *Order

func (*Order) TakeProfit

func (order *Order) TakeProfit(profit string) *Order

func (*Order) TimeInForce

func (order *Order) TimeInForce(tif string) *Order

func (*Order) TpLimitPrice

func (order *Order) TpLimitPrice(price string) *Order

func (*Order) TpOrderType

func (order *Order) TpOrderType(orderType string) *Order

func (*Order) TpTriggerBy

func (order *Order) TpTriggerBy(triggerBy string) *Order

func (*Order) TpslMode

func (order *Order) TpslMode(mode string) *Order

func (*Order) TriggerBy

func (order *Order) TriggerBy(triggerBy string) *Order

func (*Order) TriggerDirection

func (order *Order) TriggerDirection(direction int) *Order

func (*Order) TriggerPrice

func (order *Order) TriggerPrice(triggerPrice string) *Order

type PositionClient

type PositionClient struct {
	// contains filtered or unexported fields
}

func (*PositionClient) ConfirmPositionRiskLimit

func (s *PositionClient) ConfirmPositionRiskLimit(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) GetClosePnl

func (s *PositionClient) GetClosePnl(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) GetExecutionList

func (s *PositionClient) GetExecutionList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) GetPositionList

func (s *PositionClient) GetPositionList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SetPositionAutoMargin

func (s *PositionClient) SetPositionAutoMargin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SetPositionLeverage

func (s *PositionClient) SetPositionLeverage(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SetPositionRiskLimit

func (s *PositionClient) SetPositionRiskLimit(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SetPositionTpslMode

func (s *PositionClient) SetPositionTpslMode(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SetPositionTradingStop

func (s *PositionClient) SetPositionTradingStop(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SwitchPositionMargin

func (s *PositionClient) SwitchPositionMargin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) SwitchPositionMode

func (s *PositionClient) SwitchPositionMode(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PositionClient) UpdatePositionMargin

func (s *PositionClient) UpdatePositionMargin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type PreUpgradeClient

type PreUpgradeClient struct {
	// contains filtered or unexported fields
}

func (*PreUpgradeClient) GetPreUpgradeClosedPnl

func (s *PreUpgradeClient) GetPreUpgradeClosedPnl(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PreUpgradeClient) GetPreUpgradeExecutionList

func (s *PreUpgradeClient) GetPreUpgradeExecutionList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PreUpgradeClient) GetPreUpgradeOptionDeliveryRecord

func (s *PreUpgradeClient) GetPreUpgradeOptionDeliveryRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PreUpgradeClient) GetPreUpgradeOrderHistory

func (s *PreUpgradeClient) GetPreUpgradeOrderHistory(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PreUpgradeClient) GetPreUpgradeTransactionLog

func (s *PreUpgradeClient) GetPreUpgradeTransactionLog(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*PreUpgradeClient) GetPreUpgradeUsdcSettlement

func (s *PreUpgradeClient) GetPreUpgradeUsdcSettlement(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type RequestOption

type RequestOption func(*request)

RequestOption define option type for request

func WithRecvWindow

func WithRecvWindow(recvWindow string) RequestOption

WithRecvWindow Append `WithRecvWindow(insert_recvWindow)` to request to modify the default recvWindow value

type ServerResponse

type ServerResponse struct {
	RetCode    int         `json:"retCode"`
	RetMsg     string      `json:"retMsg"`
	Result     interface{} `json:"result"`
	RetExtInfo struct{}    `json:"retExtInfo"`
	Time       int64       `json:"time"`
}

type SpotLeverageClient

type SpotLeverageClient struct {
	// contains filtered or unexported fields
}

func (*SpotLeverageClient) GetLeverageTokenInfo

func (s *SpotLeverageClient) GetLeverageTokenInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotLeverageClient) GetLeverageTokenMarket

func (s *SpotLeverageClient) GetLeverageTokenMarket(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotLeverageClient) GetLeverageTokenOrders

func (s *SpotLeverageClient) GetLeverageTokenOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotLeverageClient) PurchaseLeverageToken

func (s *SpotLeverageClient) PurchaseLeverageToken(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotLeverageClient) RedeemLeverageToken

func (s *SpotLeverageClient) RedeemLeverageToken(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type SpotMarginClient

type SpotMarginClient struct {
	// contains filtered or unexported fields
}

func (*SpotMarginClient) BorrowSpotMarginLoan

func (s *SpotMarginClient) BorrowSpotMarginLoan(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginBorrowCoin

func (s *SpotMarginClient) GetSpotMarginBorrowCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginBorrowOrders

func (s *SpotMarginClient) GetSpotMarginBorrowOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginCoin

func (s *SpotMarginClient) GetSpotMarginCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginData

func (s *SpotMarginClient) GetSpotMarginData(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginInterests

func (s *SpotMarginClient) GetSpotMarginInterests(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginLoanAccountInfo

func (s *SpotMarginClient) GetSpotMarginLoanAccountInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginRepaymentOrders

func (s *SpotMarginClient) GetSpotMarginRepaymentOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) GetSpotMarginState

func (s *SpotMarginClient) GetSpotMarginState(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) RepaySpotMarginLoan

func (s *SpotMarginClient) RepaySpotMarginLoan(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) SetSpotMarginLeverage

func (s *SpotMarginClient) SetSpotMarginLeverage(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*SpotMarginClient) ToggleSpotMarginTrade

func (s *SpotMarginClient) ToggleSpotMarginTrade(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type TradeClient

type TradeClient struct {
	// contains filtered or unexported fields
}

func (*TradeClient) AmendBatchOrder

func (s *TradeClient) AmendBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error)

func (*TradeClient) AmendOrder

func (s *TradeClient) AmendOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) CancelAllOrders

func (s *TradeClient) CancelAllOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) CancelBatchOrder

func (s *TradeClient) CancelBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error)

func (*TradeClient) CancelOrder

func (s *TradeClient) CancelOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) GetOpenOrders

func (s *TradeClient) GetOpenOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) GetOrderHistory

func (s *TradeClient) GetOrderHistory(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) GetSpotBorrowQuota

func (s *TradeClient) GetSpotBorrowQuota(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) PlaceBatchOrder

func (s *TradeClient) PlaceBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error)

func (*TradeClient) PlaceOrder

func (s *TradeClient) PlaceOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*TradeClient) SetDisconnectCancelAll

func (s *TradeClient) SetDisconnectCancelAll(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type UserServiceClient

type UserServiceClient struct {
	// contains filtered or unexported fields
}

func (*UserServiceClient) CreateSubApiKey

func (s *UserServiceClient) CreateSubApiKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) CreateSubMember

func (s *UserServiceClient) CreateSubMember(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) DeleteMasterAPIKey

func (s *UserServiceClient) DeleteMasterAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) DeleteSubAPIKey

func (s *UserServiceClient) DeleteSubAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) DeleteSubUID

func (s *UserServiceClient) DeleteSubUID(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) FreezeSubUID

func (s *UserServiceClient) FreezeSubUID(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) GetAPIKeyInfo

func (s *UserServiceClient) GetAPIKeyInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) GetAffiliateUserInfo

func (s *UserServiceClient) GetAffiliateUserInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) GetSubUidList

func (s *UserServiceClient) GetSubUidList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) GetUidWalletType

func (s *UserServiceClient) GetUidWalletType(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) ModifyMasterAPIKey

func (s *UserServiceClient) ModifyMasterAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

func (*UserServiceClient) ModifySubAPIKey

func (s *UserServiceClient) ModifySubAPIKey(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error)

type WebSocket

type WebSocket struct {
	// contains filtered or unexported fields
}

func NewBybitPrivateWebSocket

func NewBybitPrivateWebSocket(url, apiKey, apiSecret string, handler MessageHandler, options ...WebsocketOption) *WebSocket

func NewBybitPublicWebSocket

func NewBybitPublicWebSocket(url string, pingInterval int, handler MessageHandler, options ...WebsocketOption) *WebSocket

func (*WebSocket) Connect

func (b *WebSocket) Connect(args []string) error

func (*WebSocket) Disconnect

func (b *WebSocket) Disconnect() error

func (*WebSocket) Ping added in v1.0.4

func (b *WebSocket) Ping() error

func (*WebSocket) Send

func (b *WebSocket) Send(message string) error

func (*WebSocket) SendAsJson

func (b *WebSocket) SendAsJson(v interface{}) error

func (*WebSocket) SetMessageHandler

func (b *WebSocket) SetMessageHandler(handler MessageHandler)

type WebsocketOption

type WebsocketOption func(*WebSocket)

func WithMaxAliveTime

func WithMaxAliveTime(maxAliveTime string) WebsocketOption

func WithPingInterval

func WithPingInterval(pingInterval int) WebsocketOption

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL