Compare commits

..

2 Commits

Author SHA1 Message Date
mmarcel
58037695d0 Merge branch 'swap-client' of https://git.mysrv.cloud/mmarcel/dero-swaps into swap-client 2024-04-23 20:22:43 +02:00
mmarcel
8afd6defc8 LTC support 2024-04-23 20:21:35 +02:00
4 changed files with 51 additions and 4 deletions

View File

@ -45,6 +45,8 @@ func LoadConfig() {
monero.Monero_Wallet = jsonrpc.NewClient("http://" + Settings.Monero_Wallet + "/json_rpc") 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" // check if pair is "supported"
for _, p := range Settings.Pairs { for _, p := range Settings.Pairs {
supported := false supported := false
@ -103,6 +105,13 @@ func CheckConfig() bool {
log.Printf("%s pair is set, but wallet is not set\n", p) log.Printf("%s pair is set, but wallet is not set\n", p)
return false 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
}
} }
} }

View File

@ -10,6 +10,8 @@ type Config struct {
Dero_Login string `json:"dero_login"` Dero_Login string `json:"dero_login"`
Monero_Daemon string `json:"monero_daemon"` Monero_Daemon string `json:"monero_daemon"`
Monero_Wallet string `json:"Monero_Wallet"` Monero_Wallet string `json:"Monero_Wallet"`
LTC_Daemon string `json:"LTC_Daemon"`
LTC_Dir string `json:"LTC_Dir"`
Pairs []string `json:"pairs"` Pairs []string `json:"pairs"`
//SwapFees float64 `json:"swap_fees"` //SwapFees float64 `json:"swap_fees"`
} }

View File

@ -10,7 +10,7 @@ type (
Pair string `json:"pair"` Pair string `json:"pair"`
Amount float64 `json:"amount"` Amount float64 `json:"amount"`
DeroAddr string `json:"dero_address"` DeroAddr string `json:"dero_address"`
Partner bool `json:"partner,omitempty"` Extern bool `json:"extern,omitempty"`
} }
Swap_Response struct { Swap_Response struct {
ID int64 `json:"id"` ID int64 `json:"id"`

View File

@ -120,13 +120,15 @@ func GetPrice(pair string) (bid float64, ask float64) {
// TODO: simplify // TODO: simplify
func UpdateMarkets() { func UpdateMarkets() {
var xmr float64 var xmr, ltc float64
var deroxmr float64 var deroxmr, deroltc float64
for p := range coin.SimplePairs { for p := range coin.SimplePairs {
switch p { switch p {
case coin.XMRDERO, coin.DEROXMR: case coin.XMRDERO, coin.DEROXMR:
deroxmr, xmr = GetPrice(p) deroxmr, xmr = GetPrice(p)
case coin.LTCDERO, coin.DEROLTC:
deroltc, ltc = GetPrice(p)
} }
// sometimes TradeOgre's BID/ASK values are swapped // sometimes TradeOgre's BID/ASK values are swapped
@ -135,6 +137,11 @@ func UpdateMarkets() {
xmr = deroxmr xmr = deroxmr
deroxmr = swap deroxmr = swap
} }
if deroltc > 0 && ltc > 0 && deroltc > ltc {
swap := ltc
ltc = deroltc
deroltc = swap
}
mk.Lock() mk.Lock()
defer mk.Unlock() defer mk.Unlock()
@ -162,6 +169,28 @@ func UpdateMarkets() {
log.Println("DERO->XMR disabled") 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() balance := UpdatePool()
@ -171,7 +200,11 @@ func UpdateMarkets() {
out.Method = "client" out.Method = "client"
out.Params = balance out.Params = balance
Connection.WriteJSON(out) if Connection != nil {
Connection.WriteJSON(out)
} else {
log.Println("<nil> server connection")
}
} }
func UpdatePool() clients.ClientInfo { func UpdatePool() clients.ClientInfo {
@ -186,6 +219,9 @@ func UpdatePool() clients.ClientInfo {
for p := range coin.Pairs { for p := range coin.Pairs {
switch p { switch p {
case coin.DEROLTC:
pair.Balance = coin.XTCGetBalance(p) - coin.Locked.GetLockedBalance(p)
pair.Pair = p
case coin.DEROXMR: case coin.DEROXMR:
pair.Balance = monero.GetBalance() - coin.Locked.GetLockedBalance(p) pair.Balance = monero.GetBalance() - coin.Locked.GetLockedBalance(p)
pair.Pair = p pair.Pair = p