-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
132 lines (107 loc) · 3.43 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"github.com/Forau/yanngo/api"
"github.com/Forau/yanngo/feed"
"github.com/Forau/yanngo/feed/feedmodel"
"github.com/Forau/yanngo/remote"
"github.com/Forau/yanngo/remote/nsqconn"
"github.com/Forau/yanngo/transports"
"io/ioutil"
"os"
"flag"
"log"
"strings"
)
// For multiple flags
type StringArray []string
func (a *StringArray) Set(s string) error {
*a = append(*a, s)
return nil
}
func (a *StringArray) String() string {
return strings.Join(*a, ",")
}
var (
user = flag.String("user", "", "User name")
pass = flag.String("pass", "", "Password")
endpoint = flag.String("url", "https://api.test.nordnet.se/next/2", "The base URL.")
topic = flag.String("topic", "nordnet.api", "Topic to listen on")
feedTopic = flag.String("feedtop", "nordnet.feed", "Topic to send feed on")
pemFile = flag.String("pem", "../../NEXTAPI_TEST_public.pem", "The PEM file")
)
func main() {
var nsqIps StringArray
flag.Var(&nsqIps, "nsqd", "NSQD ip's. (Can be used multiple times for each nsqd)")
flag.Parse()
file, err := os.Open(*pemFile)
if err != nil {
panic(err)
}
pem, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}
baseNordnetTransport, err := transports.NewDefaultTransport(*endpoint, []byte(*user), []byte(*pass), pem)
if err != nil {
panic(err)
}
cacheHandler := transports.NewSimpleMemoryCacheHandler()
nordnetTransport, _ := api.NewCachedTransportRouter(cacheHandler, baseNordnetTransport)
nsqb := nsqconn.NewNsqBuilder()
nsqb.AddNsqdIps(nsqIps...)
log.Printf("Added IP's: %+v", nsqIps)
nsqd, err := nsqb.Build()
if err != nil {
panic(err)
}
// TODO: Optional for server?
pubsub, err := remote.NewReplyablePubSubWithInbox(nsqd, "INBOX.nsqnnd.client")
if err != nil {
panic(err)
}
log.Printf("We have our nsq: %+v", pubsub)
log.Printf("We have our transport: %+v", nordnetTransport)
err = transports.BindRemoteTransportServer(*topic, pubsub, nordnetTransport)
if err != nil {
panic(err)
}
apiCli := api.NewApiClient(nordnetTransport)
// Feed
feedTopicStream := remote.MakeStreamTopicChannel(nsqd, *feedTopic)
feedCb := feed.NewFeedTransport(feedTopicStream).SetInfo("topic", *feedTopic)
err = nordnetTransport.AddTransportHandler(feedCb)
if err != nil {
log.Printf("Unable to route %+v: %+v", feedCb, err)
}
feedd, err := feed.NewFeedDaemon(feed.MakePrivateSessionProvider(apiCli),
feed.MakePublicSessionProvider(apiCli),
feedCb,
)
if err != nil {
panic(err)
}
feedCb.AddSubscription(&feedmodel.FeedCmd{Cmd: "subscribe", Args: map[string]interface{}{"t": "price", "i": "101", "m": 11}})
log.Printf("We have feedd: %+v", feedd)
res, err := apiCli.FeedSub("depth", "46", "11")
log.Printf("Res::: %+v -- %+v", res, err)
/*
// FOR TEST....
rchan := remote.MakeRequestReplyChannel(pubsub, *topic)
rtrans := transports.NewRemoteTransportClient(rchan)
cli := api.NewApiClient(rtrans)
acc,err := cli.Accounts()
log.Printf("Accounts: %+v, %+v",acc,err)
// -------------- Old tests
l, _ := net.Listen("tcp", *bind)
srv := gorpc.NewRpcTransportServer(l, ph)
defer srv.Close()
// Start feed. (badly)
cli := api.NewApiClient(ph)
nsqips := []string{"127.0.0.1:6150"}
nsqConfig := map[string]interface{}{}
nf, err := nsqfeeder.NewNsqfeeder("nodent.feed", "nordnet.admin", nsqips, nsqConfig, cli)
log.Printf("NSQ: %+v, err: %+v", nf, err)
*/
c := make(chan interface{})
log.Print(<-c)
}