-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
69 lines (58 loc) · 1.84 KB
/
main.go
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"
sdk "github.com/TinkoffCreditSystems/invest-openapi-go-sdk"
"log"
"os"
conf "tinkoff-invest-dumper/config"
dict "tinkoff-invest-dumper/dictionary"
"tinkoff-invest-dumper/eventer"
"tinkoff-invest-dumper/writer"
)
func main() {
logger := log.New(os.Stdout, "", log.LstdFlags)
config := conf.NewConfig(logger)
if config.Version {
fmt.Printf("%s\n", conf.VersionString)
os.Exit(0)
}
sandboxRestClient := sdk.NewSandboxRestClient(config.Token)
streamingClient, err := sdk.NewStreamingClient(logger, config.Token)
if err != nil {
logger.Fatalln("streaming client:", err)
}
defer func() {
err := streamingClient.Close()
if err != nil {
logger.Fatalln("streaming client:", err)
}
}()
dictionary, err := dict.NewDictionary(sandboxRestClient, dict.MergeTickers(config.GetOrderbookTickers(), config.GetCandleTickers()))
if err != nil {
logger.Fatalln("dictionary:", err)
}
receiver := eventer.NewEventReceiver(logger, streamingClient, dictionary)
writer := writer.NewWriter(logger, dictionary)
for _, ticker := range config.GetOrderbookTickers() {
channel := receiver.SubscribeToOrderbook(ticker, config.OrderbookDepth)
figi, err := dictionary.GetFIGIByTicker(ticker)
if err != nil {
logger.Fatalln("subscribe ticker:", err)
}
logger.Println("Subscribed to orderbook", ticker, figi)
path := config.BuildOrderbookPath(ticker)
go writer.OrderbookWriter(channel, path)
}
for _, ticker := range config.GetCandleTickers() {
channel := receiver.SubscribeToCandle(ticker, config.CandleInterval)
figi, err := dictionary.GetFIGIByTicker(ticker)
if err != nil {
logger.Fatalln("subscribe candle:", err)
}
logger.Println("Subscribed to candles", ticker, figi)
path := config.BuildCandlePath(ticker)
go writer.CandleWriter(channel, path)
}
go receiver.Start()
select {} // sleep(0), epta
}