-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.go
70 lines (61 loc) · 1.69 KB
/
commands.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
package main
import (
"fmt"
"strings"
types "github.com/distributeddesigns/shared_types"
)
type command interface {
Execute()
Name() string
ToAuditEvent() types.AuditEvent
}
func parseCommand(s string) command {
// Convert to a proper .csv, then parse
// change `[100] STUFF,...` -> `100,STUFF,...`
csv := strings.Replace(s, "[", "", 1)
csv = strings.Replace(csv, "] ", ",", 1)
csv = strings.TrimSpace(csv)
parts := strings.Split(csv, ",")
if len(parts) < 3 {
abortTx("Insufficient command arguments")
}
cmdType := parts[1]
var parsedCommand command
switch cmdType {
case "ADD":
parsedCommand = parseAddCmd(parts)
case "QUOTE":
parsedCommand = parseQuoteCmd(parts)
case "BUY":
parsedCommand = parseBuyCmd(parts)
case "COMMIT_BUY":
parsedCommand = parseCommitBuyCmd(parts)
case "CANCEL_BUY":
parsedCommand = parseCancelBuyCmd(parts)
case "SELL":
parsedCommand = parseSellCmd(parts)
case "COMMIT_SELL":
parsedCommand = parseCommitSellCmd(parts)
case "CANCEL_SELL":
parsedCommand = parseCancelSellCmd(parts)
case "SET_BUY_AMOUNT":
parsedCommand = parseSetBuyAmountCmd(parts)
case "SET_BUY_TRIGGER":
parsedCommand = parseSetBuyTriggerCmd(parts)
case "CANCEL_SET_BUY":
parsedCommand = parseCancelSetBuyCmd(parts)
case "SET_SELL_AMOUNT":
parsedCommand = parseSetSellAmountCmd(parts)
case "SET_SELL_TRIGGER":
parsedCommand = parseSetSellTriggerCmd(parts)
case "CANCEL_SET_SELL":
parsedCommand = parseCancelSetSellCmd(parts)
case "DISPLAY_SUMMARY":
parsedCommand = parseDisplaySummaryCmd(parts)
case "DUMPLOG":
parsedCommand = parseDumplogCmd(parts)
default:
abortTx(fmt.Sprintf("Unrecognized command %s: %+v", cmdType, parts))
}
return parsedCommand
}