forked from jeremyletang/vegamm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
44 lines (38 loc) · 1.01 KB
/
api.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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
apipb "code.vegaprotocol.io/vega/protos/data-node/api/v2"
vegapb "code.vegaprotocol.io/vega/protos/vega"
"github.com/shopspring/decimal"
)
type State struct {
Position *vegapb.Position
Market *vegapb.Market
MarketData *vegapb.MarketData
BestBid decimal.Decimal
BestAsk decimal.Decimal
Orders []*vegapb.Order
Accounts []*apipb.AccountBalance
Assets []*vegapb.Asset
}
func StartAPI(config *Config, vega *VegaStore, refPrice *BinanceRP) {
http.HandleFunc("/state", func(w http.ResponseWriter, r *http.Request) {
bid, ask := refPrice.Get()
state := State{
Position: vega.GetPosition(),
Market: vega.GetMarket(),
MarketData: vega.GetMarketData(),
Orders: vega.GetOrders(),
Accounts: vega.GetAccounts(),
BestBid: bid,
BestAsk: ask,
Assets: vega.GetAssets(),
}
out, _ := json.Marshal(&state)
fmt.Fprintf(w, "%v", string(out))
})
log.Fatal(http.ListenAndServe(":8080", nil))
}