66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
|
|
package aeshelper
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"encoding/json"
|
|||
|
|
"fmt"
|
|||
|
|
"testing"
|
|||
|
|
"time"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// 测试加密解密
|
|||
|
|
func Test_EnDe(t *testing.T) {
|
|||
|
|
a := `asg`
|
|||
|
|
b := Encrypt(a, `code_verify_success`)
|
|||
|
|
c := Decrypt(b, `code_verify_success`)
|
|||
|
|
fmt.Println(`原始为`, a)
|
|||
|
|
fmt.Println(`加密后`, b)
|
|||
|
|
fmt.Println(`解密后`, c)
|
|||
|
|
}
|
|||
|
|
func TestAesEcbEncrypt(t *testing.T) {
|
|||
|
|
//aes := AesEcbEncrypt("123456")
|
|||
|
|
aes := AesEcbEncrypt(fmt.Sprintf("%v_%v", time.Now().Unix(), 1332355333))
|
|||
|
|
dst := AesEcbDecrypt(aes)
|
|||
|
|
fmt.Println(aes)
|
|||
|
|
fmt.Println(dst)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// TODO:需要加密的接口
|
|||
|
|
/**
|
|||
|
|
1.合约下单接口 /api/futures/trade/order
|
|||
|
|
2.合约撤单 /api/futures/trade/cancelorder
|
|||
|
|
3.调整保证金 /api/futures/trade/adjustmargin
|
|||
|
|
4.变换逐全仓模式 /api/futures/trade/marginType
|
|||
|
|
5.更改持仓模式(方向) /api/futures/trade/positionSide/dual
|
|||
|
|
6.资产划转 /api/futures/transfer
|
|||
|
|
*/
|
|||
|
|
func TestAesEcbEncryptOrder(t *testing.T) {
|
|||
|
|
data := addFutOrderReq{
|
|||
|
|
OrderType: 1,
|
|||
|
|
BuyType: 3,
|
|||
|
|
TriggerDecide: 3,
|
|||
|
|
IsReduce: 2,
|
|||
|
|
Coin: "asdf",
|
|||
|
|
Price: "333.23",
|
|||
|
|
Num: "23.20",
|
|||
|
|
TriggerPrice: "1.023",
|
|||
|
|
PositionSide: "long",
|
|||
|
|
}
|
|||
|
|
b, _ := json.Marshal(data)
|
|||
|
|
aes := AesEcbEncrypt(string(b))
|
|||
|
|
dst := AesEcbDecrypt(aes)
|
|||
|
|
fmt.Println(aes)
|
|||
|
|
fmt.Println(dst)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
type addFutOrderReq struct {
|
|||
|
|
OrderType int `json:"order_type"` // 订单类型:1限价,2限价止盈止损,3市价,4市价止盈止损,5强平委托(就是限价委托)
|
|||
|
|
BuyType int `json:"buy_type"` // 买卖类型:1买,2卖
|
|||
|
|
TriggerDecide int `json:"trigger_decide"` // 触发条件 1按最新成交价格算,2按标记价格算
|
|||
|
|
IsReduce int `json:"is_reduce"` // 1是只减仓位(点击仓位列表中的平仓按钮),0正常
|
|||
|
|
Coin string `json:"coin"` // 交易币
|
|||
|
|
Price string `json:"price"` // 下单价格(限价+止盈止损时,该字段必填)
|
|||
|
|
Num string `json:"num"` // 下单数量(市价时该字段必填)
|
|||
|
|
TriggerPrice string `json:"trigger_price"` // 触发价格
|
|||
|
|
PositionSide string `json:"position_side"` // 持仓方向,单向持仓模式下可填both;在双向持仓模式下必填,且仅可选择 long 或 short
|
|||
|
|
}
|