-
Notifications
You must be signed in to change notification settings - Fork 1
/
contract.go
66 lines (53 loc) · 1.7 KB
/
contract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package coinex
import (
"time"
. "github.com/SuperGod/trademodel"
)
const (
Long = 1
Short = 2
)
type Contract struct {
Symbol string
Name string
Expiry time.Time
}
func (c Contract) String() string {
return c.Symbol + " " + c.Name
}
type Position struct {
Info Contract // 合约信息
Type int // 合约类型,Long: 多头,Short: 空头
Hold float64 // 持有仓位
Price float64 //开仓价格
ProfitRatio float64 // 盈利比例,正数表示盈利,负数表示亏岁
}
type BaseExchanger interface {
Buy(price float64, amount float64) (*Order, error)
Sell(price float64, amount float64) (*Order, error)
}
type FuturesBaseExchanger interface {
BaseExchanger
OpenLong(price float64, amount float64) (*Order, error)
CloseLong(price float64, amount float64) (*Order, error)
OpenShort(price float64, amount float64) (*Order, error)
CloseShort(price float64, amount float64) (*Order, error)
OpenLongMarket(amount float64) (*Order, error)
CloseLongMarket(amount float64) (*Order, error)
OpenShortMarket(amount float64) (*Order, error)
CloseShortMarket(amount float64) (*Order, error)
}
type FuturesExchanger interface {
FuturesBaseExchanger
Contracts() ([]Contract, error)
Positions() ([]Position, error)
ContractBalances() (map[Contract]Balance, error)
Depth(int) (Orderbook, error)
Ticker() (Ticker, error)
SetSymbol(symbol string) error
SetContract(contract string) error
SetLever(lever float64) error
KlineRecent(count int32, binSize string) (klines []*Candle, err error)
Kline(start, end time.Time, nLimit int, binSize string) (klines []*Candle, err error)
KlineChan(start, end time.Time, bSize string) (data chan []interface{}, err chan error)
}