forked from jeremyletang/vegamm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (59 loc) · 1.99 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
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
wallet "github.com/jeremyletang/vega-go-sdk/wallet"
)
const (
defaultAppPort = 8080
defaultWalletURL = "http://127.0.0.1:1789"
defaultVegaGRPCURL = "n11.testnet.vega.xyz:3007"
defaultBinanceWSURL = "wss://stream.binance.com:443/ws"
)
var (
appPort uint
vegaGRPCURL string
walletURL string
walletToken string
walletPubkey string
binanceWSURL string
vegaMarket string
binanceMarket string
)
func init() {
flag.UintVar(&appPort, "port", defaultAppPort, "port of the http API")
flag.StringVar(&vegaGRPCURL, "vega-grpc-url", defaultVegaGRPCURL, "a vega grpc server")
flag.StringVar(&walletURL, "wallet-url", defaultWalletURL, "a vega wallet service address")
flag.StringVar(&walletToken, "wallet-token", "", "a vega wallet token (for info see vega wallet token-api -h)")
flag.StringVar(&walletPubkey, "wallet-pubkey", "", "a vega public key")
flag.StringVar(&binanceWSURL, "binance-ws-url", defaultBinanceWSURL, "binance websocket url")
flag.StringVar(&vegaMarket, "vega-market", "", "a vega market id")
flag.StringVar(&binanceMarket, "binance-market", "", "a binance market symbol")
}
func main() {
config := parseFlags()
// connect to the wallet
w, err := wallet.NewClient(config.WalletURL, config.WalletToken)
if err != nil {
log.Fatalf("could not connect to the wallet: %v", err)
}
// share binance reference price for the given market
binanceRefPrice := NewBinanceRP(config.BinanceMarket)
// listening to the binance data
go BinanceAPI(config, binanceRefPrice)
// start the vega API stuff
vegaStore := NewVegaStore()
go VegaAPI(config, vegaStore)
// start the strategy
go RunStrategy(config, w, vegaStore, binanceRefPrice)
// start the state API
go StartAPI(config, vegaStore, binanceRefPrice)
// just waiting for users to close
gracefulStop := make(chan os.Signal, 1)
signal.Notify(gracefulStop, syscall.SIGTERM, syscall.SIGINT)
<-gracefulStop
log.Print("closing on user request.")
}