As more polices are being applied to reduce the green gas emission, the construction of On-site Hydrogen Refueling Stations (OHRS) is necessary for the popularization of hydrogen powered vehicles. One of the most reliable energy resources for an OHRS would be the electric energy purchased from the grid. The electricity market is divided into day-ahead market and real-time market. Considering volatility electricity prices, and uncertainty of hydrogen demand, the paper presents an electricity transaction strategy model for a single OHRS. To avoid the combinatorial "explosion" with the number of uncertainties, by using Stochastic Dual Dynamic Programming (SDDP) algorithm, the expected cost-to-go function is approximated by piecewise linear functions, which improves the solution time. Real historical market data are used in case study. The results show that when the electricity prices and hydrogen loads fluctuate, the proposed model can optimize the electricity transaction strategy for OHRS under the condition of meeting the safety criteria. The study can provide a theoretical method for OHRS for the transaction strategies.