Skip to content

Commit

Permalink
新建market后,向tickers写入初始值
Browse files Browse the repository at this point in the history
  • Loading branch information
oldfritter committed Sep 9, 2019
1 parent 42ed3fa commit 60ea214
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions models/market.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package models

import (
"encoding/json"
"fmt"

"github.com/jinzhu/gorm"
"github.com/oldfritter/goDCE/utils"
"github.com/shopspring/decimal"
)
Expand Down Expand Up @@ -59,6 +61,17 @@ func FindMarketById(id int) (Market, error) {
return market, fmt.Errorf("No market can be found.")
}

func (market *Market) AfterCreate(db *gorm.DB) {
tickerRedis := utils.GetRedisConn("ticker")
defer tickerRedis.Close()
ticker := Ticker{MarketId: market.Id, Name: market.Name}
b, _ := json.Marshal(ticker)
if _, err := tickerRedis.Do("HSET", TickersRedisKey, market.Id, string(b)); err != nil {
fmt.Println("{ error: ", err, "}")
return
}
}

// Exchange
func (assignment *Market) MatchingExchange() string {
return utils.AmqpGlobalConfig.Exchange.Matching["key"]
Expand Down

0 comments on commit 60ea214

Please sign in to comment.