Compare commits
No commits in common. "swap-client" and "v0.6" have entirely different histories.
swap-clien
...
v0.6
@ -56,8 +56,6 @@ The mentioned *withdrawal* fees are recommended and can be adjusted later.
|
|||||||
The following Pairs are supported:
|
The following Pairs are supported:
|
||||||
- xmr-dero
|
- xmr-dero
|
||||||
- dero-xmr
|
- dero-xmr
|
||||||
- ltc-dero
|
|
||||||
- dero-ltc
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -45,8 +45,6 @@ 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
|
||||||
@ -105,13 +103,6 @@ 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@ 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"`
|
||||||
}
|
}
|
||||||
|
@ -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"`
|
||||||
Extern bool `json:"extern,omitempty"`
|
Partner bool `json:"partner,omitempty"`
|
||||||
}
|
}
|
||||||
Swap_Response struct {
|
Swap_Response struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
61
go.sum
61
go.sum
@ -1,61 +0,0 @@
|
|||||||
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
|
|
||||||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
|
||||||
github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II=
|
|
||||||
github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/deroproject/derohe v0.0.0-20240229002921-e9df1205b660 h1:GwFMlJiyJ72+U5xLaeqZaUcVtEIJ5DqIjHTzUX2//OU=
|
|
||||||
github.com/deroproject/derohe v0.0.0-20240229002921-e9df1205b660/go.mod h1:EWHh1VkXRnCHvyGML98kXhngDFYebmOhk/9kZ1ATJ1c=
|
|
||||||
github.com/deroproject/graviton v0.0.0-20220130070622-2c248a53b2e1 h1:nsiNx83HYmRmYpYO37pUzSTmB7p9PFtGBl4FyD+a0jg=
|
|
||||||
github.com/deroproject/graviton v0.0.0-20220130070622-2c248a53b2e1/go.mod h1:a4u6QJtGGIADg1JwujD77UtaAyhIxg14+I0C7xjyQcc=
|
|
||||||
github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA=
|
|
||||||
github.com/fxamacker/cbor/v2 v2.6.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
|
||||||
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
|
|
||||||
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
|
||||||
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
|
||||||
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
|
|
||||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
|
||||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
|
||||||
github.com/lesismal/llib v1.1.13 h1:+w1+t0PykXpj2dXQck0+p6vdC9/mnbEXHgUy/HXDGfE=
|
|
||||||
github.com/lesismal/llib v1.1.13/go.mod h1:70tFXXe7P1FZ02AU9l8LgSOK7d7sRrpnkUr3rd3gKSg=
|
|
||||||
github.com/lesismal/nbio v1.5.6 h1:ad8s3AnZnAjMOHhnClHxWp69FsjiS40zOvJ0BYS9IG8=
|
|
||||||
github.com/lesismal/nbio v1.5.6/go.mod h1:mvfYBAA1jmrafXf2XvkM28jWkMTfA5jGks+HKDBMmOc=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
|
||||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
|
||||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
|
||||||
github.com/ybbus/jsonrpc/v3 v3.1.5 h1:0cC/QzS8OCuXYqqDbYnKKhsEe+IZLrNlDx8KPCieeW0=
|
|
||||||
github.com/ybbus/jsonrpc/v3 v3.1.5/go.mod h1:U1QbyNfL5Pvi2roT0OpRbJeyvGxfWYSgKJHjxWdAEeE=
|
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
|
||||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
|
||||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
|
||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
|
||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
|
||||||
golang.org/x/crypto v0.0.0-20210513122933-cd7d49e622d5/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
|
||||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
|
||||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
|
||||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
|
||||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
|
|
||||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
94
price.go
94
price.go
@ -120,15 +120,13 @@ func GetPrice(pair string) (bid float64, ask float64) {
|
|||||||
// TODO: simplify
|
// TODO: simplify
|
||||||
func UpdateMarkets() {
|
func UpdateMarkets() {
|
||||||
|
|
||||||
var xmr, ltc float64
|
var xmr float64
|
||||||
var deroxmr, deroltc float64
|
var deroxmr 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
|
||||||
@ -137,59 +135,32 @@ 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()
|
||||||
|
|
||||||
// TODO: simplify
|
// TODO: simplify
|
||||||
if xmr > 0 {
|
if xmr > 0 {
|
||||||
mk.Pairs.XMR = xmr
|
mk.Pairs.XMR = xmr
|
||||||
mk.Update[coin.XMRDERO] = time.Now().UnixMilli()
|
mk.Update[coin.XMRDERO] = time.Now().UnixMilli()
|
||||||
IsPairAvailable[coin.XMRDERO] = true
|
IsPairAvailable[coin.XMRDERO] = true
|
||||||
} else {
|
} else {
|
||||||
t := time.UnixMilli(mk.Update[coin.XMRDERO])
|
t := time.UnixMilli(mk.Update[coin.XMRDERO])
|
||||||
if time.Since(t) > time.Minute*2 {
|
if time.Since(t) > time.Minute*2 {
|
||||||
IsPairAvailable[coin.XMRDERO] = false
|
IsPairAvailable[coin.XMRDERO] = false
|
||||||
log.Println("XMR->DERO disabled")
|
log.Println("XMR->DERO disabled")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if deroxmr > 0 {
|
||||||
if deroxmr > 0 {
|
mk.Pairs.DEROXMR = deroxmr
|
||||||
mk.Pairs.DEROXMR = deroxmr
|
mk.Update[coin.DEROXMR] = time.Now().UnixMilli()
|
||||||
mk.Update[coin.DEROXMR] = time.Now().UnixMilli()
|
IsPairAvailable[coin.DEROXMR] = true
|
||||||
IsPairAvailable[coin.DEROXMR] = true
|
} else {
|
||||||
} else {
|
t := time.UnixMilli(mk.Update[coin.DEROXMR])
|
||||||
t := time.UnixMilli(mk.Update[coin.DEROXMR])
|
if time.Since(t) > time.Minute*2 {
|
||||||
if time.Since(t) > time.Minute*2 {
|
IsPairAvailable[coin.DEROXMR] = false
|
||||||
IsPairAvailable[coin.DEROXMR] = false
|
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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +171,7 @@ func UpdateMarkets() {
|
|||||||
out.Method = "client"
|
out.Method = "client"
|
||||||
out.Params = balance
|
out.Params = balance
|
||||||
|
|
||||||
if Connection != nil {
|
Connection.WriteJSON(out)
|
||||||
Connection.WriteJSON(out)
|
|
||||||
} else {
|
|
||||||
log.Println("<nil> server connection")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdatePool() clients.ClientInfo {
|
func UpdatePool() clients.ClientInfo {
|
||||||
@ -219,14 +186,11 @@ 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)
|
|
||||||
pair.Pair = p
|
|
||||||
case coin.DEROXMR:
|
case coin.DEROXMR:
|
||||||
pair.Balance = monero.GetBalance()
|
pair.Balance = monero.GetBalance() - coin.Locked.GetLockedBalance(p)
|
||||||
pair.Pair = p
|
pair.Pair = p
|
||||||
case coin.XMRDERO, coin.LTCDERO:
|
case coin.XMRDERO:
|
||||||
pair.Balance = dero.GetBalance()
|
pair.Balance = dero.GetBalance() - coin.Locked.GetLockedBalance(p)
|
||||||
pair.Pair = p
|
pair.Pair = p
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
|
@ -159,9 +159,9 @@ func StartClient(server url.URL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch request.Pair {
|
switch request.Pair {
|
||||||
case coin.XMRDERO, coin.LTCDERO:
|
case coin.XMRDERO:
|
||||||
response = Dero_Swap(request)
|
response = Dero_Swap(request)
|
||||||
case coin.DEROXMR, coin.DEROLTC:
|
case coin.DEROXMR:
|
||||||
response = Reverse_Swap(request)
|
response = Reverse_Swap(request)
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user