add account and account balances

This commit is contained in:
c9s 2021-01-24 20:18:04 +08:00
parent eab915abc7
commit 7310700540
2 changed files with 33 additions and 4 deletions

View File

@ -61,6 +61,35 @@ func RunServer(ctx context.Context, userConfig *Config, environ *Environment) er
c.JSON(http.StatusOK, gin.H{"orders": marketOrders})
})
r.GET("/sessions/:session/account", func(c *gin.Context) {
sessionName := c.Param("session")
session, ok := environ.Session(sessionName)
if !ok {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("session %s not found", sessionName)})
return
}
c.JSON(http.StatusOK, gin.H{"account": session.Account})
})
r.GET("/sessions/:session/account/balances", func(c *gin.Context) {
sessionName := c.Param("session")
session, ok := environ.Session(sessionName)
if !ok {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("session %s not found", sessionName)})
return
}
if session.Account == nil {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("the account of session %s is nil", sessionName)})
return
}
c.JSON(http.StatusOK, gin.H{"balances": session.Account.Balances()})
})
r.GET("/sessions/:session/symbols", func(c *gin.Context) {
sessionName := c.Param("session")

View File

@ -50,11 +50,11 @@ func (m BalanceMap) Print() {
}
type Account struct {
sync.Mutex
sync.Mutex `json:"-"`
MakerCommission int `json:"makerCommission"`
TakerCommission int `json:"takerCommission"`
AccountType string `json:"accountType"`
MakerCommission int `json:"makerCommission,omitempty"`
TakerCommission int `json:"takerCommission,omitempty"`
AccountType string `json:"accountType,omitempty"`
balances BalanceMap
}