refactor and add doc comment for InitExchangeSession

This commit is contained in:
c9s 2021-12-25 23:42:29 +08:00
parent 307d0b8e1f
commit ba8ebfe3a7
3 changed files with 7 additions and 4 deletions

View File

@ -213,7 +213,7 @@ func (environ *Environment) AddExchangesByViperKeys() error {
func (environ *Environment) AddExchangesFromSessionConfig(sessions map[string]*ExchangeSession) error {
for sessionName, session := range sessions {
if err := InitExchangeSession(sessionName, session, nil); err != nil {
if err := session.InitExchange(sessionName, nil); err != nil {
return err
}

View File

@ -683,7 +683,10 @@ func (session *ExchangeSession) FindPossibleSymbols() (symbols []string, err err
return symbols, nil
}
func InitExchangeSession(name string, session *ExchangeSession, exchange types.Exchange) error {
// InitExchange initialize the exchange instance and allocate memory for fields
// In this stage, the session var could be loaded from the JSON config, so the pointer fields are still nil
// The Init method will be called after this stage, environment.Init will call the session.Init method later.
func (session *ExchangeSession) InitExchange(name string, exchange types.Exchange) error {
var err error
var exchangeName = session.ExchangeName
if exchange == nil {

View File

@ -133,7 +133,7 @@ func (s *Server) newEngine() *gin.Engine {
return
}
err := bbgo.InitExchangeSession(session.ExchangeName.String(), &session, nil)
err := session.InitExchange(session.ExchangeName.String(), nil)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
@ -182,7 +182,7 @@ func (s *Server) newEngine() *gin.Engine {
return
}
if err := bbgo.InitExchangeSession(session.ExchangeName.String(), &session, nil); err != nil {
if err := session.InitExchange(session.ExchangeName.String(), nil); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})