Skip to content

Commit

Permalink
feat: add linear market endpoints (#9)
Browse files Browse the repository at this point in the history
* chore: refactor, added market linear endpoints

* fmt changes
  • Loading branch information
cksidharthan committed Aug 10, 2022
1 parent fe2865c commit f9c2888
Show file tree
Hide file tree
Showing 40 changed files with 1,245 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.1
v0.0.2
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ test: $(info Running tests...)
CGO_ENABLED=0 go test -coverprofile cover.out ./...
CGO_ENABLED=0 go tool cover -html=cover.out -o cover.html

.PHONY: all
.PHONY: all

# NOTE: Install godoc to run this command: `go install golang.org/x/tools/cmd/godoc@latest`
docs:
godoc -http=:6060
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go get -u github.com/cksidharthan/go-bybit
| SPOT | Account Data | :heavy_check_mark: | :heavy_check_mark: |
| SPOT | Wallet Data | :heavy_check_mark: | :heavy_check_mark: |
| SPOT | API Data | :heavy_check_mark: | :heavy_check_mark: |
| USDT Perpetual | Market Data | :x: | :x: |
| USDT Perpetual | Market Data | :heavy_check_mark: | :heavy_check_mark: |
| USDT Perpetual | Account Data | :x: | :x: |
| USDT Perpetual | Wallet Data | :x: | :x: |
| USDT Perpetual | API Data | :x: | :x: |
Expand Down
21 changes: 13 additions & 8 deletions bybit/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ const (
PrivateWalletBalancePath = "/spot/v1/account"

/* USDT Perpetual Market API */
PublicLinearOrderBookPath = "v2/public/orderBook/L2"
PublicQueryKlinePath = "/public/linear/kline"
PublicGetSymbolInformationPath = "/v2/public/tickers"
PublicGetPublicTradingRecordsPath = "/public/linear/recent-trading-records"
PublicGetLastFundingRatePath = "/public/linear/funding/prev-funding-rate"
PublicQuerySymbolPath = "/v2/public/symbols"
PublicLiquidatedOrdersPath = "/v2/public/liq-records"
PublicQueryMarkPriceKline = "/public/linear/mark-price-kline"
PublicLinearOrderBookPath = "v2/public/orderBook/L2"
PublicQueryKlinePath = "/public/linear/kline"
PublicGetSymbolInformationPath = "/v2/public/tickers"
PublicGetPublicTradingRecordsPath = "/public/linear/recent-trading-records"
PublicGetLastFundingRatePath = "/public/linear/funding/prev-funding-rate"
PublicQuerySymbolPath = "/v2/public/symbols"
PublicLiquidatedOrdersPath = "/v2/public/liq-records"
PublicQueryMarkPriceKline = "/public/linear/mark-price-kline"
PublicQueryIndexPriceKlinePath = "/v2/public/index-price-kline"
PublicQueryPremiumIndexPriceKlinePath = "/v2/public/premium-index-kline"
PublicGetOpenInterestPath = "/v2/public/open-interest"
PublicGetLatestBigDealPath = "/v2/public/big-deal"
PublicGetLongShortRatioPath = "/v2/public/account-ratio"

// ACCOUNT DATA ENDPOINTS
// Inverse Perpetual
Expand Down
17 changes: 17 additions & 0 deletions bybit/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ const (
// IntervalMonth :
IntervalMonth = Interval("M")
)

type Period string

const (
// Period5Min :
Period5Min = Period("5m")
// Period15Min :
Period15Min = Period("15m")
// Period30Min :
Period30Min = Period("30m")
// Period1hr :
Period1hr = Period("1h")
// Period4hr :
Period4hr = Period("4h")
// Period1day :
Period1day = Period("1d")
)
5 changes: 5 additions & 0 deletions rest/domain/linear/market_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ type MarketInterface interface {
GetLiquidatedOrders(ctx context.Context, params *GetLiquidatedOrdersParams) (*GetLiquidatedOrdersResponse, error)
GetLastFundingRate(ctx context.Context, params *GetLastFundingRateParams) (*GetLastFundingRateResponse, error)
QueryMarkPriceKline(ctx context.Context, params *QueryMarkPriceKlineParams) (*QueryMarkPriceKlineResponse, error)
QueryIndexPriceKline(ctx context.Context, params *QueryIndexPriceKlineParams) (*QueryIndexPriceKlineResponse, error)
QueryPremiumIndexKline(ctx context.Context, params *QueryPremiumIndexKlineParams) (*QueryPremiumIndexKlineResponse, error)
GetOpenInterest(ctx context.Context, params *GetOpenInterestParams) (*GetOpenInterestResponse, error)
GetLatestBigDeal(ctx context.Context, params *GetLatestBigDealParams) (*GetLatestBigDealResponse, error)
GetLongShortRatio(ctx context.Context, params *GetLongShortRatioParams) (*GetLongShortRatioResponse, error)
}
99 changes: 99 additions & 0 deletions rest/domain/linear/market_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,102 @@ type QueryMarkPriceKlineResult struct {
Close float64 `json:"close"`
StartAt int `json:"start_at"`
}

type QueryIndexPriceKlineParams struct {
Symbol string `url:"symbol" json:"symbol"`
Interval bybit.Interval `url:"interval" json:"interval"`
From int `url:"from" json:"from"`
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

type QueryIndexPriceKlineResponse struct {
domain.BaseResponse `json:",inline"`
Result []QueryIndexPriceKlineResult `json:"result"`
}

type QueryIndexPriceKlineResult struct {
Symbol string `json:"symbol"`
Period string `json:"period"`
OpenTime int `json:"open_time"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
}

type QueryPremiumIndexKlineParams struct {
Symbol string `url:"symbol" json:"symbol"`
Interval bybit.Interval `url:"interval" json:"interval"`
From int `url:"from,omitempty" json:"from,omitempty"`
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

type QueryPremiumIndexKlineResponse struct {
domain.BaseResponse `json:",inline"`
Result []QueryPremiumIndexKlineResult `json:"result"`
}

type QueryPremiumIndexKlineResult struct {
Symbol string `json:"symbol"`
Period string `json:"period"`
OpenTime float64 `json:"open_time"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
}

type GetOpenInterestParams struct {
Symbol string `url:"symbol" json:"symbol"`
// Data recording period. 5min, 15min, 30min, 1h, 4h, 1d
Period bybit.Period `url:"period" json:"period"`
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

type GetOpenInterestResponse struct {
domain.BaseResponse `json:",inline"`
Result []GetOpenInterestResult `json:"result"`
}

type GetOpenInterestResult struct {
Symbol string `json:"symbol"`
Timestamp int `json:"timestamp"`
OpenInterest float64 `json:"open_interest"`
}

type GetLatestBigDealParams struct {
Symbol string `url:"symbol" json:"symbol"`
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

type GetLatestBigDealResponse struct {
domain.BaseResponse `json:",inline"`
Result []GetLatestBigDealResult `json:"result"`
}

type GetLatestBigDealResult struct {
Symbol string `json:"symbol"`
Side string `json:"side"`
Timestamp int `json:"timestamp"`
Value float64 `json:"value"`
}

type GetLongShortRatioParams struct {
Symbol string `url:"symbol" json:"symbol"`
// Data recording period. 5min, 15min, 30min, 1h, 4h, 1d
Period bybit.Period `url:"period,omitempty" json:"period,omitempty"`
// Limit for data size per page, max size is 500. Default as showing 50 pieces of data per page
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

type GetLongShortRatioResponse struct {
domain.BaseResponse `json:",inline"`
Result []GetLongShortRatioResult `json:"result"`
}

type GetLongShortRatioResult struct {
Symbol string `json:"symbol"`
BuyRatio float64 `json:"buy_ratio"`
SellRatio float64 `json:"sell_ratio"`
Timestamp int `json:"timestamp"`
}
17 changes: 0 additions & 17 deletions rest/linear/market/get_last_funding_rate.go

This file was deleted.

17 changes: 0 additions & 17 deletions rest/linear/market/get_liquidated_orders.go

This file was deleted.

17 changes: 0 additions & 17 deletions rest/linear/market/get_order_book.go

This file was deleted.

17 changes: 0 additions & 17 deletions rest/linear/market/get_public_trading_records.go

This file was deleted.

17 changes: 0 additions & 17 deletions rest/linear/market/get_symbol_info.go

This file was deleted.

113 changes: 113 additions & 0 deletions rest/linear/market/market.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package market

import (
"context"
"net/http"

"github.com/cksidharthan/go-bybit/bybit"
"github.com/cksidharthan/go-bybit/rest/domain/linear"
)

func (c *Client) GetOrderBook(ctx context.Context, params *linear.OrderBookParams) (res *linear.OrderBookResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicLinearOrderBookPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) QueryKline(ctx context.Context, params *linear.QueryKlineParams) (res *linear.QueryKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicQueryKlinePath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetSymbolInformation(ctx context.Context, params *linear.GetSymbolInformationParams) (res *linear.GetSymbolInformationResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetSymbolInformationPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetPublicTradingRecords(ctx context.Context, params *linear.GetPublicTradingRecordsParams) (res *linear.GetPublicTradingRecordsResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetPublicTradingRecordsPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) QuerySymbol(ctx context.Context) (res *linear.QuerySymbolResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicQuerySymbolPath, nil, &res)
if err != nil {
return
}
return
}

func (c *Client) GetLiquidatedOrders(ctx context.Context, params *linear.GetLiquidatedOrdersParams) (res *linear.GetLiquidatedOrdersResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicLiquidatedOrdersPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetLastFundingRate(ctx context.Context, params *linear.GetLastFundingRateParams) (res *linear.GetLastFundingRateResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetLastFundingRatePath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) QueryMarkPriceKline(ctx context.Context, params *linear.QueryMarkPriceKlineParams) (res *linear.QueryMarkPriceKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicQueryMarkPriceKline, params, &res)
if err != nil {
return
}
return
}

func (c *Client) QueryIndexPriceKline(ctx context.Context, params *linear.QueryIndexPriceKlineParams) (res *linear.QueryIndexPriceKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicQueryIndexPriceKlinePath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) QueryPremiumIndexKline(ctx context.Context, params *linear.QueryPremiumIndexKlineParams) (res *linear.QueryPremiumIndexKlineResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicQueryPremiumIndexPriceKlinePath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetOpenInterest(ctx context.Context, params *linear.GetOpenInterestParams) (res *linear.GetOpenInterestResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetOpenInterestPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetLatestBigDeal(ctx context.Context, params *linear.GetLatestBigDealParams) (res *linear.GetLatestBigDealResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetLatestBigDealPath, params, &res)
if err != nil {
return
}
return
}

func (c *Client) GetLongShortRatio(ctx context.Context, params *linear.GetLongShortRatioParams) (res *linear.GetLongShortRatioResponse, err error) {
err = c.transporter.UnsignedRequest(ctx, http.MethodGet, bybit.PublicGetLongShortRatioPath, params, &res)
if err != nil {
return
}
return
}
Loading

0 comments on commit f9c2888

Please sign in to comment.