Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "math"
  7. "os"
  8. "strings"
  9. "time"
  10.  
  11. ansi "github.com/k0kubun/go-ansi"
  12. "github.com/mitchellh/colorstring"
  13. bittrex "github.com/toorop/go-bittrex"
  14. )
  15.  
  16. type Configuration struct {
  17. APIKey string `json:"api_key"`
  18. APISecret string `json:"api_secret"`
  19. MinChange float64 `json:"min_change"`
  20. MinVolume float64 `json:"min_volume"`
  21. UpdateTime float64 `json:"update_time"`
  22. MaxVolume float64 `json:"max_volume"`
  23. }
  24.  
  25. func main() {
  26.  
  27. // LOAD CONFIG
  28. file, _ := os.Open("botsettings.json")
  29. decoder := json.NewDecoder(file)
  30. config := Configuration{}
  31. err := decoder.Decode(&config)
  32. if err != nil {
  33. fmt.Println("error:", err)
  34. }
  35.  
  36. bittrex := bittrex.New(config.APIKey, config.APISecret)
  37.  
  38. startSumVolume := make(map[string]float64)
  39. startSumPrice := make(map[string]float64)
  40. trackedCoins := make(map[string]bool)
  41.  
  42. ShowIntro(config.MinChange, config.MinVolume, config.MaxVolume)
  43.  
  44. sum, err := bittrex.GetMarketSummaries()
  45.  
  46. if err != nil {
  47. panic(err)
  48. }
  49.  
  50. for i := range sum {
  51. startSumVolume[sum[i].MarketName] = sum[i].BaseVolume
  52. startSumPrice[sum[i].MarketName] = sum[i].Last
  53. }
  54.  
  55. for true {
  56. summaries, err := bittrex.GetMarketSummaries()
  57.  
  58. found := 0
  59.  
  60. if err != nil {
  61. panic(err)
  62. }
  63.  
  64. for i := range summaries {
  65. change := PercentageChange(startSumVolume[summaries[i].MarketName], summaries[i].BaseVolume)
  66. priceChange := PercentageChange(startSumPrice[summaries[i].MarketName], summaries[i].Last)
  67. volIncrease := summaries[i].BaseVolume - startSumVolume[summaries[i].MarketName]
  68. volChangePercent := PercentageChange(startSumVolume[summaries[i].MarketName], summaries[i].BaseVolume)
  69. coinVolume := startSumVolume[summaries[i].MarketName]
  70.  
  71. if change > config.MinChange && volIncrease > config.MinVolume && strings.HasPrefix(summaries[i].MarketName, "BTC") && priceChange > 0 && config.MaxVolume > coinVolume {
  72.  
  73. found++
  74.  
  75. if _, ok := trackedCoins[summaries[i].MarketName]; !ok {
  76. trackedCoins[summaries[i].MarketName] = true
  77. } else {
  78. trackedCoins[summaries[i].MarketName] = false
  79. }
  80.  
  81. percColor := "[green]"
  82.  
  83. str := fmt.Sprintf("%v%v [yellow]%v [white]%v[green](%v%v) [white]%v [green](+%v / %v%v%v[green]) ",
  84. IfNew(trackedCoins, summaries[i].MarketName),
  85. time.Now().Format("15:04:05"),
  86. summaries[i].MarketName,
  87. summaries[i].Last,
  88. toFixed(priceChange, 2),
  89. "%",
  90. toFixed(summaries[i].BaseVolume, 9),
  91. toFixed(volIncrease, 2),
  92. percColor,
  93. toFixed(volChangePercent, 2),
  94. "%",
  95. )
  96.  
  97. colorstring.Fprintln(ansi.NewAnsiStdout(), str)
  98. } else {
  99. delete(trackedCoins, summaries[i].MarketName)
  100. }
  101. }
  102.  
  103. if found != 0 {
  104. fmt.Print("\n")
  105. }
  106.  
  107. time.Sleep(time.Duration(config.UpdateTime) * time.Second)
  108. }
  109. }
  110.  
  111. func ShowIntro(minChange, minVolume, maxVolume float64) {
  112. str := fmt.Sprintf(`
  113. [green]================================================================
  114. [green]// [yellow]LIL PRE-PUMP [red]PUMP [yellow]TOOL - v1.0 - November 29, 2017 - Author: [red]Luxio
  115. [green]================================================================
  116. [green]// Minimum Price Change: [yellow]%v%v
  117. [green]// Minimum Volume Change: [yellow]%v BTC
  118. [green]// Maximum Market Volume: [yellow]%v BTC
  119. [green]================================================================
  120. `, minChange, "%", minVolume, maxVolume,
  121. )
  122.  
  123. colorstring.Fprintln(ansi.NewAnsiStdout(), str)
  124. }
  125.  
  126. func PercentageChange(old, new float64) (delta float64) {
  127. diff := float64(new - old)
  128. delta = (diff / float64(old)) * 100
  129. return
  130. }
  131.  
  132. func round(num float64) int {
  133. return int(num + math.Copysign(0.5, num))
  134. }
  135.  
  136. func toFixed(num float64, precision int) float64 {
  137. output := math.Pow(10, float64(precision))
  138. return float64(round(num*output)) / output
  139. }
  140.  
  141. func IfNew(trackedCoins map[string]bool, market string) string {
  142. if trackedCoins[market] {
  143. return "[green]"
  144. }
  145. return ""
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement