Ejemplo n.º 1
0
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)
	}
}
Ejemplo n.º 2
0
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)
	}
}
Ejemplo n.º 3
0
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)
	}
}
Ejemplo n.º 4
0
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)
	}
}
Ejemplo n.º 5
0
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)
	}
}
Ejemplo n.º 6
0
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)
	}
}
Ejemplo n.º 7
0
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
}