Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions server/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"strings"
"time"

"github.com/oapi-codegen/nullable"
Expand Down Expand Up @@ -39,19 +40,26 @@ func NewBot(id int, name string, accountID int, enabled bool) tcmock.Bot {
// This is a helper to make it easier to create test deals
func NewDeal(id int, botID int, pair string, status string) tcmock.Deal {
now := time.Now()
// Extract currency from pair (assumes format like "USDT_BTC")
// Extract currency from pair (format like "USDT_BTC" or "BTC_USD")
toCurrency := "BTC"
if len(pair) > 3 {
toCurrency = pair[len(pair)-3:]
if pair != "" {
upper := strings.ToUpper(pair)
if parts := strings.Split(upper, "_"); len(parts) > 1 {
toCurrency = parts[len(parts)-1]
} else if len(upper) > 3 {
toCurrency = upper[len(upper)-3:]
} else {
toCurrency = upper
}
}
return tcmock.Deal{
Id: id,
BotId: botID,
Pair: pair,
Status: tcmock.DealStatus(status),
CreatedAt: now,
UpdatedAt: now,
BotEvents: []struct {
Id: id,
BotId: botID,
Pair: pair,
Status: tcmock.DealStatus(status),
CreatedAt: now,
UpdatedAt: now,
BotEvents: []struct {
CreatedAt *time.Time `json:"created_at,omitempty"`
Message *string `json:"message,omitempty"`
}{},
Expand Down Expand Up @@ -105,19 +113,19 @@ func NewDeal(id int, botID int, pair string, status string) tcmock.Deal {
SafetyStrategyList: []map[string]interface{}{},
SlToBreakevenEnabled: false,
CloseStrategyList: []map[string]interface{}{},
TakeProfitSteps: []struct {
AmountPercentage *float32 `json:"amount_percentage,omitempty"`
Editable *bool `json:"editable,omitempty"`
TakeProfitSteps: []struct {
AmountPercentage *float32 `json:"amount_percentage,omitempty"`
Editable *bool `json:"editable,omitempty"`
ExecutionTimestamp nullable.Nullable[time.Time] `json:"execution_timestamp,omitempty"`
Id *int `json:"id,omitempty"`
InitialAmount *string `json:"initial_amount,omitempty"`
PanicSellable *bool `json:"panic_sellable,omitempty"`
Price *string `json:"price,omitempty"`
ProfitPercentage *float32 `json:"profit_percentage,omitempty"`
Status *string `json:"status,omitempty"`
TradeId *int `json:"trade_id,omitempty"`
Id *int `json:"id,omitempty"`
InitialAmount *string `json:"initial_amount,omitempty"`
PanicSellable *bool `json:"panic_sellable,omitempty"`
Price *string `json:"price,omitempty"`
ProfitPercentage *float32 `json:"profit_percentage,omitempty"`
Status *string `json:"status,omitempty"`
TradeId *int `json:"trade_id,omitempty"`
}{},
Type: "simple",
Type: "simple",
}
}

Expand Down