mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 00:07:01 +08:00
fix bybit_trader future order
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -32,8 +33,23 @@ type BybitTrader struct {
|
|||||||
|
|
||||||
// NewBybitTrader 创建 Bybit 交易器
|
// NewBybitTrader 创建 Bybit 交易器
|
||||||
func NewBybitTrader(apiKey, secretKey string) *BybitTrader {
|
func NewBybitTrader(apiKey, secretKey string) *BybitTrader {
|
||||||
|
const src = "Up000938"
|
||||||
|
|
||||||
client := bybit.NewBybitHttpClient(apiKey, secretKey, bybit.WithBaseURL(bybit.MAINNET))
|
client := bybit.NewBybitHttpClient(apiKey, secretKey, bybit.WithBaseURL(bybit.MAINNET))
|
||||||
|
|
||||||
|
// 设置 HTTP 传输
|
||||||
|
if client != nil && client.HTTPClient != nil {
|
||||||
|
defaultTransport := client.HTTPClient.Transport
|
||||||
|
if defaultTransport == nil {
|
||||||
|
defaultTransport = http.DefaultTransport
|
||||||
|
}
|
||||||
|
|
||||||
|
client.HTTPClient.Transport = &headerRoundTripper{
|
||||||
|
base: defaultTransport,
|
||||||
|
refererID: src,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trader := &BybitTrader{
|
trader := &BybitTrader{
|
||||||
client: client,
|
client: client,
|
||||||
cacheDuration: 15 * time.Second,
|
cacheDuration: 15 * time.Second,
|
||||||
@@ -44,6 +60,17 @@ func NewBybitTrader(apiKey, secretKey string) *BybitTrader {
|
|||||||
return trader
|
return trader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// headerRoundTripper 用于添加自定义 header 的 HTTP RoundTripper
|
||||||
|
type headerRoundTripper struct {
|
||||||
|
base http.RoundTripper
|
||||||
|
refererID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *headerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
req.Header.Set("Referer", h.refererID)
|
||||||
|
return h.base.RoundTrip(req)
|
||||||
|
}
|
||||||
|
|
||||||
// GetBalance 获取账户余额
|
// GetBalance 获取账户余额
|
||||||
func (t *BybitTrader) GetBalance() (map[string]interface{}, error) {
|
func (t *BybitTrader) GetBalance() (map[string]interface{}, error) {
|
||||||
// 检查缓存
|
// 检查缓存
|
||||||
|
|||||||
Reference in New Issue
Block a user