Skip to content

Commit

Permalink
Merge pull request #6 from codewc/main
Browse files Browse the repository at this point in the history
Added interface of risk limit level
  • Loading branch information
1bazinga25 committed Dec 3, 2021
2 parents 384f2dc + 94d7ff2 commit 4e2f000
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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)
}

0 comments on commit 4e2f000

Please sign in to comment.