Skip to content

Commit

Permalink
various pointer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling committed Aug 6, 2017
1 parent 4506a11 commit be598e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 26 additions & 14 deletions streaming/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"log"
"strconv"
"time"
//"os"
//"fmt"
)

func CreateMarketCache(changeMessage MarketChangeMessage, marketChange MarketChange) *MarketCache {
cache := MarketCache{
changeMessage.PublishTime,
&changeMessage.PublishTime,
marketChange.MarketId,
marketChange.TradedVolume,
*marketChange.MarketDefinition,
&marketChange.TradedVolume,
marketChange.MarketDefinition,
make(map[int64]RunnerCache),
}
for _, runnerChange := range marketChange.RunnerChange {
Expand Down Expand Up @@ -332,22 +334,21 @@ func (cache *RunnerCache) UpdateCache(change RunnerChange) {
}

type MarketCache struct {
PublishTime int
PublishTime *int
MarketId string
TradedVolume float64
MarketDefinition MarketDefinition
TradedVolume *float64
MarketDefinition *MarketDefinition
Runners map[int64]RunnerCache
}

func (cache *MarketCache) UpdateCache(changeMessage MarketChangeMessage, marketChange MarketChange) {
cache.PublishTime = changeMessage.PublishTime
*cache.PublishTime = changeMessage.PublishTime

if marketChange.MarketDefinition != nil {
cache.MarketDefinition = *marketChange.MarketDefinition
log.Println("Update", marketChange.MarketDefinition)
*cache.MarketDefinition = *marketChange.MarketDefinition
}
if marketChange.TradedVolume != 0 {
cache.TradedVolume = marketChange.TradedVolume
*cache.TradedVolume = marketChange.TradedVolume
}
if marketChange.RunnerChange != nil {
for _, runnerChange := range marketChange.RunnerChange {
Expand All @@ -358,10 +359,21 @@ func (cache *MarketCache) UpdateCache(changeMessage MarketChangeMessage, marketC
}
}
}
tem, _ := cache.Runners[12787754]
s := strconv.Itoa(cache.PublishTime)
log.Println(MsToTime(s), tem.SelectionId, *tem.LastTradedPrice, len(tem.Traded.Prices), *tem.TradedVolume,
len(tem.AvailableToBack.Prices), cache.MarketDefinition.Status, cache.MarketDefinition.BetDelay, cache.MarketDefinition.CrossMatching)
//tem, _ := cache.Runners[12943079]
//s := strconv.Itoa(*cache.PublishTime)
//s_t := fmt.Sprintf("%v,%v,%v,%v,%v,%v,%v,%v,%v\n",
// MsToTime(s).Format("2006-01-02 15:04:05.999999"), tem.SelectionId, *tem.LastTradedPrice, len(tem.Traded.Prices), *tem.TradedVolume,
// len(tem.AvailableToBack.Prices), cache.MarketDefinition.Status, cache.MarketDefinition.BetDelay,
// cache.MarketDefinition.CrossMatching)
//
//f, err := os.OpenFile("tempertrap.txt", os.O_APPEND|os.O_WRONLY, 0600)
//if err != nil {
// panic(err)
//}
//defer f.Close()
//if _, err = f.WriteString(s_t); err != nil {
// panic(err)
//}
}

func MsToTime(ms string) (time.Time) {
Expand Down
2 changes: 2 additions & 0 deletions streaming/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type MarketDefinition struct {
BspReconciled bool `json:"bspReconciled"`
LineInterval float64 `json:"lineInterval"`
Status string `json:"status"`
PriceLadderDescription string `json:"priceLadderDescription"`
KeyLineDefinition string `json:"keyLineDefinition"`
}

type RunnerChange struct {
Expand Down

0 comments on commit be598e6

Please sign in to comment.