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

Added interface of risk limit level #6

Merged
merged 1 commit into from Dec 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions risk_limit_level.go
@@ -0,0 +1,31 @@
package kumex

import (
"net/http"
)

// RiskLimitLevelModel represents a Contract risk limit level info.
type RiskLimitLevelModel struct {
Symbol string `json:"symbol"`
Level int64 `json:"level"`
MaxRiskLimit int64 `json:"maxRiskLimit"`
MinRiskLimit int64 `json:"minRiskLimit"`
MaxLeverage int64 `json:"maxLeverage"`
InitialMargin float64 `json:"initialMargin"`
MaintainMargin float64 `json:"maintainMargin"`
}

// ContractRiskLimitLevelModel represents a Contract risk limit level info.
type ContractsRiskLimitLevelModel []*RiskLimitLevelModel

// ContractsRiskLimitLevel obtain information about risk limit level of a specific contract
func (as *ApiService) ContractsRiskLimitLevel(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/contracts/risk-limit/"+symbol, nil)
return as.Call(req)
}

// ContractsRiskLimit adjust contract risk limit level
func (as *ApiService) ChangeRiskLimitLevel(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/position/risk-limit-level/change", params)
return as.Call(req)
}
30 changes: 30 additions & 0 deletions risk_limit_level_test.go
@@ -0,0 +1,30 @@
package kumex

import "testing"

func TestApiService_ContractsRiskLimitLevel(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.ContractsRiskLimitLevel("ADAUSDTM")
if err != nil {
t.Fatal(err)
}
o := &ContractsRiskLimitLevelModel{}
if err := rsp.ReadData(o); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(o))

}

func TestApiService_ChangeRiskLimitLevel(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.ChangeRiskLimitLevel(map[string]string{"symbol": "ADAUSDTM", "level": "2"})
if err != nil {
t.Fatal(err)
}
var ret bool
if err := rsp.ReadData(&ret); err != nil {
t.Fatal(err)
}
t.Log(ret)
}