from app.config import Settings from app.instrument import ( DEFAULT_SYMBOL, get_instrument, instrument_for_symbol, INSTRUMENTS, ) def test_settings_default_to_the_es_profile(): settings = Settings() assert settings.instrument == "es" assert settings.profile.tick == 0.25 assert Settings(instrument="gc").profile.schwab_symbol == "/GC" def test_es_is_the_default_profile(): es = get_instrument("es") assert es.schwab_symbol == DEFAULT_SYMBOL assert es.tick == 0.25 assert es.rth == "spy_rth" def test_nq_shares_es_tick_and_rth(): nq = get_instrument("nq") es = get_instrument("es") assert nq.tick == es.tick assert nq.rth == es.rth assert nq.schwab_symbol == "/NQ" def test_gold_and_oil_are_not_quarter_ticks(): assert get_instrument("gc").tick == 0.10 assert get_instrument("gc").rth == "none" assert get_instrument("cl").tick == 0.01 assert get_instrument("cl").rth == "nymex_day" def test_yahoo_and_schwab_names_map_to_the_same_root(): assert instrument_for_symbol("ES=F").schwab_symbol == "/ES" assert instrument_for_symbol("/ES").id == "es" assert instrument_for_symbol("GC=F").id == "gc" assert instrument_for_symbol("unknown").id == "es" def test_unknown_instrument_id_is_rejected(): try: get_instrument("btc") except ValueError as error: assert "btc" in str(error) else: raise AssertionError("unknown id was accepted") def test_gold_snap_is_not_a_quarter_point(): gc = get_instrument("gc") assert gc.snap(3450.07) == 3450.10 assert get_instrument("es").snap(6400.10) == 6400.00 assert get_instrument("cl").snap(70.014) == 70.01 def test_every_planned_root_is_in_the_table(): assert set(INSTRUMENTS) == {"es", "nq", "gc", "cl"}