Bybit Official Open API SDK
Go to file
wuhewuhe 3a13a13355 add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
.github/workflows Create go.yml 2023-11-03 14:33:18 +01:00
.idea http public request 2023-10-30 19:26:54 +01:00
examples fix users endpoints and add examples 2023-12-10 15:25:04 +01:00
handlers market endpoints 2023-11-05 22:35:56 +01:00
models spot margin 2023-11-06 14:32:20 +01:00
LICENSE Initial commit 2023-10-30 17:21:04 +01:00
README.md update readme 2023-11-07 00:09:40 +01:00
account.go add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
asset.go asset 2023-11-06 00:44:54 +01:00
broker.go add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
bybit_api_client.go add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
bybit_api_client_test.go tag 1.0.0 2023-11-06 17:29:28 +01:00
bybit_websocket.go add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
consts.go add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
go.mod tag 1.0.0 2023-11-06 17:29:28 +01:00
go.sum add ping interval and maxAlive time option 2023-12-13 00:16:15 +01:00
lending.go lending need to finish response ins 2023-11-06 01:15:59 +01:00
market.go market endpoints 2023-11-05 22:35:56 +01:00
market_klines.go market endpoints 2023-11-05 22:35:56 +01:00
market_test.go tag 1.0.0 2023-11-06 17:29:28 +01:00
place_order.go trade endpoints 2023-11-05 23:18:48 +01:00
position.go account endpoints 2023-11-06 00:16:08 +01:00
pre_upgrade.go preupgrade endpoints 2023-11-05 23:55:41 +01:00
request.go place order post example 2023-11-05 17:33:56 +01:00
spot_leverage.go spot leverage to do spot margin 2023-11-06 12:40:09 +01:00
spot_margin.go spot margin 2023-11-06 14:32:20 +01:00
trade.go position endpoints 2023-11-05 23:42:17 +01:00
user.go fix users endpoints and add examples 2023-12-10 15:25:04 +01:00

README.md

bybit-go-api

GO 1.21.0 Contributor Victor License: MIT

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

💻 📖