Bedtools get fasta and ORF from a blastX run
Blast uses a 1-based coordinate system. Bed is 0-based half open. Your code needs to convert appropriately. See for example: https://www.biostars.org/p/317112/ .