feat: subscribe to RabbitMQ trade signals and notify by rules
Consume configurable queues, format signals (including period), share NotifyService with HTTP, and drop duplicate bodies within 1h.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package tradesignal
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ptr(v float64) *float64 { return &v }
|
||||
|
||||
func TestFormatOpenIncludesPeriodAfterSymbol(t *testing.T) {
|
||||
out := Format(&Signal{
|
||||
Symbol: "BTCUSDT", Side: "LONG", Action: "OPEN",
|
||||
Quantity: ptr(0.01), Price: 64000.5, Leverage: 10,
|
||||
Period: "1h", EventTime: "2026-06-23T01:30:00Z",
|
||||
})
|
||||
if !strings.Contains(out, "多单开仓") || !strings.Contains(out, "交易品种: BTC") {
|
||||
t.Fatalf("%s", out)
|
||||
}
|
||||
idxSym := strings.Index(out, "交易品种: BTC")
|
||||
idxPer := strings.Index(out, "周期: 1h")
|
||||
idxPx := strings.Index(out, "开仓价格:")
|
||||
if idxPer < 0 || idxPer < idxSym || idxPx < idxPer {
|
||||
t.Fatalf("period placement:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatOmitsEmptyPeriod(t *testing.T) {
|
||||
out := Format(&Signal{
|
||||
Symbol: "BTCUSDT", Side: "LONG", Action: "OPEN",
|
||||
Price: 1, EventTime: "2026-06-23T01:30:00Z",
|
||||
})
|
||||
if strings.Contains(out, "周期:") {
|
||||
t.Fatalf("%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatCloseLong(t *testing.T) {
|
||||
pnl, bal := 941.0, 74744.90
|
||||
out := Format(&Signal{
|
||||
Symbol: "BTCUSDT", Side: "LONG", Action: "CLOSE",
|
||||
Quantity: ptr(3), Price: 63175.76,
|
||||
EventTime: "2026-07-07T05:52:14Z", PnL: &pnl, AccountBalance: &bal,
|
||||
})
|
||||
for _, want := range []string{"多单平仓", "平仓价格: 63175.76", "平仓盈亏: 941.00"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("missing %q in\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatWithAvgPrice(t *testing.T) {
|
||||
avg := 150.0
|
||||
out := Format(&Signal{
|
||||
Symbol: "BTCUSDT", Side: "LONG", Action: "ADD",
|
||||
Quantity: ptr(1), Price: 200, EventTime: "2026-07-07T05:52:14Z",
|
||||
}, FormatOptions{AvgPrice: &avg})
|
||||
if !strings.Contains(out, "平均单价: 150.00") {
|
||||
t.Fatalf("%s", out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user