Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v5 get risk limit #132

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ The following API endpoints have been implemented
- [`/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)
- [`/v5/market/risk-limit` Get Risk Limit](https://bybit-exchange.github.io/docs/v5/market/risk-limit)

#### Position

Expand Down
15 changes: 15 additions & 0 deletions integrationtest/v5/market/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,18 @@ func TestGetInsurance(t *testing.T) {
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
}
}

func TestGetRiskLimit(t *testing.T) {
client := bybit.NewTestClient()
symbol := bybit.SymbolV5BTCUSDT
res, err := client.V5().Market().GetRiskLimit(bybit.V5GetRiskLimitParam{
Category: bybit.CategoryV5Linear,
Symbol: &symbol,
})
require.NoError(t, err)
{
goldenFilename := "./testdata/v5-market-get-risk-limit.json"
testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
}
}
311 changes: 311 additions & 0 deletions integrationtest/v5/market/testdata/v5-market-get-risk-limit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
{
"category": "linear",
"list": [
{
"id": 1,
"symbol": "BTCUSDT",
"riskLimitValue": "2000000",
"maintenanceMargin": "0.005",
"initialMargin": "0.01",
"isLowestRisk": 1,
"maxLeverage": "100.00"
},
{
"id": 2,
"symbol": "BTCUSDT",
"riskLimitValue": "4000000",
"maintenanceMargin": "0.01",
"initialMargin": "0.0175",
"isLowestRisk": 0,
"maxLeverage": "57.14"
},
{
"id": 3,
"symbol": "BTCUSDT",
"riskLimitValue": "6000000",
"maintenanceMargin": "0.015",
"initialMargin": "0.025",
"isLowestRisk": 0,
"maxLeverage": "40.00"
},
{
"id": 4,
"symbol": "BTCUSDT",
"riskLimitValue": "8000000",
"maintenanceMargin": "0.02",
"initialMargin": "0.0325",
"isLowestRisk": 0,
"maxLeverage": "30.77"
},
{
"id": 5,
"symbol": "BTCUSDT",
"riskLimitValue": "10000000",
"maintenanceMargin": "0.025",
"initialMargin": "0.04",
"isLowestRisk": 0,
"maxLeverage": "25.00"
},
{
"id": 6,
"symbol": "BTCUSDT",
"riskLimitValue": "12000000",
"maintenanceMargin": "0.03",
"initialMargin": "0.0475",
"isLowestRisk": 0,
"maxLeverage": "21.05"
},
{
"id": 7,
"symbol": "BTCUSDT",
"riskLimitValue": "14000000",
"maintenanceMargin": "0.035",
"initialMargin": "0.055",
"isLowestRisk": 0,
"maxLeverage": "18.18"
},
{
"id": 8,
"symbol": "BTCUSDT",
"riskLimitValue": "16000000",
"maintenanceMargin": "0.04",
"initialMargin": "0.0625",
"isLowestRisk": 0,
"maxLeverage": "16.00"
},
{
"id": 9,
"symbol": "BTCUSDT",
"riskLimitValue": "18000000",
"maintenanceMargin": "0.045",
"initialMargin": "0.07",
"isLowestRisk": 0,
"maxLeverage": "14.29"
},
{
"id": 10,
"symbol": "BTCUSDT",
"riskLimitValue": "20000000",
"maintenanceMargin": "0.05",
"initialMargin": "0.0775",
"isLowestRisk": 0,
"maxLeverage": "12.90"
},
{
"id": 11,
"symbol": "BTCUSDT",
"riskLimitValue": "22000000",
"maintenanceMargin": "0.055",
"initialMargin": "0.085",
"isLowestRisk": 0,
"maxLeverage": "11.76"
},
{
"id": 12,
"symbol": "BTCUSDT",
"riskLimitValue": "24000000",
"maintenanceMargin": "0.06",
"initialMargin": "0.0925",
"isLowestRisk": 0,
"maxLeverage": "10.81"
},
{
"id": 13,
"symbol": "BTCUSDT",
"riskLimitValue": "26000000",
"maintenanceMargin": "0.065",
"initialMargin": "0.1",
"isLowestRisk": 0,
"maxLeverage": "10.00"
},
{
"id": 14,
"symbol": "BTCUSDT",
"riskLimitValue": "28000000",
"maintenanceMargin": "0.07",
"initialMargin": "0.1075",
"isLowestRisk": 0,
"maxLeverage": "9.30"
},
{
"id": 15,
"symbol": "BTCUSDT",
"riskLimitValue": "30000000",
"maintenanceMargin": "0.075",
"initialMargin": "0.115",
"isLowestRisk": 0,
"maxLeverage": "8.70"
},
{
"id": 16,
"symbol": "BTCUSDT",
"riskLimitValue": "32000000",
"maintenanceMargin": "0.08",
"initialMargin": "0.1225",
"isLowestRisk": 0,
"maxLeverage": "8.16"
},
{
"id": 17,
"symbol": "BTCUSDT",
"riskLimitValue": "34000000",
"maintenanceMargin": "0.085",
"initialMargin": "0.13",
"isLowestRisk": 0,
"maxLeverage": "7.69"
},
{
"id": 18,
"symbol": "BTCUSDT",
"riskLimitValue": "36000000",
"maintenanceMargin": "0.09",
"initialMargin": "0.1375",
"isLowestRisk": 0,
"maxLeverage": "7.27"
},
{
"id": 19,
"symbol": "BTCUSDT",
"riskLimitValue": "38000000",
"maintenanceMargin": "0.095",
"initialMargin": "0.145",
"isLowestRisk": 0,
"maxLeverage": "6.90"
},
{
"id": 20,
"symbol": "BTCUSDT",
"riskLimitValue": "40000000",
"maintenanceMargin": "0.1",
"initialMargin": "0.1525",
"isLowestRisk": 0,
"maxLeverage": "6.56"
},
{
"id": 21,
"symbol": "BTCUSDT",
"riskLimitValue": "42000000",
"maintenanceMargin": "0.105",
"initialMargin": "0.16",
"isLowestRisk": 0,
"maxLeverage": "6.25"
},
{
"id": 22,
"symbol": "BTCUSDT",
"riskLimitValue": "44000000",
"maintenanceMargin": "0.11",
"initialMargin": "0.1675",
"isLowestRisk": 0,
"maxLeverage": "5.97"
},
{
"id": 23,
"symbol": "BTCUSDT",
"riskLimitValue": "46000000",
"maintenanceMargin": "0.115",
"initialMargin": "0.175",
"isLowestRisk": 0,
"maxLeverage": "5.71"
},
{
"id": 24,
"symbol": "BTCUSDT",
"riskLimitValue": "48000000",
"maintenanceMargin": "0.12",
"initialMargin": "0.1825",
"isLowestRisk": 0,
"maxLeverage": "5.48"
},
{
"id": 25,
"symbol": "BTCUSDT",
"riskLimitValue": "50000000",
"maintenanceMargin": "0.125",
"initialMargin": "0.19",
"isLowestRisk": 0,
"maxLeverage": "5.26"
},
{
"id": 26,
"symbol": "BTCUSDT",
"riskLimitValue": "52000000",
"maintenanceMargin": "0.13",
"initialMargin": "0.1975",
"isLowestRisk": 0,
"maxLeverage": "5.06"
},
{
"id": 27,
"symbol": "BTCUSDT",
"riskLimitValue": "54000000",
"maintenanceMargin": "0.135",
"initialMargin": "0.205",
"isLowestRisk": 0,
"maxLeverage": "4.88"
},
{
"id": 28,
"symbol": "BTCUSDT",
"riskLimitValue": "56000000",
"maintenanceMargin": "0.14",
"initialMargin": "0.2125",
"isLowestRisk": 0,
"maxLeverage": "4.71"
},
{
"id": 29,
"symbol": "BTCUSDT",
"riskLimitValue": "58000000",
"maintenanceMargin": "0.145",
"initialMargin": "0.22",
"isLowestRisk": 0,
"maxLeverage": "4.55"
},
{
"id": 30,
"symbol": "BTCUSDT",
"riskLimitValue": "60000000",
"maintenanceMargin": "0.15",
"initialMargin": "0.2275",
"isLowestRisk": 0,
"maxLeverage": "4.40"
},
{
"id": 31,
"symbol": "BTCUSDT",
"riskLimitValue": "70000000",
"maintenanceMargin": "0.18",
"initialMargin": "0.3",
"isLowestRisk": 0,
"maxLeverage": "3.33"
},
{
"id": 32,
"symbol": "BTCUSDT",
"riskLimitValue": "85000000",
"maintenanceMargin": "0.3",
"initialMargin": "0.5",
"isLowestRisk": 0,
"maxLeverage": "2.00"
},
{
"id": 33,
"symbol": "BTCUSDT",
"riskLimitValue": "100000000",
"maintenanceMargin": "0.42",
"initialMargin": "0.7",
"isLowestRisk": 0,
"maxLeverage": "1.43"
},
{
"id": 34,
"symbol": "BTCUSDT",
"riskLimitValue": "200000000",
"maintenanceMargin": "0.6",
"initialMargin": "1",
"isLowestRisk": 0,
"maxLeverage": "1.00"
}
]
}
7 changes: 7 additions & 0 deletions v5_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,10 @@ const (
WithdrawStatusV5Fail = WithdrawStatusV5("Fail")
WithdrawStatusV5BlockchainConfirmed = WithdrawStatusV5("BlockchainConfirmed")
)

type IsLowestRisk int

const (
IsLowestRiskFalse = IsLowestRisk(0)
IsLowestRiskTrue = IsLowestRisk(1)
)
Loading