コード例 #1
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecuritySymbol(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := "AAPL"
	if security.Symbol != expected {
		t.Errorf(errorMessage, expected, security.Symbol)
	}
}
コード例 #2
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecurityTestIssue(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := false
	if security.TestIssue != expected {
		t.Errorf(errorMessage, expected, security.TestIssue)
	}
}
コード例 #3
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecurityRoundLotSize(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := 100
	if security.RoundLotSize != expected {
		t.Errorf(errorMessage, expected, security.RoundLotSize)
	}
}
コード例 #4
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecurityMarketCategory(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := "Q"
	if security.MarketCategory != expected {
		t.Errorf(errorMessage, expected, security.MarketCategory)
	}
}
コード例 #5
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecurityFinancialStatus(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := "N"
	if security.FinancialStatus != expected {
		t.Errorf(errorMessage, expected, security.FinancialStatus)
	}
}
コード例 #6
0
ファイル: security_test.go プロジェクト: ghg/investments
func TestNewSecurityExchangeId(t *testing.T) {
	security := models.NewSecurity(2, "N", "Q", "Apple Inc. - Common Stock", 100, "AAPL", false)

	expected := 2
	if security.ExchangeId != expected {
		t.Errorf(errorMessage, expected, security.ExchangeId)
	}
}
コード例 #7
0
ファイル: securities.go プロジェクト: ghg/investments
func importSecurities(buffer *bytes.Buffer) error {
	db, err := models.NewDB(os.Getenv("DB_TYPE"), connectionString())

	if err != nil {
		log.Panic(err)
		return err
	}

	reader := csv.NewReader(buffer)
	reader.Comma = '|'
	reader.FieldsPerRecord = 6

	currentLine := 0
	numSecurities := 0

	for {
		currentLine++
		row, err := reader.Read()

		if currentLine == 1 {
			log.Println("Skipping first line (header)")
			continue
		}

		match, _ := regexp.MatchString("^File Creation", row[0])
		if match {
			log.Println("Done, skipping last line (file creation)")
			break
		}

		if err != nil {
			if err == io.EOF {
				err = nil
			} else {
				log.Println("err: ", err)
			}
		}

		exchangeId := parseExchangeId()
		roundLotSize := parseRoundLotSize(row[roundLotSizeIndex])
		testIssue := parseTestIssue(row[testIssueIndex])

		security := models.NewSecurity(
			exchangeId,
			row[financialStatusIndex],
			row[marketCategoryIndex],
			row[securityNameIndex],
			roundLotSize,
			row[symbolIndex],
			testIssue,
		)
		db.Create(security)
		numSecurities++
	}

	if numSecurities != currentLine-2 {
		err = errors.New("The number of securities imported does not match")
		return err
	}

	log.Println("Imported securities:", numSecurities)
	return nil
}