bybit_connector

package module
v0.0.0-...-097e613 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 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
  • Institution Loan
  • Broker

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!

Release

  • refactor all the project
  • Market endpoints:
    • add server response adapter
  • Position endpoints:
    • SetPositionRiskLimit is deprecated;
    • SetPositionTpslMode is deprecated.
    • Add move position and history
  • trade
    • Rename v5/execution/list to trade history
  • account
    • Add transaction log to classical user
    • Get DCP Info
    • New endpoint /v5/account/smp-group
  • demo trading
    • Add request coin endpoint
  • asset
    • Add Get Convert Coin List
    • Add Request a Quote
    • Add Confirm a Quote
    • Add Get Convert Status
    • Add Get Convert history
  • user
    • Query unlimited sub members
  • spot margin uta
    • GetSpotMarginCoin is deprecated.
    • GetSpotMarginBorrowCoin is deprecated.
    • GetSpotMarginLoanAccountInfo is deprecated.
    • GetSpotMarginBorrowOrders is deprecated.
    • GetSpotMarginRepaymentOrders is deprecated.
    • BorrowSpotMarginLoan is deprecated.
    • RepaySpotMarginLoan is deprecated.
    • Add spot margin uta interest history
  • ins
    • GetC2cLendingAccountInfo is deprecated.
    • GetC2cLendingOrders is deprecated.
    • GetC2cLendingCoinInfo is deprecated.
    • C2cCancelRedeemFunds is deprecated.
    • C2cRedeemFunds is deprecated.
    • C2cDepositFunds is deprecated.
    • Add associate ins loan id
  • broker
    • Add Get Sub Account Deposit Records

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.NewUtaBybitServiceWithParams(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.NewUtaBybitServiceWithParams(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.NewUtaBybitServiceWithParams(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.NewUtaBybitServiceWithParams(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.4"
	// Https
	MAINNET       = "https://api.bybit.com"
	MAINNET_BACKT = "https://api.bytick.com"
	TESTNET       = "https://api-testnet.bybit.com"
	DEMO_ENV      = "https://api-demo.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_TRADE_MAINNET   = "wss://stream.bybit.com/v5/trade"
	WEBSOCKET_PRIVATE_TESTNET = "wss://stream-testnet.bybit.com/v5/private"
	WEBSOCKET_TRADE_TESTNET   = "wss://stream-testnet.bybit.com/v5/trade"
	WEBSOCKET_PRIVATE_DEMO    = "wss://wss://stream-demo.bybit.com/v5/private"
	WEBSOCKET_TRADE_DEMO      = "wss://wss://stream-demo.bybit.com/v5/trade"

	// Deprecated: V3 is deprecated and replaced by v5
	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

This section is empty.

Functions

func FormatTimestamp

func FormatTimestamp(t time.Time) int64

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

func GetBatchOrderServerResponse

func GetBatchOrderServerResponse(err error, data []byte) (*models.BatchOrderServerResponse, error)

func GetCurrentTime

func GetCurrentTime() int64

func PrettyPrint

func PrettyPrint(i interface{}) string

func SendRequest

func SendRequest(ctx context.Context, opts []RequestOption, r *request, s *BybitClientRequest, err error) []byte

Types

type BybitClientRequest

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

func (*BybitClientRequest) AmendBatchOrder

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

func (*BybitClientRequest) AmendOrder

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

func (*BybitClientRequest) AssociateInsLoan

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

func (*BybitClientRequest) BorrowSpotMarginLoan deprecated

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

Deprecated: BorrowSpotMarginLoan is deprecated.

func (*BybitClientRequest) C2cCancelRedeemFunds deprecated

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

Deprecated: C2cCancelRedeemFunds is deprecated.

func (*BybitClientRequest) C2cDepositFunds deprecated

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

Deprecated: C2cDepositFunds is deprecated.

func (*BybitClientRequest) C2cRedeemFunds deprecated

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

Deprecated: C2cRedeemFunds is deprecated.

func (*BybitClientRequest) CancelAllOrders

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

func (*BybitClientRequest) CancelBatchOrder

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

func (*BybitClientRequest) CancelOrder

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

func (*BybitClientRequest) CancelWithdraw

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

func (*BybitClientRequest) ConfirmConvertQuote

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

func (*BybitClientRequest) ConfirmPositionRiskLimit

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

func (*BybitClientRequest) CreateInternalTransfer

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

func (*BybitClientRequest) CreateSubApiKey

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

func (*BybitClientRequest) CreateSubMember

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

func (*BybitClientRequest) CreateUniversalTransfer

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

func (*BybitClientRequest) CreateWithdraw

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

func (*BybitClientRequest) DeleteMasterAPIKey

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

func (*BybitClientRequest) DeleteSubAPIKey

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

func (*BybitClientRequest) DeleteSubUID

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

func (*BybitClientRequest) FreezeSubUID

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

func (*BybitClientRequest) GetAPIKeyInfo

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

func (*BybitClientRequest) GetAccountInfo

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

func (*BybitClientRequest) GetAccountWallet

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

func (*BybitClientRequest) GetAffiliateUserInfo

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

func (*BybitClientRequest) GetAllCoinsBalance

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

func (*BybitClientRequest) GetAllSubMembersDepositRecords

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

func (*BybitClientRequest) GetAllowedDepositCoin

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

func (*BybitClientRequest) GetAssetInfo

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

func (*BybitClientRequest) GetAssetOrderRecord

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

func (*BybitClientRequest) GetBorrowHistory

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

func (*BybitClientRequest) GetBrokerAccountInfo

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

func (*BybitClientRequest) GetBrokerEarning

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

func (*BybitClientRequest) GetC2cLendingAccountInfo deprecated

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

Deprecated: GetC2cLendingAccountInfo is deprecated.

func (*BybitClientRequest) GetC2cLendingCoinInfo deprecated

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

Deprecated: GetC2cLendingCoinInfo is deprecated.

func (*BybitClientRequest) GetC2cLendingOrders deprecated

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

Deprecated: GetC2cLendingOrders is deprecated.

func (*BybitClientRequest) GetClosePnl

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

func (*BybitClientRequest) GetCoinGreeks

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

func (*BybitClientRequest) GetCoinInfo

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

func (*BybitClientRequest) GetCollateralInfo

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

func (*BybitClientRequest) GetConvertCoinList

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

func (*BybitClientRequest) GetConvertHistory

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

func (*BybitClientRequest) GetConvertStatus

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

func (*BybitClientRequest) GetDeliveryPrice

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

func (*BybitClientRequest) GetDeliveryRecord

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

func (*BybitClientRequest) GetDepositRecords

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

func (*BybitClientRequest) GetDisconnectProtectionInfo

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

func (*BybitClientRequest) GetFeeRates

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

func (*BybitClientRequest) GetFundingRateHistory

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

func (*BybitClientRequest) GetHistoryVolatility

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

func (*BybitClientRequest) GetIndexPriceKline

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

func (*BybitClientRequest) GetInsLoanInfo

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

func (*BybitClientRequest) GetInsLoanOrders

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

func (*BybitClientRequest) GetInsLoanToValue

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

func (*BybitClientRequest) GetInsMarginCoinInfo

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

func (*BybitClientRequest) GetInsRepayOrders

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

func (*BybitClientRequest) GetInstrumentInfo

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

func (*BybitClientRequest) GetInternalDepositRecords

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

func (*BybitClientRequest) GetInternalTransferRecords

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

func (*BybitClientRequest) GetLeverageTokenInfo

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

func (*BybitClientRequest) GetLeverageTokenMarket

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

func (*BybitClientRequest) GetLeverageTokenOrders

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

func (*BybitClientRequest) GetLongShortRatio

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

func (*BybitClientRequest) GetMMPState

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

func (*BybitClientRequest) GetMarkPriceKline

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

func (*BybitClientRequest) GetMarketInsurance

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

func (*BybitClientRequest) GetMarketKline

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

func (*BybitClientRequest) GetMarketRiskLimits

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

func (*BybitClientRequest) GetMarketTickers

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

func (*BybitClientRequest) GetMasterAccDepositAddress

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

func (*BybitClientRequest) GetMovePositionHistory

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

func (*BybitClientRequest) GetOpenInterests

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

func (*BybitClientRequest) GetOpenOrders

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

func (*BybitClientRequest) GetOrderBookInfo

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

func (*BybitClientRequest) GetOrderHistory

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

func (*BybitClientRequest) GetPositionList

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

func (*BybitClientRequest) GetPreUpgradeClosedPnl

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

func (*BybitClientRequest) GetPreUpgradeOptionDeliveryRecord

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

func (*BybitClientRequest) GetPreUpgradeOrderHistory

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

func (*BybitClientRequest) GetPreUpgradeTradeHistory

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

func (*BybitClientRequest) GetPreUpgradeTransactionLog

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

func (*BybitClientRequest) GetPreUpgradeUsdcSettlement

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

func (*BybitClientRequest) GetPremiumIndexPriceKline

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

func (*BybitClientRequest) GetPublicRecentTrades

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

func (*BybitClientRequest) GetSelfMarketProtectionGroup

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

func (*BybitClientRequest) GetServerTime

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

func (*BybitClientRequest) GetSingleCoinsBalance

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

func (*BybitClientRequest) GetSpotBorrowQuota

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

func (*BybitClientRequest) GetSpotMarginBorrowCoin deprecated

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

Deprecated: GetSpotMarginBorrowCoin is deprecated.

func (*BybitClientRequest) GetSpotMarginBorrowOrders deprecated

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

Deprecated: GetSpotMarginBorrowOrders is deprecated.

func (*BybitClientRequest) GetSpotMarginCoin deprecated

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

Deprecated: GetSpotMarginCoin is deprecated.

func (*BybitClientRequest) GetSpotMarginData

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

func (*BybitClientRequest) GetSpotMarginInterests

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

func (*BybitClientRequest) GetSpotMarginLoanAccountInfo deprecated

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

Deprecated: GetSpotMarginLoanAccountInfo is deprecated.

func (*BybitClientRequest) GetSpotMarginRepaymentOrders deprecated

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

Deprecated: GetSpotMarginRepaymentOrders is deprecated.

func (*BybitClientRequest) GetSpotMarginState

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

func (*BybitClientRequest) GetSubAccDepositAddress

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

func (*BybitClientRequest) GetSubAccUids

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

func (*BybitClientRequest) GetSubMemberDepositRecords

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

func (*BybitClientRequest) GetSubUidList

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

func (*BybitClientRequest) GetSubUidListUnlimited

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

func (*BybitClientRequest) GetTradeHistory

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

func (*BybitClientRequest) GetTransactionLog

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

func (*BybitClientRequest) GetTransferableCoin

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

func (*BybitClientRequest) GetUidWalletType

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

func (*BybitClientRequest) GetUniversalTransferRecords

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

func (*BybitClientRequest) GetUsdcSettlement

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

func (*BybitClientRequest) GetWithdrawalAmount

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

func (*BybitClientRequest) GetWithdrawalRecords

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

func (*BybitClientRequest) ModifyMasterAPIKey

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

func (*BybitClientRequest) ModifySubAPIKey

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

func (*BybitClientRequest) MovePosition

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

func (*BybitClientRequest) PlaceBatchOrder

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

func (*BybitClientRequest) PlaceOrder

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

func (*BybitClientRequest) PurchaseLeverageToken

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

func (*BybitClientRequest) RedeemLeverageToken

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

func (*BybitClientRequest) RepaySpotMarginLoan deprecated

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

Deprecated: RepaySpotMarginLoan is deprecated.

func (*BybitClientRequest) RequestConvertQuote

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

func (*BybitClientRequest) RequestTestFund

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

func (*BybitClientRequest) ResetMarketMakerProtection

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

func (*BybitClientRequest) SetCollateralCoin

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

func (*BybitClientRequest) SetDepositAccount

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

func (*BybitClientRequest) SetDisconnectCancelAll

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

func (*BybitClientRequest) SetMarginMode

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

func (*BybitClientRequest) SetMarketMakerProtection

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

func (*BybitClientRequest) SetPositionAutoMargin

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

func (*BybitClientRequest) SetPositionLeverage

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

func (*BybitClientRequest) SetPositionRiskLimit deprecated

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

Deprecated: SetPositionRiskLimit is deprecated. Since bybit has launched auto risk limit depends on current leverage

func (*BybitClientRequest) SetPositionTpslMode deprecated

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

Deprecated: SetPositionTpslMode is deprecated. now tpsl is based on order level

func (*BybitClientRequest) SetPositionTradingStop

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

func (*BybitClientRequest) SetSpotHedgeMode

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

func (*BybitClientRequest) SetSpotMarginLeverage

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

func (*BybitClientRequest) SwitchPositionMargin

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

func (*BybitClientRequest) SwitchPositionMode

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

func (*BybitClientRequest) ToggleSpotMarginTrade

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

func (*BybitClientRequest) UpdatePositionMargin

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

func (*BybitClientRequest) UpgradeToUTA

func (s *BybitClientRequest) UpgradeToUTA(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

	ProxyURL string
	// 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) NewClassicalBybitServiceNoParams

func (c *Client) NewClassicalBybitServiceNoParams() *BybitClientRequest

func (*Client) NewClassicalBybitServiceWithParams

func (c *Client) NewClassicalBybitServiceWithParams(params map[string]interface{}) *BybitClientRequest

func (*Client) NewPlaceOrderService

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

NewPlaceOrderService quick order endpoint

func (*Client) NewUtaBybitServiceNoParams

func (c *Client) NewUtaBybitServiceNoParams() *BybitClientRequest

func (*Client) NewUtaBybitServiceWithParams

func (c *Client) NewUtaBybitServiceWithParams(params map[string]interface{}) *BybitClientRequest

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

func WithProxyURL

func WithProxyURL(proxyURL string) ClientOption

WithProxyURL is a client option to set the proxy url

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 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"`
}

func GetServerResponse

func GetServerResponse(err error, data []byte) (*ServerResponse, 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, handler MessageHandler) *WebSocket

func (*WebSocket) Connect

func (b *WebSocket) Connect() *WebSocket

func (*WebSocket) Disconnect

func (b *WebSocket) Disconnect() error

func (*WebSocket) IsConnected

func (b *WebSocket) IsConnected() bool

func (*WebSocket) ReConnect

func (b *WebSocket) ReConnect()

func (*WebSocket) SendSubscription

func (b *WebSocket) SendSubscription(args []string) (*WebSocket, 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

Jump to

Keyboard shortcuts

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