-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands_cancelSetSell.go
More file actions
67 lines (57 loc) · 1.38 KB
/
commands_cancelSetSell.go
File metadata and controls
67 lines (57 loc) · 1.38 KB
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
package main
import (
"fmt"
"strconv"
"time"
types "github.com/distributeddesigns/shared_types"
)
type cancelSetSellCmd struct {
id uint64
userID string
stock string
}
func parseCancelSetSellCmd(parts []string) cancelSetSellCmd {
if len(parts) != 4 {
abortTx("CANCEL_SET_SELL needs 4 parts")
}
id, err := strconv.ParseUint(parts[0], 10, 64)
abortTxOnError(err, "Could not parse ID")
return cancelSetSellCmd{
id: id,
userID: parts[2],
stock: parts[3],
}
}
func (css cancelSetSellCmd) Name() string {
return fmt.Sprintf("[%d] CANCEL_SET_SELL", css.id)
}
func (css cancelSetSellCmd) ToAuditEvent() types.AuditEvent {
xmlElement := fmt.Sprintf(`
<userCommand>
<timestamp>%d</timestamp>
<server>%s</server>
<transactionNum>%d</transactionNum>
<command>CANCEL_SET_SELL</command>
<username>%s</username>
<stockSymbol>%s</stockSymbol>
</userCommand>`,
time.Now().UnixNano()/1e6, redisBaseKey, css.id, css.userID, css.stock,
)
return types.AuditEvent{
UserID: css.userID,
ID: css.id,
EventType: "command",
Content: xmlElement,
}
}
func (css cancelSetSellCmd) Execute() {
autoTxKey := types.AutoTxKey{
Stock: css.stock,
UserID: css.userID,
Action: "Sell",
}
delete(workATXStore, autoTxKey)
autoTxCancelChan <- autoTxKey
consoleLog.Debugf("Published aTx %v successfully", autoTxKey)
consoleLog.Notice(" [✔] Finished", css.Name())
}