forked from oldfritter/goDCE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
620ad5d
commit c24408d
Showing
12 changed files
with
197 additions
and
90 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
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,62 +1,37 @@ | ||
package v1 | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gomodule/redigo/redis" | ||
"github.com/labstack/echo" | ||
. "github.com/oldfritter/goDCE/models" | ||
"github.com/oldfritter/goDCE/utils" | ||
) | ||
|
||
func V1GetTickers(context echo.Context) error { | ||
mainDB := utils.MainDbBegin() | ||
defer mainDB.DbRollback() | ||
tickerRedis := utils.GetRedisConn("ticker") | ||
defer tickerRedis.Close() | ||
values, _ := redis.Values(tickerRedis.Do("HGETALL", TickersRedisKey)) | ||
tickers := make([]interface{}, 0) | ||
var market Market | ||
for i, value := range values { | ||
if i%2 == 1 { | ||
ticker := Ticker{ | ||
MarketId: market.Id, | ||
At: time.Now().Unix(), | ||
Name: market.Name, | ||
} | ||
json.Unmarshal(value.([]byte), &ticker.TickerAspect) | ||
tickers = append(tickers, ticker) | ||
} else { | ||
marketId, _ := redis.String(value, nil) | ||
if mainDB.Where("id = ?", marketId).First(&market).RecordNotFound() { | ||
return utils.BuildError("1021") | ||
} | ||
} | ||
func V1GetTickersMarket(context echo.Context) error { | ||
market, err := FindMarketByCode(context.Param("market")) | ||
if err != nil { | ||
return utils.BuildError("1021") | ||
} | ||
ticker := Ticker{MarketId: market.Id, TickerAspect: market.Ticker} | ||
response := utils.SuccessResponse | ||
response.Body = tickers | ||
response.Body = ticker | ||
return context.JSON(http.StatusOK, response) | ||
} | ||
|
||
func V1GetTickersMarket(context echo.Context) error { | ||
var market Market | ||
mainDB := utils.MainDbBegin() | ||
defer mainDB.DbRollback() | ||
if mainDB.Where("code = ?", context.Param("market")).First(&market).RecordNotFound() { | ||
return utils.BuildError("1021") | ||
} | ||
tickerRedis := utils.GetRedisConn("ticker") | ||
defer tickerRedis.Close() | ||
value, _ := tickerRedis.Do("HGET", TickersRedisKey, market.Id) | ||
ticker := Ticker{ | ||
MarketId: market.Id, | ||
At: time.Now().Unix(), | ||
Name: market.Name, | ||
func V1GetTickers(context echo.Context) error { | ||
var tickers []Ticker | ||
for _, market := range AllMarkets { | ||
tickers = append(tickers, Ticker{ | ||
MarketId: market.Id, | ||
At: time.Now().Unix(), | ||
Name: market.Name, | ||
TickerAspect: market.Ticker, | ||
}) | ||
} | ||
json.Unmarshal(value.([]byte), &ticker.TickerAspect) | ||
|
||
response := utils.SuccessResponse | ||
response.Body = ticker | ||
response.Body = tickers | ||
return context.JSON(http.StatusOK, response) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
model: production | ||
node: a | ||
newrelic: | ||
app_name: goDCE | ||
license_key: fd4037a09661ecc12378f9da59b161e4a88c9c7e | ||
app_name: | ||
license_key: |
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,35 @@ | ||
package initializers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/oldfritter/goDCE/config" | ||
. "github.com/oldfritter/goDCE/models" | ||
) | ||
|
||
func LoadLatestKLines() { | ||
go func() { | ||
channel, err := config.RabbitMqConnect.Channel() | ||
if err != nil { | ||
fmt.Errorf("Channel: %s", err) | ||
} | ||
channel.ExchangeDeclare(config.AmqpGlobalConfig.Exchange["fanout"]["k"], "fanout", true, false, false, false, nil) | ||
queue, err := channel.QueueDeclare("", true, true, false, false, nil) | ||
if err != nil { | ||
return | ||
} | ||
channel.QueueBind(queue.Name, queue.Name, config.AmqpGlobalConfig.Exchange["fanout"]["k"], false, nil) | ||
msgs, _ := channel.Consume(queue.Name, "", true, false, false, false, nil) | ||
for d := range msgs { | ||
var notifyKLine KLine | ||
json.Unmarshal(d.Body, ¬ifyKLine) | ||
for i, _ := range AllMarkets { | ||
if AllMarkets[i].Id == notifyKLine.MarketId { | ||
AllMarkets[i].LatestKLines[notifyKLine.Period] = notifyKLine | ||
} | ||
} | ||
} | ||
return | ||
}() | ||
} |
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,35 @@ | ||
package initializers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/oldfritter/goDCE/config" | ||
. "github.com/oldfritter/goDCE/models" | ||
) | ||
|
||
func LoadLatestTickers() { | ||
go func() { | ||
channel, err := config.RabbitMqConnect.Channel() | ||
if err != nil { | ||
fmt.Errorf("Channel: %s", err) | ||
} | ||
channel.ExchangeDeclare(config.AmqpGlobalConfig.Exchange["fanout"]["ticker"], "fanout", true, false, false, false, nil) | ||
queue, err := channel.QueueDeclare("", true, true, false, false, nil) | ||
if err != nil { | ||
return | ||
} | ||
channel.QueueBind(queue.Name, queue.Name, config.AmqpGlobalConfig.Exchange["fanout"]["ticker"], false, nil) | ||
msgs, _ := channel.Consume(queue.Name, "", true, false, false, false, nil) | ||
for d := range msgs { | ||
var ticker Ticker | ||
json.Unmarshal(d.Body, &ticker) | ||
for i, _ := range AllMarkets { | ||
if AllMarkets[i].Id == ticker.MarketId { | ||
AllMarkets[i].Ticker = ticker.TickerAspect | ||
} | ||
} | ||
} | ||
return | ||
}() | ||
} |
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
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
Oops, something went wrong.