Skip to content

Commit

Permalink
feat: add docs for implemented methods (#25)
Browse files Browse the repository at this point in the history
* added doc for spot

* add documentation for spot and linear

* completed with docs for implemented methods
  • Loading branch information
cksidharthan authored Aug 25, 2022
1 parent 3e8da4f commit 091cb77
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func (c *Client) InversePerpetual() inverseperp.Client {
return c.inversePerpetual
}

// NewRestClient - creates a new bybit rest client
// docs - https://bybit-exchange.github.io/docs/spot/#t-introduction
func NewRestClient(url, apiKey, apiSecret string) *Client {
return &Client{
spot: *spot.NewSpotClient(url, apiKey, apiSecret),
Expand Down
3 changes: 3 additions & 0 deletions rest/inverse_perpetual/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (c *Client) Wallet() inverseperp.WalletInterface {
return c.wallet
}

// NewInversePerpetualClient - create a new inverse perpetual client.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-introduction
func NewInversePerpetualClient(url, apiKey, apiSecret string) *Client {
return &Client{
market: market.NewInversePerpetualMarketClient(url, apiKey, apiSecret),
Expand Down
3 changes: 3 additions & 0 deletions rest/inverse_perpetual/market/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type InversePerpetualMarketClient struct {
transporter transport.Transporter
}

// NewInversePerpetualMarketClient - create a new inverse perpetual market client.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-marketdata
func NewInversePerpetualMarketClient(url, apiKey, apiSecret string) *InversePerpetualMarketClient {
transporter := httpTransport.New(url, apiKey, apiSecret)
return &InversePerpetualMarketClient{
Expand Down
43 changes: 43 additions & 0 deletions rest/inverse_perpetual/market/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
inverseperp "github.com/cksidharthan/go-bybit/rest/domain/inverse_perpetual"
)

// OrderBook - get order book. [ /v2/public/orderBook/L2 - GET ]
//
// Get the orderbook. Each side has a depth of 25.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-orderbook
func (c *InversePerpetualMarketClient) OrderBook(ctx context.Context, params *inverseperp.OrderBookParams) (response *inverseperp.OrderBookResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualOrderBookPath, params, &response)
if err != nil {
Expand All @@ -16,6 +21,9 @@ func (c *InversePerpetualMarketClient) OrderBook(ctx context.Context, params *in
return
}

// QueryKline - get kline data. [ /v2/public/kline/list - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-querykline
func (c *InversePerpetualMarketClient) QueryKline(ctx context.Context, params *inverseperp.QueryKlineParams) (response *inverseperp.QueryKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualQueryKlinePath, params, &response)
if err != nil {
Expand All @@ -24,6 +32,9 @@ func (c *InversePerpetualMarketClient) QueryKline(ctx context.Context, params *i
return
}

// GetSymbolInformation - get latest symbol information. [ /v2/public/tickers - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-latestsymbolinfo
func (c *InversePerpetualMarketClient) GetSymbolInformation(ctx context.Context, params *inverseperp.GetSymbolInformationParams) (response *inverseperp.GetSymbolInformationResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualSymbolInformationPath, params, &response)
if err != nil {
Expand All @@ -32,6 +43,9 @@ func (c *InversePerpetualMarketClient) GetSymbolInformation(ctx context.Context,
return
}

// PublicTradingRecords - get public trading records. [ /v2/public/trading-records - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-publictradingrecords
func (c *InversePerpetualMarketClient) PublicTradingRecords(ctx context.Context, params *inverseperp.PublicTradingRecordsParams) (response *inverseperp.PublicTradingRecordsResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualPublicTradingRecordsPath, params, &response)
if err != nil {
Expand All @@ -40,6 +54,9 @@ func (c *InversePerpetualMarketClient) PublicTradingRecords(ctx context.Context,
return
}

// QuerySymbols - get symbols. [ /v2/public/symbols - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-querysymbol
func (c *InversePerpetualMarketClient) QuerySymbols(ctx context.Context) (response *inverseperp.QuerySymbolsResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualQuerySymbolPath, nil, &response)
if err != nil {
Expand All @@ -48,6 +65,9 @@ func (c *InversePerpetualMarketClient) QuerySymbols(ctx context.Context) (respon
return
}

// QueryMarkPriceKline - Query mark price kline (like Query Kline but for mark price). [ /v2/public/mark-price-kline - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-markpricekline
func (c *InversePerpetualMarketClient) QueryMarkPriceKline(ctx context.Context, params *inverseperp.QueryMarkPriceKlineParams) (response *inverseperp.QueryMarkPriceKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualQueryMarkPriceKlinePath, params, &response)
if err != nil {
Expand All @@ -56,6 +76,9 @@ func (c *InversePerpetualMarketClient) QueryMarkPriceKline(ctx context.Context,
return
}

// QueryIndexPriceKline - Index price kline. Tracks BTC spot prices, with a frequency of every second [ /v2/public/index-price-kline - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-queryindexpricekline
func (c *InversePerpetualMarketClient) QueryIndexPriceKline(ctx context.Context, params *inverseperp.QueryIndexPriceKlineParams) (response *inverseperp.QueryIndexPriceKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualQueryIndexPriceKlinePath, params, &response)
if err != nil {
Expand All @@ -64,6 +87,11 @@ func (c *InversePerpetualMarketClient) QueryIndexPriceKline(ctx context.Context,
return
}

// QueryPremiumIndexKline - Query premium index kline. [ /v2/public/premium-index-kline - GET ]
//
// Premium index kline. Tracks the premium / discount of BTC perpetual contracts relative to the mark price per minute
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-querypremiumindexkline
func (c *InversePerpetualMarketClient) QueryPremiumIndexKline(ctx context.Context, params *inverseperp.QueryPremiumIndexKlineParams) (response *inverseperp.QueryPremiumIndexKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualQueryPremiumIndexKlinePath, params, &response)
if err != nil {
Expand All @@ -72,6 +100,11 @@ func (c *InversePerpetualMarketClient) QueryPremiumIndexKline(ctx context.Contex
return
}

// OpenInterest - get open interest. [ /v2/public/open-interest - GET ]
//
// Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-marketopeninterest
func (c *InversePerpetualMarketClient) OpenInterest(ctx context.Context, params *inverseperp.OpenInterestParams) (response *inverseperp.OpenInterestResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualOrderBookPath, params, &response)
if err != nil {
Expand All @@ -80,6 +113,13 @@ func (c *InversePerpetualMarketClient) OpenInterest(ctx context.Context, params
return
}

// LatestBigDeal - get latest big deal. [ /v2/public/big-deal - GET ]
//
// Obtain filled orders worth more than 500,000 USD within the last 24h.
//
// This endpoint may return orders which are over the maximum order qty for the symbol you call. For instance, the maximum order qty for BTCUSD is 1 million contracts, but in the event of the liquidation of a position larger than 1 million this endpoint returns this "impossible" order size.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-marketbigdeal
func (c *InversePerpetualMarketClient) LatestBigDeal(ctx context.Context, params *inverseperp.LatestBigDealParams) (response *inverseperp.LatestBigDealResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualLatestBigDealPath, params, &response)
if err != nil {
Expand All @@ -88,6 +128,9 @@ func (c *InversePerpetualMarketClient) LatestBigDeal(ctx context.Context, params
return
}

// LongShortRatio - get long short ratio. [ /v2/public/account-ratio - GET ]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-marketaccountratio
func (c *InversePerpetualMarketClient) LongShortRatio(ctx context.Context, params *inverseperp.LongShortRatioParams) (response *inverseperp.LongShortRatioResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicInversePerpetualLongShortRatioPath, params, &response)
if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions rest/linear/account/active_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/cksidharthan/go-bybit/rest/domain/linear"
)

// PlaceActiveOrder - Place an active linear order. [/private/linear/order/create - POST]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-placeactive
func (c *LinearAccountClient) PlaceActiveOrder(ctx context.Context, params *linear.PlaceActiveOrderParams) (res *linear.PlaceActiveOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearPlaceOrderPath, params, &res)
if err != nil {
Expand All @@ -16,6 +19,12 @@ func (c *LinearAccountClient) PlaceActiveOrder(ctx context.Context, params *line
return
}

// GetActiveOrder - Get active linear orders. [/private/linear/order/list - GET]
//
// Get my active order list.
// Because order creation/cancellation is asynchronous, there can be a data delay in this endpoint. You can get real-time order info with the Query Active Order (real-time) endpoint.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-getactive
func (c *LinearAccountClient) GetActiveOrder(ctx context.Context, params *linear.GetActiveOrderParams) (res *linear.GetActiveOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearGetActiveOrderPath, params, &res)
if err != nil {
Expand All @@ -24,6 +33,12 @@ func (c *LinearAccountClient) GetActiveOrder(ctx context.Context, params *linear
return
}

// CancelActiveOrder - Cancel an active linear order. [/private/linear/order/cancel - POST]
//
// Either order_id or order_link_id are required for cancelling active orders. order_id - this unique 36 characters order ID was returned to you when the active order was created successfully.
// You may cancel active orders that are unfilled or partially filled. Fully filled orders cannot be cancelled.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-cancelactive
func (c *LinearAccountClient) CancelActiveOrder(ctx context.Context, params *linear.CancelActiveOrderParams) (res *linear.CancelActiveOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearOrderCancelPath, params, &res)
if err != nil {
Expand All @@ -32,6 +47,10 @@ func (c *LinearAccountClient) CancelActiveOrder(ctx context.Context, params *lin
return
}

// CancelAllActiveOrders - Cancel all active linear orders. [/private/linear/order/cancel-all - POST]
//
// Cancel all active orders that are unfilled or partially filled. Fully filled orders cannot be cancelled.
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-cancelactive
func (c *LinearAccountClient) CancelAllActiveOrders(ctx context.Context, params *linear.CancelAllActiveOrdersParams) (res *linear.CancelAllActiveOrdersResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearOrderCancelAllPath, params, &res)
if err != nil {
Expand All @@ -40,6 +59,9 @@ func (c *LinearAccountClient) CancelAllActiveOrders(ctx context.Context, params
return
}

// ReplaceActiveOrder - Replace order can modify/amend your active orders. [/private/linear/order/replace - POST]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-replaceactive
func (c *LinearAccountClient) ReplaceActiveOrder(ctx context.Context, params *linear.ReplaceActiveOrderParams) (res *linear.ReplaceActiveOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearReplaceActiveOrderPath, params, &res)
if err != nil {
Expand All @@ -48,6 +70,10 @@ func (c *LinearAccountClient) ReplaceActiveOrder(ctx context.Context, params *li
return
}

// QueryActiveOrder - Query active linear orders. [/private/linear/order/query - GET]
//
// Query real-time active order information. If only order_id or order_link_id are passed, a single order will be returned; otherwise, returns up to 500 unfilled orders.
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-queryactive
func (c *LinearAccountClient) QueryActiveOrder(ctx context.Context, params *linear.QueryActiveOrderParams) (res *linear.QueryActiveOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearQueryActiveOrderPath, params, &res)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions rest/linear/account/api_key_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/cksidharthan/go-bybit/rest/domain/linear"
)

// GetAPIKeyInfo - get users api key info. [/linear/v1/account - GET]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-key
func (c *LinearAccountClient) GetAPIKeyInfo(ctx context.Context) (res *linear.GetAPIKeyInfoResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearGetAPIKeyInfoPath, nil, &res)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions rest/linear/account/conditional_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/cksidharthan/go-bybit/rest/domain/linear"
)

// PlaceConditionalOrder - place conditional order. [/private/linear/stop-order/create - POST]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-placecond
func (c *LinearAccountClient) PlaceConditionalOrder(ctx context.Context, params *linear.PlaceConditionalOrderParams) (res *linear.PlaceConditionalOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearPlaceConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -16,6 +19,12 @@ func (c *LinearAccountClient) PlaceConditionalOrder(ctx context.Context, params
return
}

// GetConditionalOrder - Gets conditional order [/private/linear/stop-order/list - GET]
//
// Get my conditional order list.
// Because order creation/cancellation is asynchronous, there can be a data delay in this endpoint. You can get real-time order info with the Query Conditional Order (real-time) endpoint.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-getcond
func (c *LinearAccountClient) GetConditionalOrder(ctx context.Context, params *linear.GetConditionalOrderParams) (res *linear.GetConditionalOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearGetConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -24,6 +33,12 @@ func (c *LinearAccountClient) GetConditionalOrder(ctx context.Context, params *l
return
}

// CancelConditionalOrder - cancel conditional order. [/private/linear/stop-order/cancel - POST]
//
// You may cancel all untriggered conditional orders or take profit/stop loss order. Essentially, after a conditional order is triggered, it will become an active order.
// So, when a conditional order is triggered, cancellation has to be done through the active order endpoint for any unfilled or partially filled active order. As always, orders that have been fully filled cannot be cancelled.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-cancelcond
func (c *LinearAccountClient) CancelConditionalOrder(ctx context.Context, params *linear.CancelConditionalOrderParams) (res *linear.CancelConditionalOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearCancelConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -32,6 +47,9 @@ func (c *LinearAccountClient) CancelConditionalOrder(ctx context.Context, params
return
}

// CancelAllConditionalOrders - Cancel all untriggered conditional orders.. [/private/linear/stop-order/cancel-all - POST]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-cancelallcond
func (c *LinearAccountClient) CancelAllConditionalOrders(ctx context.Context, params *linear.CancelAllConditionalOrdersParams) (res *linear.CancelAllConditionalOrdersResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearCancelAllConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -40,6 +58,12 @@ func (c *LinearAccountClient) CancelAllConditionalOrders(ctx context.Context, pa
return
}

// ReplaceConditionalOrder - replace conditional order. [/private/linear/stop-order/replace - POST]
//
// Replace conditional order can modify/amend your conditional orders.
// order_id and symbol are required for identifying a conditional order.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-replacecond
func (c *LinearAccountClient) ReplaceConditionalOrder(ctx context.Context, params *linear.ReplaceConditionalOrderParams) (res *linear.ReplaceConditionalOrderResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodPost, bybit.PrivateLinearReplaceConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -48,6 +72,9 @@ func (c *LinearAccountClient) ReplaceConditionalOrder(ctx context.Context, param
return
}

// QueryConditionalOrderBySymbol - Query conditional order by symbol. [/private/linear/stop-order/list - GET]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-querycond
func (c *LinearAccountClient) QueryConditionalOrderBySymbol(ctx context.Context, params *linear.QueryConditionalOrderBySymbolParams) (res *linear.QueryConditionalOrderBySymbolResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearQueryConditionalOrderPath, params, &res)
if err != nil {
Expand All @@ -56,6 +83,11 @@ func (c *LinearAccountClient) QueryConditionalOrderBySymbol(ctx context.Context,
return
}

// QueryConditionalOrderWithIDs - Query conditional order with IDs. [/private/linear/stop-order/list - GET]
//
// Query real-time stop order information. When passing the parameter order_id or order_link_id, a single order data will be returned; otherwise, returns up to 10 unfilled orders.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-querycond
func (c *LinearAccountClient) QueryConditionalOrderWithIDs(ctx context.Context, params *linear.QueryConditionalOrderWithIDsParams) (res *linear.QueryConditionalOrderWithIDsResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearQueryConditionalOrderPath, params, &res)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions rest/linear/account/funding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/cksidharthan/go-bybit/rest/domain/linear"
)

// GetPredictedFundingRate - Get predicted funding rate and my predicted funding fee.. [/private/linear/funding/predicted-funding - GET]
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-predictedfunding
func (c *LinearAccountClient) GetPredictedFundingRate(ctx context.Context, params *linear.PredictedFundingRateParams) (res *linear.PredictedFundingRateResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearPredictedFundingRatePath, params, &res)
if err != nil {
Expand All @@ -16,6 +19,13 @@ func (c *LinearAccountClient) GetPredictedFundingRate(ctx context.Context, param
return
}

// GetLastFundingFee - Get last funding fee. [/private/linear/funding/prev-funding - GET]
//
// Funding settlement occurs every 8 hours at 00:00 UTC, 08:00 UTC and 16:00 UTC. The current interval's fund fee settlement is based on the previous interval's fund rate.
//
// For example, at 16:00, the settlement is based on the fund rate generated at 8:00. The fund rate generated at 16:00 will be used at 0:00 the next day.
//
// docs - https://bybit-exchange.github.io/docs/futuresV2/linear/#t-mylastfundingfee
func (c *LinearAccountClient) GetLastFundingFee(ctx context.Context, params *linear.GetLastFundingFeeParams) (res *linear.GetLastFundingFeeResponse, err error) {
err = c.transporter.SignedRequest(ctx, http.MethodGet, bybit.PrivateLinearGetLastFundingFeePath, params, &res)
if err != nil {
Expand Down
Loading

0 comments on commit 091cb77

Please sign in to comment.