예제 #1
0
파일: pit.go 프로젝트: postfix/pit
func main() {
	if len(os.Args) > 1 {
		cfg.Init("pit", os.Args[1])

		log.SetLogger(
			log.Levels[cfg.GetStr("logger", "level")],
			cfg.GetStr("logger", "log_file"),
			cfg.GetInt("logger", "max_log_size_mb"),
		)
	} else {
		cfg.Init("pit", "dev")
	}
	runtime.GOMAXPROCS(runtime.NumCPU())

	usersModel := users.GetModel(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"))

	accountsManager := accountsmanager.Init(
		cfg.GetStr("rec-api", "base-url"),
		cfg.GetStr("mail", "addr"),
		cfg.GetStr("mail", "server"),
		cfg.GetInt("mail", "port"),
		usersModel)

	shardsManager := shardsmanager.Init(
		cfg.GetStr("aws", "prefix"),
		cfg.GetStr("aws", "region"),
		cfg.GetStr("aws", "s3-backups-path"),
		int(cfg.GetInt("rec-api", "port")),
		usersModel,
		cfg.GetStr("mail", "addr"))

	api.Init(
		shardsManager,
		accountsManager,
		cfg.GetStr("rec-api", "static"),
		int(cfg.GetInt("rec-api", "port")),
		int(cfg.GetInt("rec-api", "ssl-port")),
		cfg.GetStr("rec-api", "ssl-cert"),
		cfg.GetStr("rec-api", "ssl-key"))

	log.Info("System started...")
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
	// Block until a signal is received.
	<-c

	log.Info("Stopping all the services")
	shardsManager.Stop()
}
예제 #2
0
func TestPlaceOrder(t *testing.T) {
	cfg.Init("v", "dev")

	api, err := InitOandaApi(
		cfg.GetStr("oanda", "endpoint"),
		cfg.GetStr("oanda", "token"),
		int(cfg.GetInt("oanda", "account-id")),
		strings.Split(cfg.GetStr("oanda", "currencies"), ","),
		cfg.GetStr("oanda", "exanges-log"),
	)

	if err != nil {
		t.Error("Problem connecting with oanda, Error:", err)
	}

	curr := api.GetBaseCurrency()
	if curr != "EUR" {
		t.Error("The configured value on the test account was EUR, but:", curr, "was returned")
	}

	currs := api.GetCurrencies()
	log.Debug(currs)

	order, err := api.Buy("USD", 1, 1.3, true, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Sell("USD", 1, 1.0, true, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Buy("USD", 1, 1.3, false, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}

	order, err = api.Sell("USD", 1, 1.0, false, time.Now().Unix())
	if err != nil {
		t.Error("Problem placing an order, Error:", err)
	}

	err = api.CloseOrder(order, time.Now().Unix())
	if err != nil {
		t.Error("Problem closing an order, Error:", err)
	}
}
예제 #3
0
파일: pit-cli.go 프로젝트: postfix/pit
func main() {
	app := kingpin.New("pit-cli", "Pit-cli is a tool to manage all the different features of the recommener system Pit")

	env := app.Flag("env", "Configuration environment: pro, pre, dev").Required().Enum("pro", "pre", "dev")

	cmdInstances := app.Command("instances", "Manage all the instances of the cluster")
	cmdInstancesList := cmdInstances.Command("list", "Lists all the instances on the clusted")

	cmdUsers := app.Command("users", "Users management")
	cmdUsersList := cmdUsers.Command("list", "lists all the users")

	cmdUsersAdd := cmdUsers.Command("add", "Adds a new user")
	cmdUsersAddUID := cmdUsersAdd.Arg("user-ID", "User ID").Required().String()
	cmdUsersAddKey := cmdUsersAdd.Arg("key", "User Password").Required().String()

	cmdUsersShow := cmdUsers.Command("show", "Shows all the sotred information for a specific user")
	cmdUsersShowUID := cmdUsersShow.Arg("user-ID", "User ID").Required().String()
	cmdUsersEnable := cmdUsers.Command("enable", "Enables a disabled user account")
	cmdUsersEnableUID := cmdUsersEnable.Arg("user-ID", "User ID").Required().String()
	cmdUsersDisable := cmdUsers.Command("disable", "Disables an enabled user account")
	cmdUsersDisableUID := cmdUsersDisable.Arg("user-ID", "User ID").Required().String()

	cmdGroups := app.Command("groups", "Manage all the recommendation groups allocated by Pit")
	cmdGroupsList := cmdGroups.Command("list", "lists all the shards in the system")
	cmdGroupsListUser := cmdGroupsList.Flag("userid", `List the instances for this user`).String()

	cmdGroupsDel := cmdGroups.Command("del", "Removes one of the groups")
	cmdGroupsDelGroupID := cmdGroupsDel.Arg("group-id", `ID of the group to be removed`).Required().String()

	cmdGroupsAdd := cmdGroups.Command("update", "Adds or updates an existing shard")
	cmdGroupsAddMaxScore := cmdGroupsAdd.Flag("max-score", `Max possible score`).Required().Int()
	cmdGroupsAddNumShards := cmdGroupsAdd.Flag("num-shards", `Total number of shards`).Required().Int()
	cmdGroupsAddMaxElements := cmdGroupsAdd.Flag("num-elems", `Max number of elements that can be allocated by shard`).Required().Int()
	cmdGroupsAddMaxReqSec := cmdGroupsAdd.Flag("max-req-sec", `Max number of requests by second`).Required().Int()
	cmdGroupsAddMaxInsertReqSec := cmdGroupsAdd.Flag("max-ins-req-sec", `Max number of insert requests`).Required().Int()
	cmdGroupsAddUserID := cmdGroupsAdd.Flag("user-id", `User ID of the owner of this group`).Required().String()
	cmdGroupsAddGroupID := cmdGroupsAdd.Flag("group-id", `ID of the group to be updated or added`).Required().String()

	kingpin.MustParse(app.Parse(os.Args[1:]))
	cfg.Init("pit", *env)
	switch kingpin.MustParse(app.Parse(os.Args[1:])) {
	case cmdInstancesList.FullCommand():
		listInstances()

	case cmdGroupsList.FullCommand():
		listGroups(*cmdGroupsListUser)

	case cmdGroupsDel.FullCommand():
		delGroup(*cmdGroupsDelGroupID)

	case cmdGroupsAdd.FullCommand():
		addGroup(
			*cmdGroupsAddUserID,
			*cmdGroupsAddGroupID,
			*cmdGroupsAddNumShards,
			uint64(*cmdGroupsAddMaxElements),
			uint64(*cmdGroupsAddMaxReqSec),
			uint64(*cmdGroupsAddMaxInsertReqSec),
			uint8(*cmdGroupsAddMaxScore))

	case cmdUsersAdd.FullCommand():
		addUser(*cmdUsersAddUID, *cmdUsersAddKey)

	case cmdUsersList.FullCommand():
		listUsers()

	case cmdUsersShow.FullCommand():
		showUserInfo(*cmdUsersShowUID)

	case cmdUsersEnable.FullCommand():
		enableUser(*cmdUsersEnableUID)

	case cmdUsersDisable.FullCommand():
		disableUser(*cmdUsersDisableUID)

	default:
		fmt.Printf("Not command specified, use: \"%s --help\" to get help\n", strings.Join(os.Args, " "))
	}
}