From 8afd6defc88ecb7cc5f39a22a7323cd5ca0444ec Mon Sep 17 00:00:00 2001 From: mmarcel Date: Tue, 23 Apr 2024 20:21:35 +0200 Subject: [PATCH] LTC support --- cfg/config.go | 9 +++++++++ cfg/variables.go | 2 ++ coin/variables.go | 2 +- price.go | 42 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 5517424..b771c9f 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -45,6 +45,8 @@ func LoadConfig() { monero.Monero_Wallet = jsonrpc.NewClient("http://" + Settings.Monero_Wallet + "/json_rpc") + coin.XTC_URL[coin.LTCDERO] = "http://" + Settings.LTC_Daemon + // check if pair is "supported" for _, p := range Settings.Pairs { supported := false @@ -103,6 +105,13 @@ func CheckConfig() bool { log.Printf("%s pair is set, but wallet is not set\n", p) return false } + case coin.LTCDERO, coin.DEROLTC: + if Settings.LTC_Daemon == "" || Settings.LTC_Dir == "" { + log.Printf("%s pair is set, but daemon or directory is not set\n", p) + return false + } else { + coin.LTC_Dir = Settings.LTC_Dir + } } } diff --git a/cfg/variables.go b/cfg/variables.go index 6146967..76d1823 100644 --- a/cfg/variables.go +++ b/cfg/variables.go @@ -10,6 +10,8 @@ type Config struct { Dero_Login string `json:"dero_login"` Monero_Daemon string `json:"monero_daemon"` Monero_Wallet string `json:"Monero_Wallet"` + LTC_Daemon string `json:"LTC_Daemon"` + LTC_Dir string `json:"LTC_Dir"` Pairs []string `json:"pairs"` //SwapFees float64 `json:"swap_fees"` } diff --git a/coin/variables.go b/coin/variables.go index 4977c56..eeda348 100644 --- a/coin/variables.go +++ b/coin/variables.go @@ -10,7 +10,7 @@ type ( Pair string `json:"pair"` Amount float64 `json:"amount"` DeroAddr string `json:"dero_address"` - Partner bool `json:"partner,omitempty"` + Extern bool `json:"extern,omitempty"` } Swap_Response struct { ID int64 `json:"id"` diff --git a/price.go b/price.go index ecf4e8c..fd28942 100644 --- a/price.go +++ b/price.go @@ -120,13 +120,15 @@ func GetPrice(pair string) (bid float64, ask float64) { // TODO: simplify func UpdateMarkets() { - var xmr float64 - var deroxmr float64 + var xmr, ltc float64 + var deroxmr, deroltc float64 for p := range coin.SimplePairs { switch p { case coin.XMRDERO, coin.DEROXMR: deroxmr, xmr = GetPrice(p) + case coin.LTCDERO, coin.DEROLTC: + deroltc, ltc = GetPrice(p) } // sometimes TradeOgre's BID/ASK values are swapped @@ -135,6 +137,11 @@ func UpdateMarkets() { xmr = deroxmr deroxmr = swap } + if deroltc > 0 && ltc > 0 && deroltc > ltc { + swap := ltc + ltc = deroltc + deroltc = swap + } mk.Lock() defer mk.Unlock() @@ -162,6 +169,28 @@ func UpdateMarkets() { log.Println("DERO->XMR disabled") } } + if ltc > 0 { + mk.Pairs.LTC = ltc + mk.Update[coin.LTCDERO] = time.Now().UnixMilli() + IsPairAvailable[coin.LTCDERO] = true + } else { + t := time.UnixMilli(mk.Update[coin.LTCDERO]) + if time.Since(t) > time.Minute*2 { + IsPairAvailable[coin.LTCDERO] = false + log.Println("LTC->DERO disabled") + } + } + if deroltc > 0 { + mk.Pairs.DEROLTC = deroltc + mk.Update[coin.DEROLTC] = time.Now().UnixMilli() + IsPairAvailable[coin.DEROLTC] = true + } else { + t := time.UnixMilli(mk.Update[coin.DEROLTC]) + if time.Since(t) > time.Minute*2 { + IsPairAvailable[coin.DEROLTC] = false + log.Println("DERO->LTC disabled") + } + } } balance := UpdatePool() @@ -171,7 +200,11 @@ func UpdateMarkets() { out.Method = "client" out.Params = balance - Connection.WriteJSON(out) + if Connection != nil { + Connection.WriteJSON(out) + } else { + log.Println(" server connection") + } } func UpdatePool() clients.ClientInfo { @@ -186,6 +219,9 @@ func UpdatePool() clients.ClientInfo { for p := range coin.Pairs { switch p { + case coin.DEROLTC: + pair.Balance = coin.XTCGetBalance(p) - coin.Locked.GetLockedBalance(p) + pair.Pair = p case coin.DEROXMR: pair.Balance = monero.GetBalance() - coin.Locked.GetLockedBalance(p) pair.Pair = p