Skip to content

Commit

Permalink
status fixed
Browse files Browse the repository at this point in the history
clean up to pointers
fmt run
  • Loading branch information
liampauling committed Oct 16, 2017
1 parent be598e6 commit 78f3839
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 65 deletions.
36 changes: 18 additions & 18 deletions betting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type eventType struct {
}

type eventTypeResult struct {
MarketCount int `json:"marketCount"`
EventType eventType `json:"eventType"`
MarketCount int `json:"marketCount"`
EventType eventType `json:"eventType"`
}

type competition struct {
Expand All @@ -18,9 +18,9 @@ type competition struct {
}

type competitionResult struct {
MarketCount int `json:"marketCount"`
CompetitionRegion string `json:"competitionRegion"`
Competition competition `json:"competition"`
MarketCount int `json:"marketCount"`
CompetitionRegion string `json:"competitionRegion"`
Competition competition `json:"competition"`
}

type timeRange struct {
Expand All @@ -29,8 +29,8 @@ type timeRange struct {
}

type timeRangeResult struct {
MarketCount int `json:"marketCount"`
TimeRange timeRange `json:"timeRange"`
MarketCount int `json:"marketCount"`
TimeRange timeRange `json:"timeRange"`
}

type event struct {
Expand All @@ -43,8 +43,8 @@ type event struct {
}

type eventResult struct {
MarketCount int `json:"marketCount"`
Event event `json:"event"`
MarketCount int `json:"marketCount"`
Event event `json:"event"`
}

type marketTypeResult struct {
Expand Down Expand Up @@ -93,15 +93,15 @@ type runnerCatalogue struct {
}

type marketCatalogue struct {
MarketId string `json:"marketId"`
MarketName string `json:"marketName"`
TotalMatched float32 `json:"totalMatched"`
MarketStartTime time.Time `json:"marketStartTime"`
Competition competition `json:"competition"`
Event event `json:"event"`
EventType eventType `json:"eventType"`
MarketCatalogueDescription marketCatalogueDescription `json:"description"`
Runners []runnerCatalogue `json:"runners"`
MarketId string `json:"marketId"`
MarketName string `json:"marketName"`
TotalMatched float32 `json:"totalMatched"`
MarketStartTime time.Time `json:"marketStartTime"`
Competition competition `json:"competition"`
Event event `json:"event"`
EventType eventType `json:"eventType"`
MarketCatalogueDescription marketCatalogueDescription `json:"description"`
Runners []runnerCatalogue `json:"runners"`
}

func (b *Betting) ListEventTypes(filter MarketFilter) ([]eventTypeResult, error) {
Expand Down
66 changes: 21 additions & 45 deletions streaming/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"log"
"strconv"
"time"
//"os"
//"fmt"
"os"
"fmt"
)

func CreateMarketCache(changeMessage MarketChangeMessage, marketChange MarketChange) *MarketCache {
cache := MarketCache{
cache := &MarketCache{
&changeMessage.PublishTime,
marketChange.MarketId,
&marketChange.TradedVolume,
Expand All @@ -19,7 +19,7 @@ func CreateMarketCache(changeMessage MarketChangeMessage, marketChange MarketCha
for _, runnerChange := range marketChange.RunnerChange {
cache.Runners[runnerChange.SelectionId] = *CreateRunnerCache(runnerChange)
}
return &cache
return cache
}

func CreateRunnerCache(change RunnerChange) *RunnerCache {
Expand Down Expand Up @@ -115,7 +115,7 @@ func CreateRunnerCache(change RunnerChange) *RunnerCache {
}
bestDisplayAvailableToLay.Reverse = false

cache := RunnerCache{
cache := &RunnerCache{
change.SelectionId,
&change.LastTradedPrice,
&change.TradedVolume,
Expand All @@ -129,7 +129,7 @@ func CreateRunnerCache(change RunnerChange) *RunnerCache {
&bestDisplayAvailableToBack,
&bestDisplayAvailableToLay,
}
return &cache
return cache
}

type AvailableInterface interface {
Expand Down Expand Up @@ -250,28 +250,6 @@ func (available *Available) Update(updates [][]float64) {
}
}

//func UpdateTwo(available AvailableInterface, updates [][]float64) {
// for _, update := range updates {
// updated := false
// for count, trade := range available.Prices {
// if trade.Price == update[0] {
// if update[1] == 0 {
// available.RemovePrice(count)
// updated = true
// break
// } else {
// available.UpdatePrice(count, update)
// updated = true
// break
// }
// }
// }
// if updated == false && update[1] != 0 {
// available.AppendPrice(update)
// }
// }
//}

type RunnerCache struct {
SelectionId int64
LastTradedPrice *float64
Expand Down Expand Up @@ -304,7 +282,6 @@ func (cache *RunnerCache) UpdateCache(change RunnerChange) {
//}
if len(change.Traded) > 0 {
cache.Traded.Update(change.Traded)
//UpdateTwo(cache.Traded)
}
if len(change.AvailableToBack) > 0 {
cache.AvailableToBack.Update(change.AvailableToBack)
Expand All @@ -320,7 +297,6 @@ func (cache *RunnerCache) UpdateCache(change RunnerChange) {
}
if len(change.BestAvailableToBack) > 0 {
cache.BestAvailableToBack.Update(change.BestAvailableToBack)
//UpdateTwo(cache.BestAvailableToBack)
}
if len(change.BestAvailableToLay) > 0 {
cache.BestAvailableToLay.Update(change.BestAvailableToLay)
Expand Down Expand Up @@ -359,21 +335,21 @@ func (cache *MarketCache) UpdateCache(changeMessage MarketChangeMessage, marketC
}
}
}
//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)
//}

f, err := os.OpenFile("tempertrap.txt", os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
defer f.Close()
for _, tem := range cache.Runners {
s := strconv.Itoa(*cache.PublishTime)
s_t := fmt.Sprintf("%v,%v,%v,%v,%v,%v,%v,%v,%v,%v\n",
MsToTime(s).Format("2006-01-02 15:04:05.999999"), cache.MarketId, tem.SelectionId,
*tem.LastTradedPrice, *tem.TradedVolume, cache.MarketDefinition.InPlay, *cache.TradedVolume)
if _, err = f.WriteString(s_t); err != nil {
panic(err)
}
}
}

func MsToTime(ms string) (time.Time) {
Expand Down
5 changes: 3 additions & 2 deletions streaming/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type MarketDefinition struct {
BetDelay int32 `json:"betDelay"`
BspMarket bool `json:"bspMarket"`
BettingType string `json:"bettingType"`
NumberOfActiveRunners int32 `json:"status"`
NumberOfActiveRunners int32 `json:"numberOfActiveRunners"`
LineMinUnit float64 `json:"lineMinUnit"`
EventId string `json:"eventId"`
CrossMatching bool `json:"crossMatching"`
Expand All @@ -45,11 +45,12 @@ type MarketDefinition struct {
Status string `json:"status"`
PriceLadderDescription string `json:"priceLadderDescription"`
KeyLineDefinition string `json:"keyLineDefinition"`
Name string `json:"name"`
}

type RunnerChange struct {
SelectionId int64 `json:"id"`
Handicap *float64 `json:"hc"`
Handicap float64 `json:"hc"`
TradedVolume float64 `json:"tv"`
LastTradedPrice float64 `json:"ltp"`
Traded [][]float64 `json:"trd"`
Expand Down

0 comments on commit 78f3839

Please sign in to comment.