Skip to content

Commit

Permalink
Merge branch 'main' into feature/reportSubcommandFunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSaeedkia authored Mar 2, 2025
2 parents d48d062 + 5d7a431 commit ba67159
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/engine/command/market/market.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/engine/command/market/market.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ sub_commands:
help: Shows the latest price of PAC coin across different markets
result_template: |
Xeggex Price: **{{.xeggexPrice}} USDT**
[Xeggex](https://xeggex.com/market/PACTUS_USDT)
Tradeogre Price: **{{.tradeOgre}} USDT**
[Trade Ogre](https://tradeogre.com/exchange/PAC-USDT)
Expand Down
11 changes: 10 additions & 1 deletion internal/engine/command/market/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ func (m *MarketCmd) priceHandler(_ *entity.User, cmd *command.Command, _ map[str
return cmd.RenderFailedTemplate("failed to get price from markets. please try again later")
}

xeggexPrice, err := strconv.ParseFloat(priceData.XeggexPacToUSDT.LastPrice, 64)
if err != nil {
log.Error("unable to parse float", "error", err)
}

tradeOgre, err := strconv.ParseFloat(priceData.TradeOgrePacToUSDT.Price, 64)
if err != nil {
log.Error("unable to parse float", "error", err)
}

return cmd.RenderResultTemplate("tradeOgre", tradeOgre, "azbitPrice", priceData.AzbitPacToUSDT.Price)
return cmd.RenderResultTemplate(
"xeggexPrice", xeggexPrice,
"tradeOgre", tradeOgre,
"azbitPrice", priceData.AzbitPacToUSDT.Price,
)
}
17 changes: 15 additions & 2 deletions internal/job/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
)

const (
_defaultTradeOgreEndpoint = "https://tradeogre.com/api/v1/ticker/PAC-USDT"
_defaultAzbitPriceEndpoint = "https://data.azbit.com/api/tickers?currencyPairCode=PAC_USDT"
_defaultXeggexPriceEndpoint = "https://api.xeggex.com/api/v2/market/getbysymbol/Pactus%2Fusdt"
_defaultTradeOgreEndpoint = "https://tradeogre.com/api/v1/ticker/PAC-USDT"
_defaultAzbitPriceEndpoint = "https://data.azbit.com/api/tickers?currencyPairCode=PAC_USDT"
)

type price struct {
Expand Down Expand Up @@ -48,12 +49,23 @@ func (p *price) start() {
var (
wg sync.WaitGroup
price entity.Price
xeggex entity.XeggexPriceResponse
tradeOgre entity.TradeOgrePriceResponse
azbit []entity.AzbitPriceResponse
)

ctx := context.Background()

wg.Add(1)
go func() {
defer wg.Done()
if err := p.getPrice(ctx, _defaultXeggexPriceEndpoint, &xeggex); err != nil {
log.Error(err.Error())

return
}
}()

wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -76,6 +88,7 @@ func (p *price) start() {

wg.Wait()

price.XeggexPacToUSDT = xeggex
price.TradeOgrePacToUSDT = tradeOgre
if len(azbit) > 0 {
price.AzbitPacToUSDT = azbit[0]
Expand Down

0 comments on commit ba67159

Please sign in to comment.