This repository was archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproject_routine.go
More file actions
70 lines (51 loc) · 1.46 KB
/
project_routine.go
File metadata and controls
70 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"time"
"sync"
)
/*
* Main Routine for Project Management
*/
func ProjectRoutine(wg *sync.WaitGroup){
defer wg.Done()
fmt.Printf("ProjectTick Start: \t%s\n\n", time.Now().Format("2006-01-02 15:04:05.004005683"))
// start a goroutine to get realtime project management in 1 min interval
ticker := projectTicker()
var tickerCount = 0
loop:
for {
select {
case _ = <- routinesExitChan:
break loop
case tick := <-ticker.C:
ticker.Stop()
//RoiReport()
tickerCount += 1
fmt.Printf("ProjectTick: \t\t%s\t%d\n", tick.Format("2006-01-02 15:04:05.004005683"), tickerCount)
// account query can auto-import the project and tracking
QueryAccount()
// trades query can give the new project basic info such as InitialBalance, InitialPrice.
QueryMyTrades()
// orders query can get the final state of order if it's not finalized,
// but they are already in local database via GetAllOrders() in ProjectManager()
QueryOrders()
ProjectManager()
// Update the ticker
ticker = projectTicker()
default:
time.Sleep(100 * time.Millisecond)
}
}
fmt.Println("goroutine exited - ProjectRoutine")
}
func projectTicker() *time.Ticker {
now := time.Now()
second := 45 - now.Second() // range: [45..-15]
if second <= 0 {
second += 60 // range: [45..0] + [45..60] -> [0..60]
}
return time.NewTicker(
time.Second * time.Duration(second) -
time.Nanosecond * time.Duration(now.Nanosecond()))
}