Example #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)
	}
}
Example #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)
	}
}
Example #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)
	}
}
Example #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)
	}
}
Example #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)
	}
}
Example #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)
	}
}
Example #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
}