Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Oct 10, 2020
1 parent cbdcfa5 commit 344fba9
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,7 @@ type Exchange interface {

// 订阅持仓
SubscribePositions(market Market, callback func(positions []*Position)) error

// 调用其他功能
IO(name string, params string) (string, error)
}
4 changes: 4 additions & 0 deletions exchanges/binancefutures/binancefutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ func (b *BinanceFutures) SubscribePositions(market Market, callback func(positio
return ErrNotImplemented
}

func (b *BinanceFutures) IO(name string, params string) (string, error) {
return "", nil
}

func NewBinanceFutures(params *Parameters) *BinanceFutures {
client := futures.NewClient(params.AccessKey, params.SecretKey)
b := &BinanceFutures{
Expand Down
4 changes: 4 additions & 0 deletions exchanges/bitmex/bitmex.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ func (b *BitMEX) SubscribePositions(market Market, callback func(positions []*Po
return err
}

func (b *BitMEX) IO(name string, params string) (string, error) {
return "", nil
}

func NewBitMEX(params *Parameters) *BitMEX {
baseUri := "www.bitmex.com"
if params.Testnet {
Expand Down
4 changes: 4 additions & 0 deletions exchanges/bybit/bybit.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ func (b *Bybit) SubscribePositions(market Market, callback func(positions []*Pos
return b.ws.SubscribePositions(market, callback)
}

func (b *Bybit) IO(name string, params string) (string, error) {
return "", nil
}

func NewBybit(params *Parameters) *Bybit {
baseUri := "https://api.bybit.com/"
if params.Testnet {
Expand Down
4 changes: 4 additions & 0 deletions exchanges/deribit/deribit.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ func (b *Deribit) SubscribePositions(market Market, callback func(positions []*P
return ErrNotImplemented
}

func (b *Deribit) IO(name string, params string) (string, error) {
return "", nil
}

func NewDeribit(params *Parameters) *Deribit {
baseUri := "wss://www.deribit.com/ws/api/v2/"
if params.Testnet {
Expand Down
10 changes: 10 additions & 0 deletions exchanges/exsim/exsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/chuckpreslar/emission"
. "github.com/coinrust/crex"
"github.com/coinrust/crex/dataloader"
"github.com/spf13/cast"
"log"
"math"
"time"
Expand Down Expand Up @@ -798,6 +799,15 @@ func (b *ExSim) logOrderInfo(msg string, event string, order *Order) {
"positions", *positions)
}

func (b *ExSim) IO(name string, params string) (string, error) {
switch name {
case "AddBalance":
value := cast.ToFloat64(params)
b.balance += value
}
return "", nil
}

// NewExSim 创建模拟交易所
// cash: 初始资金
// makerFeeRate: Maker 费率
Expand Down
4 changes: 4 additions & 0 deletions exchanges/generatesim/generatesim.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,7 @@ func (s *GenerateSim) logOrderInfo(msg string, event string, order *Order) {
"positions", position,
)
}

func (s *GenerateSim) IO(name string, params string) (string, error) {
return "", nil
}
4 changes: 4 additions & 0 deletions exchanges/hbdm/hbdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ func (b *Hbdm) SubscribePositions(market Market, callback func(positions []*Posi
return b.ws.SubscribePositions(rawSymbol, contractType, callback)
}

func (b *Hbdm) IO(name string, params string) (string, error) {
return "", nil
}

func NewHbdm(params *Parameters) *Hbdm {
baseUri := "https://api.hbdm.com"
if params.ApiURL != "" {
Expand Down
4 changes: 4 additions & 0 deletions exchanges/hbdmswap/hbdmswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ func (b *HbdmSwap) SubscribePositions(market Market, callback func(positions []*
return b.ws.SubscribePositions(market, callback)
}

func (b *HbdmSwap) IO(name string, params string) (string, error) {
return "", nil
}

func NewHbdmSwap(params *Parameters) *HbdmSwap {
baseUri := "https://api.hbdm.com"
if params.ApiURL != "" {
Expand Down
4 changes: 4 additions & 0 deletions exchanges/okexfutures/okexfutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ func (b *OkexFutures) SubscribePositions(market Market, callback func(positions
return b.ws.SubscribePositions(market, callback)
}

func (b *OkexFutures) IO(name string, params string) (string, error) {
return "", nil
}

func NewOkexFutures(params *Parameters) *OkexFutures {
var baseUri string
if params.ApiURL != "" {
Expand Down
4 changes: 4 additions & 0 deletions exchanges/okexswap/okexswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ func (b *OkexSwap) SubscribePositions(market Market, callback func(positions []*
return b.ws.SubscribePositions(market, callback)
}

func (b *OkexSwap) IO(name string, params string) (string, error) {
return "", nil
}

func NewOkexSwap(params *Parameters) *OkexSwap {
var baseUri string
if params.ApiURL != "" {
Expand Down
18 changes: 18 additions & 0 deletions exchanges/spotsim/spotsim.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spotsim

import (
"encoding/json"
"errors"
"github.com/chuckpreslar/emission"
. "github.com/coinrust/crex"
Expand Down Expand Up @@ -393,6 +394,23 @@ func (s *SpotSim) CancelOrder(symbol string, id string, opts ...OrderOption) (re
return
}

func (s *SpotSim) IO(name string, params string) (string, error) {
switch name {
case "AddBalance":
var b SpotBalance
if err := json.Unmarshal([]byte(params), &b); err != nil {
return "", err
}
s.balance.Base.Available += b.Base.Available
s.balance.Base.Borrow += b.Base.Borrow
s.balance.Base.Frozen += b.Base.Frozen
s.balance.Quote.Available += b.Quote.Available
s.balance.Quote.Borrow += b.Quote.Borrow
s.balance.Quote.Frozen += b.Quote.Frozen
}
return "", nil
}

func (s *SpotSim) SetBacktest(backtest IBacktest) {
s.backtest = backtest
}
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.29.15/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
github.com/aws/aws-sdk-go v1.30.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/beaquant/utils v0.0.0-20200214111051-cad84a41cb41 h1:iJmblp0UKoV+UAOOdJCsbFEuEcjBjnrMcnuWTlTb1E8=
Expand Down Expand Up @@ -284,6 +285,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
Expand Down Expand Up @@ -343,6 +345,7 @@ github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
Expand Down Expand Up @@ -647,6 +650,7 @@ go.mongodb.org/mongo-driver v1.4.0 h1:C8rFn1VF4GVEM/rG+dSoMmlm2pyQ9cs2/oRtUATejR
go.mongodb.org/mongo-driver v1.4.0/go.mod h1:llVBH2pkj9HywK0Dtdt6lDikOjFLbceHVu/Rc0iMKLs=
go.mongodb.org/mongo-driver v1.4.1 h1:38NSAyDPagwnFpUA/D5SFgbugUYR3NzYRNa4Qk9UxKs=
go.mongodb.org/mongo-driver v1.4.1/go.mod h1:llVBH2pkj9HywK0Dtdt6lDikOjFLbceHVu/Rc0iMKLs=
go.mongodb.org/mongo-driver v1.4.2 h1:WlnEglfTg/PfPq4WXs2Vkl/5ICC6hoG8+r+LraPmGk4=
go.mongodb.org/mongo-driver v1.4.2/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
Expand Down Expand Up @@ -842,6 +846,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
3 changes: 3 additions & 0 deletions spotapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type SpotExchange interface {

// 撤销单个委托单
CancelOrder(symbol string, id string, opts ...OrderOption) (result *Order, err error)

// 调用其他功能
IO(name string, params string) (string, error)
}

// SpotExchangeSim 模拟交易所接口
Expand Down

0 comments on commit 344fba9

Please sign in to comment.