-
-
Notifications
You must be signed in to change notification settings - Fork 279
/
exchange.go
93 lines (64 loc) · 2.22 KB
/
exchange.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package types
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/pkg/errors"
)
const DateFormat = "2006-01-02"
type ExchangeName string
func (n *ExchangeName) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s) ; err != nil {
return err
}
switch s {
case "max", "binance", "ftx":
*n = ExchangeName(s)
return nil
}
return fmt.Errorf("unknown or unsupported exchange name: %s, valid names are: max, binance, ftx", s)
}
func (n ExchangeName) String() string {
return string(n)
}
const (
ExchangeMax = ExchangeName("max")
ExchangeBinance = ExchangeName("binance")
ExchangeFTX = ExchangeName("ftx")
)
func ValidExchangeName(a string) (ExchangeName, error) {
switch strings.ToLower(a) {
case "max":
return ExchangeMax, nil
case "binance", "bn":
return ExchangeBinance, nil
}
return "", errors.New("invalid exchange name")
}
type Exchange interface {
Name() ExchangeName
PlatformFeeCurrency() string
NewStream() Stream
QueryMarkets(ctx context.Context) (MarketMap, error)
QueryAccount(ctx context.Context) (*Account, error)
QueryAccountBalances(ctx context.Context) (BalanceMap, error)
QueryTicker(ctx context.Context, symbol string) (*Ticker, error)
QueryTickers(ctx context.Context, symbol ...string) (map[string]Ticker, error)
QueryKLines(ctx context.Context, symbol string, interval Interval, options KLineQueryOptions) ([]KLine, error)
QueryTrades(ctx context.Context, symbol string, options *TradeQueryOptions) ([]Trade, error)
QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []Deposit, err error)
QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (allWithdraws []Withdraw, err error)
SubmitOrders(ctx context.Context, orders ...SubmitOrder) (createdOrders OrderSlice, err error)
QueryOpenOrders(ctx context.Context, symbol string) (orders []Order, err error)
QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) (orders []Order, err error)
CancelOrders(ctx context.Context, orders ...Order) error
}
type TradeQueryOptions struct {
StartTime *time.Time
EndTime *time.Time
Limit int64
LastTradeID int64
}