-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
62 lines (55 loc) · 1.75 KB
/
market.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
package app
import (
"fmt"
"math"
"strings"
)
// MarketInfo specifies a market that the Archiver must support.
type MarketInfo struct {
Name string
Base uint32
Quote uint32
LotSize uint64
EpochDuration uint64 // msec
MarketBuyBuffer float64
MaxUserCancelsPerEpoch uint32
BookedLotLimit uint32
}
func marketName(base, quote string) string {
return base + "_" + quote
}
// MarketName creates the string representation of a DEX market (e.g. "dcr_btc")
// given the base and quote asset indexes defined in BIP-0044. See also
// BipIDSymbol.
func MarketName(base, quote uint32) (string, error) {
baseSymbol := BipIDSymbol(base)
if baseSymbol == "" {
return "", fmt.Errorf("base asset %d not found", base)
}
baseSymbol = strings.ToLower(baseSymbol)
quoteSymbol := BipIDSymbol(quote)
if quoteSymbol == "" {
return "", fmt.Errorf("quote asset %d not found", quote)
}
quoteSymbol = strings.ToLower(quoteSymbol)
return marketName(baseSymbol, quoteSymbol), nil
}
// NewMarketInfo creates a new market configuration (MarketInfo) from the given
// base and quote asset indexes, order lot size, and epoch duration in
// milliseconds. See also MarketName.
func NewMarketInfo(base, quote uint32, lotSize, epochDuration uint64, marketBuyBuffer float64) (*MarketInfo, error) {
name, err := MarketName(base, quote)
if err != nil {
return nil, err
}
return &MarketInfo{
Name: name,
Base: base,
Quote: quote,
LotSize: lotSize,
EpochDuration: epochDuration,
MarketBuyBuffer: marketBuyBuffer,
MaxUserCancelsPerEpoch: math.MaxUint32,
BookedLotLimit: math.MaxUint32,
}, nil
}