Exemplo n.º 1
0
async def green_light(pilot_name: str, passenger: AutoPilotTask,
                      etrade: AsyncEtrade) -> bool:
    # handle override signal
    if passenger.signal == AutoPilotTask.MANUAL_OVERRIDE:
        logger.info("%s %s received signal MANUAL_OVERRIDE.", PREFIX,
                    pilot_name)
        logger.info("%s %s releasing control...", PREFIX, pilot_name)
        passenger.status = AutoPilotTask.DONE
        return False

    # if no market session, sleep until market opens
    if MarketSession.current(passenger.is_otc) is None:
        logger.debug("%s %s market is closed. sleeping 1h", PREFIX, pilot_name)
        time_till_open = time_till_market_open(passenger.is_otc)
        await asyncio.sleep(time_till_open)
        return False

    # if no access token, sleep 1s (repeat until valid access)
    if not etrade.is_session_active():
        logger.debug("%s %s waiting for valid %s session...", PREFIX,
                     pilot_name, etrade.name)
        await asyncio.sleep(1)
        return False

    return True
Exemplo n.º 2
0
def test_time_till_market_open__friday_otc_closed_start_into_weekend__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_AFTERHOURS_START
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open == 235800
Exemplo n.º 3
0
def test_time_till_market_open__sunday_otc_10am__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_CLOSED_START + timedelta(hours=38)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open == 84600
Exemplo n.º 4
0
def test_time_till_market_open__friday_otc_closed_end__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_PREMARKET_END
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open == 0.000001
Exemplo n.º 5
0
def test_time_till_market_open__friday_otc_market_end__zero(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_MARKET_END
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open is 0
Exemplo n.º 6
0
def test_time_till_market_open__friday_closed_start_into_weekend__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_CLOSED_START
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open == 201600
Exemplo n.º 7
0
def test_time_till_market_open__saturday_10am__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_CLOSED_START + timedelta(hours=14)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open == 151200
Exemplo n.º 8
0
def test_time_till_market_open__friday_afterhours_end__zero(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_AFTERHOURS_END
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open is 0
Exemplo n.º 9
0
def test_time_till_market_open__friday_market_start__zero(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_MARKET_START
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open is 0
Exemplo n.º 10
0
def test_time_till_market_open__friday_closed_end__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_CLOSED_END
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open == 0.000001
Exemplo n.º 11
0
def test_time_till_market_open__thursday_closed_start__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_CLOSED_START - timedelta(days=1)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open == 28800
Exemplo n.º 12
0
def test_time_till_market_open__friday_otc_1am__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_PREMARKET_START - \
        timedelta(hours=3)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open == 30600
Exemplo n.º 13
0
def test_time_till_market_open__thursday_otc_closed_start__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_AFTERHOURS_START - \
        timedelta(days=1)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open(otc=True)

    assert time_till_open == 63000
Exemplo n.º 14
0
def test_time_till_market_open__thursday_11pm__seconds(mock_datetime):
    mock_datetime.now.return_value = FRIDAY_PREMARKET_START - \
        timedelta(hours=5)
    mock_datetime.side_effect = create_datetime

    time_till_open = time_till_market_open()

    assert time_till_open == 18000