Add Market order tracking
This commit is contained in:
parent
101db8707d
commit
4088dfb25b
1 changed files with 77 additions and 0 deletions
77
main.go
77
main.go
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
ESIClones "./client/clones"
|
||||
ESILocation "./client/location"
|
||||
ESIMarket "./client/market"
|
||||
ESIPlanetaryInteraction "./client/planetary_interaction"
|
||||
ESISkills "./client/skills"
|
||||
ESIUniverse "./client/universe"
|
||||
|
@ -121,6 +122,7 @@ func main() {
|
|||
cloneInfoChan := make(chan string)
|
||||
planetInfoChan := make(chan string)
|
||||
skillsInfoChan := make(chan string)
|
||||
marketInfoChan := make(chan string)
|
||||
|
||||
go func() {
|
||||
charInfoChan <- printCharacterInformation(swaggerclient, m)
|
||||
|
@ -137,6 +139,11 @@ func main() {
|
|||
close(planetInfoChan)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
marketInfoChan <- printCharacterMarketOrders(swaggerclient, m)
|
||||
close(marketInfoChan)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
skillsInfoChan <- printCharacterSkillQueue(swaggerclient, m)
|
||||
close(skillsInfoChan)
|
||||
|
@ -160,6 +167,11 @@ func main() {
|
|||
for msg := range skillsInfoChan {
|
||||
fmt.Print(msg)
|
||||
}
|
||||
|
||||
fmt.Printf("\n\nMarket orders\n")
|
||||
for msg := range marketInfoChan {
|
||||
fmt.Print(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func readConfigurationFile() (*InternalUtils.HTTPConfiguration, error) {
|
||||
|
@ -592,6 +604,71 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) string {
|
|||
return content
|
||||
}
|
||||
|
||||
func printCharacterMarketOrders(swaggerclient *ESI.App, m *Character) string {
|
||||
cloCallParams := ESIMarket.NewGetCharactersCharacterIDOrdersParams()
|
||||
cloCallParams.WithCharacterID(m.CharacterID)
|
||||
|
||||
cloresponse, cloerr := swaggerclient.Market.GetCharactersCharacterIDOrders(cloCallParams, nil)
|
||||
if cloerr != nil {
|
||||
fmt.Println("Error while getting the current character market orders.")
|
||||
log.Fatalf("Got error on GetCharactersCharacterIDOrders: %s", cloerr)
|
||||
}
|
||||
|
||||
ac := accounting.Accounting{Symbol: "", Precision: 2, Thousand: "'"}
|
||||
|
||||
var content string
|
||||
|
||||
orders := cloresponse.Payload
|
||||
|
||||
ptIds := make([]int32, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
ptIds = append(ptIds, *order.TypeID)
|
||||
}
|
||||
pinNames := getUniverseNames(swaggerclient, &ptIds)
|
||||
|
||||
for _, order := range orders {
|
||||
expirationDate := time.Time(*order.Issued).Add(time.Duration(*order.Duration) * time.Hour * 24)
|
||||
remainingAmount := *order.Price * float32(*order.VolumeRemain)
|
||||
remainingDuration := expirationDate.Sub(time.Now())
|
||||
|
||||
buySellStatus := "↟"
|
||||
if *order.IsBuyOrder {
|
||||
buySellStatus = "↡"
|
||||
}
|
||||
|
||||
status := ""
|
||||
|
||||
if remainingDuration.Hours() <= 0 {
|
||||
status = fmt.Sprint(aurora.Red(buySellStatus).Bold())
|
||||
} else if remainingDuration.Hours() <= 72 {
|
||||
status = fmt.Sprint(aurora.Magenta(buySellStatus).Bold())
|
||||
} else {
|
||||
status = fmt.Sprint(aurora.Green(buySellStatus).Bold())
|
||||
}
|
||||
|
||||
quantity := fmt.Sprintf("%d/%d", *order.VolumeRemain, *order.VolumeTotal)
|
||||
pctRemaining := float32(*order.VolumeRemain) / float32(*order.VolumeTotal)
|
||||
if pctRemaining <= 0.25 {
|
||||
quantity = fmt.Sprint(aurora.Red(quantity))
|
||||
} else if pctRemaining <= 0.5 {
|
||||
quantity = fmt.Sprint(aurora.Brown(quantity))
|
||||
} else {
|
||||
quantity = fmt.Sprint(aurora.Green(quantity))
|
||||
}
|
||||
|
||||
content = content + fmt.Sprintf(" %s % 25.25s ISK % 12s %s ISK % 13s (%s)\n",
|
||||
status,
|
||||
pinNames[*order.TypeID],
|
||||
ac.FormatMoney(*order.Price),
|
||||
expirationDate.Format(defaultDateFormat),
|
||||
ac.FormatMoney(remainingAmount),
|
||||
quantity,
|
||||
)
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string {
|
||||
itemNames := make(map[int32]string)
|
||||
itemMissingNames := make(map[int32]string)
|
||||
|
|
Reference in a new issue