diff --git a/README.md b/README.md index 059e0f6..59c98e0 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ The following API endpoints have been implemented - [`/v5/market/recent-trade` Get Public Trading History](https://bybit-exchange.github.io/docs/v5/market/recent-trade) - [`/v5/market/open-interest` Get Open Interest](https://bybit-exchange.github.io/docs/v5/market/open-interest) - [`/v5/market/historical-volatility` Get Historical Volatility](https://bybit-exchange.github.io/docs/v5/market/iv) +- [`/v5/market/insurance` Get Insurance](https://bybit-exchange.github.io/docs/v5/market/insurance) #### Position diff --git a/integrationtest/v5/market/market_test.go b/integrationtest/v5/market/market_test.go index 73f3298..3c1e1e5 100644 --- a/integrationtest/v5/market/market_test.go +++ b/integrationtest/v5/market/market_test.go @@ -221,3 +221,14 @@ func TestGetHistoricalVolatility(t *testing.T) { testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) } } + +func TestGetInsurance(t *testing.T) { + client := bybit.NewTestClient() + res, err := client.V5().Market().GetInsurance(bybit.V5GetInsuranceParam{}) + require.NoError(t, err) + { + goldenFilename := "./testdata/v5-market-get-insurance.json" + testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + } +} diff --git a/integrationtest/v5/market/testdata/v5-market-get-insurance.json b/integrationtest/v5/market/testdata/v5-market-get-insurance.json new file mode 100644 index 0000000..2a8fdf7 --- /dev/null +++ b/integrationtest/v5/market/testdata/v5-market-get-insurance.json @@ -0,0 +1,65 @@ +{ + "updatedTime": "1682467200000", + "list": [ + { + "coin": "USDT", + "balance": "472565175.36148953", + "value": "472629325.5808998" + }, + { + "coin": "USDC", + "balance": "996049.97239122", + "value": "996044.9942383142" + }, + { + "coin": "EOS", + "balance": "767102.58626542", + "value": "833072.7720000001" + }, + { + "coin": "BTC", + "balance": "47533.89021999", + "value": "1418307241.21" + }, + { + "coin": "ADA", + "balance": "895412.56208743", + "value": "372849.5568" + }, + { + "coin": "BIT", + "balance": "101256.65607912", + "value": "51903.8256" + }, + { + "coin": "SOL", + "balance": "7760.59832427", + "value": "101888.8" + }, + { + "coin": "LTC", + "balance": "909951.79684841", + "value": "85062219.48" + }, + { + "coin": "DOT", + "balance": "1103850.50091492", + "value": "6832831.5" + }, + { + "coin": "ETH", + "balance": "981392.36669191", + "value": "1922772648.16" + }, + { + "coin": "XRP", + "balance": "212730.43859841", + "value": "102642.22499999999" + }, + { + "coin": "MANA", + "balance": "4996881.117703", + "value": "2875705.0155" + } + ] +} \ No newline at end of file diff --git a/v5_market_service.go b/v5_market_service.go index 9ee3f02..6e10475 100644 --- a/v5_market_service.go +++ b/v5_market_service.go @@ -22,6 +22,7 @@ type V5MarketServiceI interface { GetPublicTradingHistory(V5GetPublicTradingHistoryParam) (*V5GetPublicTradingHistoryResponse, error) GetOpenInterest(V5GetOpenInterestParam) (*V5GetOpenInterestResponse, error) GetHistoricalVolatility(V5GetHistoricalVolatilityParam) (*V5GetHistoricalVolatilityResponse, error) + GetInsurance(V5GetInsuranceParam) (*V5GetInsuranceResponse, error) } // V5MarketService : @@ -973,3 +974,40 @@ func (s *V5MarketService) GetHistoricalVolatility(param V5GetHistoricalVolatilit return &res, nil } + +// V5GetInsuranceParam : +type V5GetInsuranceParam struct { + Coin *Coin `url:"coin"` +} + +// V5GetInsuranceResponse : +type V5GetInsuranceResponse struct { + CommonV5Response `json:",inline"` + Result V5GetInsuranceResult `json:"result"` +} + +// V5GetInsuranceResult : +type V5GetInsuranceResult struct { + UpdatedTime string `json:"updatedTime"` + List []struct { + Coin Coin `json:"coin"` + Balance string `json:"balance"` + Value string `json:"value"` + } `json:"list"` +} + +// GetInsurance : +func (s *V5MarketService) GetInsurance(param V5GetInsuranceParam) (*V5GetInsuranceResponse, error) { + var res V5GetInsuranceResponse + + queryString, err := query.Values(param) + if err != nil { + return nil, err + } + + if err := s.client.getPublicly("/v5/market/insurance", queryString, &res); err != nil { + return nil, err + } + + return &res, nil +} diff --git a/v5_market_service_test.go b/v5_market_service_test.go index 508be0a..c5018b3 100644 --- a/v5_market_service_test.go +++ b/v5_market_service_test.go @@ -745,3 +745,94 @@ func TestV5Market_GetHistoricalVolatility(t *testing.T) { assert.Equal(t, respBody["category"], string(resp.Result.Category)) assert.Equal(t, respBody["result"].([]map[string]interface{})[0]["period"], resp.Result.List[0].Period) } + +func TestV5Market_GetInsurance(t *testing.T) { + param := V5GetInsuranceParam{} + + path := "/v5/market/insurance" + method := http.MethodGet + status := http.StatusOK + respBody := map[string]interface{}{ + "result": map[string]interface{}{ + "updatedTime": "1682467200000", + "list": []map[string]interface{}{ + { + "coin": "USDT", + "balance": "472565175.36148953", + "value": "472629325.5808998", + }, + { + "coin": "USDC", + "balance": "996049.97239122", + "value": "996044.9942383142", + }, + { + "coin": "EOS", + "balance": "767102.58626542", + "value": "833072.7720000001", + }, + { + "coin": "BTC", + "balance": "47533.89021999", + "value": "1418307241.21", + }, + { + "coin": "ADA", + "balance": "895412.56208743", + "value": "372849.5568", + }, + { + "coin": "BIT", + "balance": "101256.65607912", + "value": "51903.8256", + }, + { + "coin": "SOL", + "balance": "7760.59832427", + "value": "101888.8", + }, + { + "coin": "LTC", + "balance": "909951.79684841", + "value": "85062219.48", + }, + { + "coin": "DOT", + "balance": "1103850.50091492", + "value": "6832831.5", + }, + { + "coin": "ETH", + "balance": "981392.36669191", + "value": "1922772648.16", + }, + { + "coin": "XRP", + "balance": "212730.43859841", + "value": "102642.22499999999", + }, + { + "coin": "MANA", + "balance": "4996881.117703", + "value": "2875705.0155", + }, + }, + }, + } + bytesBody, err := json.Marshal(respBody) + require.NoError(t, err) + + server, teardown := testhelper.NewServer( + testhelper.WithHandlerOption(path, method, status, bytesBody), + ) + defer teardown() + + client := NewTestClient(). + WithBaseURL(server.URL) + + resp, err := client.V5().Market().GetInsurance(param) + require.NoError(t, err) + + require.NotNil(t, resp) + testhelper.Compare(t, respBody["result"], resp.Result) +}