-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define prototype for market command (#278)
- Loading branch information
1 parent
c0640ac
commit d913e99
Showing
8 changed files
with
82 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
name: market | ||
help: Commands for managing market | ||
sub_commands: | ||
- name: price | ||
help: Shows the latest price of PAC coin across different markets | ||
result_template: | | ||
Xeggex Price: **{{.xeggexPrice}} USDT** | ||
https://xeggex.com/market/PACTUS_USDT | ||
Azbit Price: **{{.azbitPrice}} USDT** | ||
https://azbit.com/exchange/PAC_USDT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
package market | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/pagu-project/pagu/config" | ||
"github.com/pagu-project/pagu/internal/engine/command" | ||
"github.com/pagu-project/pagu/internal/entity" | ||
"github.com/pagu-project/pagu/pkg/log" | ||
) | ||
|
||
func (m *MarketCmd) priceHandler(_ *entity.User, cmd *command.Command, _ map[string]string) command.CommandResult { | ||
priceData, ok := m.priceCache.Get(config.PriceCacheKey) | ||
if !ok { | ||
return cmd.ErrorResult(fmt.Errorf("failed to get price from markets. please try again later")) | ||
return cmd.RenderFailedTemplate("failed to get price from markets. please try again later") | ||
} | ||
|
||
bldr := strings.Builder{} | ||
xeggexPrice, err := strconv.ParseFloat(priceData.XeggexPacToUSDT.LastPrice, 64) | ||
if err == nil { | ||
bldr.WriteString(fmt.Sprintf("Xeggex Price: %f USDT\n https://xeggex.com/market/PACTUS_USDT \n\n", | ||
xeggexPrice)) | ||
if err != nil { | ||
log.Error("unable to parse float", "error", err) | ||
} | ||
|
||
if priceData.AzbitPacToUSDT.Price > 0 { | ||
bldr.WriteString(fmt.Sprintf("Azbit Price: %f USDT\n https://azbit.com/exchange/PAC_USDT \n\n", | ||
priceData.AzbitPacToUSDT.Price)) | ||
} | ||
|
||
return cmd.SuccessfulResult(bldr.String()) | ||
return cmd.RenderResultTemplate("xeggexPrice", xeggexPrice, "azbitPrice", priceData.AzbitPacToUSDT.Price) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters