github.com/vmpartner/bitmex@v1.1.0/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/vmpartner/bitmex/tools"
     6  	"os"
     7  )
     8  
     9  type Config struct {
    10  	Host    string
    11  	Key     string
    12  	Secret  string
    13  	Timeout int64
    14  	DB      struct {
    15  		Host     string
    16  		Login    string
    17  		Password string
    18  		Name     string
    19  	}
    20  	Neural struct {
    21  		Iterations int
    22  		Predict    float64
    23  	}
    24  	Strategy struct {
    25  		Profit   float64
    26  		StopLose float64
    27  		Quantity float32
    28  	}
    29  }
    30  
    31  type MasterConfig struct {
    32  	IsDev  bool
    33  	Master Config
    34  	Dev    Config
    35  }
    36  
    37  func LoadConfig(path string) Config {
    38  	config := LoadMasterConfig(path)
    39  	if config.IsDev {
    40  		return config.Dev
    41  	}
    42  
    43  	return config.Master
    44  }
    45  
    46  func LoadMasterConfig(path string) MasterConfig {
    47  	file, err := os.Open(path)
    48  	tools.CheckErr(err)
    49  	defer file.Close()
    50  	decoder := json.NewDecoder(file)
    51  	config := MasterConfig{}
    52  	err = decoder.Decode(&config)
    53  	tools.CheckErr(err)
    54  
    55  	return config
    56  }