Skip to content

Commit

Permalink
Fix debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
rluisr committed Sep 28, 2022
1 parent cd89b84 commit 79bd14b
Showing 1 changed file with 54 additions and 57 deletions.
111 changes: 54 additions & 57 deletions pkg/external/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package external

import (
"context"
"os"

"github.com/rluisr/tvbit-bot/pkg/domain"

Expand Down Expand Up @@ -82,70 +81,68 @@ func cron() {
return 0, nil
})

if os.Getenv("SERVER_ENV") != "local" {

/*
Save wallet balance
*/
task.Task("0 * * * *", func(ctx context.Context) (int, error) {
settings, err := tvController.Interactor.TVRepository.GetSettings()
if err != nil {
return 0, err
}
/*
Save wallet balance
*/
task.Task("0 * * * *", func(ctx context.Context) (int, error) {
settings, err := tvController.Interactor.TVRepository.GetSettings()
if err != nil {
return 0, err
}

var walletHistories []domain.WalletHistory
var walletHistories []domain.WalletHistory

for _, setting := range settings {
switch setting.CEX {
case "bybit":
tvController.Bybit(domain.TV{
IsTestNet: setting.IsTestnet,
APIKey: setting.APIKey,
APISecretKey: setting.APISecretKey,
})
for _, setting := range settings {
switch setting.CEX {
case "bybit":
tvController.Bybit(domain.TV{
IsTestNet: setting.IsTestnet,
APIKey: setting.APIKey,
APISecretKey: setting.APISecretKey,
})

// USDC
bybitUSDCWallet, err := tvController.Interactor.BybitRepository.GetWalletInfoUSDC()
if err != nil {
return 1, err
}
// USDC
bybitUSDCWallet, err := tvController.Interactor.BybitRepository.GetWalletInfoUSDC()
if err != nil {
return 1, err
}

balance, err := decimal.NewFromString(bybitUSDCWallet.Result.WalletBalance)
if err != nil {
return 1, err
}
totalRPL, err := decimal.NewFromString(bybitUSDCWallet.Result.TotalRPL)
if err != nil {
return 1, err
}
balance, err := decimal.NewFromString(bybitUSDCWallet.Result.WalletBalance)
if err != nil {
return 1, err
}
totalRPL, err := decimal.NewFromString(bybitUSDCWallet.Result.TotalRPL)
if err != nil {
return 1, err
}

walletHistories = append(walletHistories, domain.WalletHistory{
SettingID: setting.ID,
Type: "usdc",
Balance: balance,
TotalRPL: totalRPL,
})
walletHistories = append(walletHistories, domain.WalletHistory{
SettingID: setting.ID,
Type: "usdc",
Balance: balance,
TotalRPL: totalRPL,
})

// Deriv USDT
bybitDerivWallet, err := tvController.Interactor.BybitRepository.GetWalletInfoDeriv()
if err != nil {
return 1, err
}
walletHistories = append(walletHistories, domain.WalletHistory{
SettingID: setting.ID,
Type: "usdt",
Balance: decimal.NewFromFloat(bybitDerivWallet.Equity),
TotalRPL: decimal.NewFromFloat(bybitDerivWallet.CumRealisedPnl),
})
// Deriv USDT
bybitDerivWallet, err := tvController.Interactor.BybitRepository.GetWalletInfoDeriv()
if err != nil {
return 1, err
}
walletHistories = append(walletHistories, domain.WalletHistory{
SettingID: setting.ID,
Type: "usdt",
Balance: decimal.NewFromFloat(bybitDerivWallet.Equity),
TotalRPL: decimal.NewFromFloat(bybitDerivWallet.CumRealisedPnl),
})
}
}

err = tvController.Interactor.TVRepository.SaveWalletHistories(walletHistories)
if err != nil {
return 1, err
}
return 0, nil
})

err = tvController.Interactor.TVRepository.SaveWalletHistories(walletHistories)
if err != nil {
return 1, err
}
return 0, nil
})
}
task.Run()
}

0 comments on commit 79bd14b

Please sign in to comment.