-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: define prototype for market command #278
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,4 +81,4 @@ logger: | |
max_size: 10 # Maximum size (in MB) of the log file before rotation. | ||
max_backups: 10 # Maximum number of backup log files to retain. | ||
compress: true # Compress old log files. | ||
targets: [file, console] # Logging targets: file, console, or both. | ||
targets: [file, console] # Logging targets: file, console, or both. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One new line is missed here. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this line is not applied.