mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
add account and account balances
This commit is contained in:
parent
eab915abc7
commit
7310700540
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user