coinrust / crex

A Golang cryptocurrency trading API & Library. Support Binance, BitMEX, Deribit, Bybit, Huobi DM, OKEX Futures and more.
MIT License
512 stars 154 forks source link

运行出错 #19

Closed redkiller79 closed 4 years ago

redkiller79 commented 4 years ago

执行 examples\live 下的main.go的时候提示2020/10/02 01:02:42 jsonrpc2: code 13009 message: unauthorized 请问一下大佬怎么解决 希望能得到大佬的回复。国庆快乐

f0cii commented 4 years ago

应该是没有认证,你试试代码中写入你的Access Key & Api Secret,参考代码如下所示: exchange := exchanges.NewExchange(exchanges.Deribit, // ApiProxyURLOption("socks5://127.0.0.1:1080"), // 使用代理 ApiAccessKeyOption("[accessKey]"), // 这里填入你的 AccessKey ApiSecretKeyOption("[secretKey]"), // 这里填入你的 SecretKey ApiTestnetOption(true))

redkiller79 commented 4 years ago

非常感谢您的回复。我按照您说的添加了了对应的代码还是提示错误 : 2020/10/03 13:06:11 auth error: jsonrpc2: code 13004 message: invalid_credentials 2020/10/03 13:06:11 jsonrpc2: code 13009 message: unauthorized

我的代码如下:

package main

import ( . "github.com/coinrust/crex" "github.com/coinrust/crex/exchanges" "log" "time" )

type BasicStrategy struct { StrategyBase }

func (s *BasicStrategy) OnInit() error { return nil }

func (s *BasicStrategy) OnTick() error { currency := "LTC" symbol := "LTC-USDT-SWAP"

balance, err := s.Exchange.GetBalance(currency)
if err != nil {
    log.Fatal(err)
}
log.Printf("balance: %#v", balance)

s.Exchange.GetOrderBook(symbol, 10)

s.Exchange.OpenLong(symbol, OrderTypeLimit, 5000, 10)
s.Exchange.CloseLong(symbol, OrderTypeLimit, 6000, 10)

s.Exchange.PlaceOrder(symbol,
    Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))

s.Exchange.GetOpenOrders(symbol)
s.Exchange.GetPositions(symbol)
return nil

}

func (s BasicStrategy) Run() error { // run loop for { s.OnTick() time.Sleep(1 time.Second) } return nil }

func (s *BasicStrategy) OnExit() error { return nil }

func main() { exchange := exchanges.NewExchange(exchanges.Deribit, //ApiProxyURLOption("socks5://127.0.0.1:1080"), // 使用代理 ApiAccessKeyOption("[xxx-1b73-421a-b1ef-7f6228dd8153]"), ApiSecretKeyOption("[xxCA68B47C79BD47994A01E4497]"), ApiPassPhraseOption("[Ioff45xx45767]"), ApiTestnetOption(true))

s := &BasicStrategy{}

s.Setup(TradeModeLiveTrading, exchange)

s.OnInit()
s.Run()
s.OnExit()

}

f0cii commented 4 years ago

很明显 AccessKey 和 SecretKey 不包含 “[”, "]" 等字符。应该如: ApiAccessKeyOption("xxx-1b73-421a-b1ef-7f6228dd8153"), ApiSecretKeyOption("xxCA68B47C79BD47994A01E4497"),