feat(lighter): improve API key validation and market caching

- Add API key validation status tracking
- Add market list caching to reduce API calls
- Improve logging (debug vs info levels)
- Add comprehensive integration tests
- Update trader manager and store for lighter support
This commit is contained in:
tinkle-community
2026-01-17 23:07:35 +08:00
parent 19698529b8
commit 7f24a90851
11 changed files with 2024 additions and 166 deletions

View File

@@ -103,7 +103,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "open_long",
0.1, 3500, 0.5, 0,
time.Now(), "order-1",
time.Now().UnixMilli(), "order-1",
)
if err != nil {
t.Fatalf("Failed to process open long: %v", err)
@@ -126,7 +126,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "close_long",
0.1, 3600, 0.5, 10.0, // PnL = (3600-3500)*0.1 = 10
time.Now(), "order-2",
time.Now().UnixMilli(), "order-2",
)
if err != nil {
t.Fatalf("Failed to process close long: %v", err)
@@ -152,7 +152,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "SHORT", "open_short",
0.05, 3500, 0.25, 0,
time.Now(), "order-3",
time.Now().UnixMilli(), "order-3",
)
if err != nil {
t.Fatalf("Failed to process open short: %v", err)
@@ -176,7 +176,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "SHORT", "close_short",
0.05, 3400, 0.25, 5.0, // PnL = (3500-3400)*0.05 = 5
time.Now(), "order-4",
time.Now().UnixMilli(), "order-4",
)
if err != nil {
t.Fatalf("Failed to process close short: %v", err)
@@ -205,7 +205,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "open_long",
0.1, 3500, 0.5, 0,
time.Now(), "order-5",
time.Now().UnixMilli(), "order-5",
)
if err != nil {
t.Fatalf("Failed to process first open: %v", err)
@@ -216,7 +216,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "open_long",
0.1, 3600, 0.5, 0,
time.Now(), "order-6",
time.Now().UnixMilli(), "order-6",
)
if err != nil {
t.Fatalf("Failed to process add position: %v", err)
@@ -243,7 +243,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "close_long",
0.2, 3700, 1.0, 30.0,
time.Now(), "order-7",
time.Now().UnixMilli(), "order-7",
)
if err != nil {
t.Fatalf("Failed to process close: %v", err)
@@ -269,7 +269,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "open_long",
1.0, 3500, 2.0, 0,
time.Now(), "order-8",
time.Now().UnixMilli(), "order-8",
)
if err != nil {
t.Fatalf("Failed to process open: %v", err)
@@ -280,7 +280,7 @@ func TestHyperliquidPositionBuilding(t *testing.T) {
traderID, exchangeID, exchangeType,
symbol, "LONG", "close_long",
0.3, 3600, 0.6, 30.0,
time.Now(), "order-9",
time.Now().UnixMilli(), "order-9",
)
if err != nil {
t.Fatalf("Failed to process partial close: %v", err)
@@ -351,7 +351,7 @@ func TestHyperliquidBugScenario(t *testing.T) {
traderID, exchangeID, exchangeType,
trade.symbol, trade.side, trade.action,
trade.qty, trade.price, trade.fee, trade.pnl,
time.Now().Add(time.Duration(i)*time.Second),
time.Now().Add(time.Duration(i)*time.Second).UnixMilli(),
"",
)
if err != nil {