Esempio n. 1
0
def merge_trading_period(trading_period):
    result = []
    for time_range in sorted(set(trading_period)):
        if result and result[-1].end >= time_range.start:
            result[-1] = TimeRange(start=result[-1].start, end=max(result[-1].end, time_range.end))
        else:
            result.append(time_range)
    return result
Esempio n. 2
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import time

from rqalpha.utils.datetime_func import TimeRange

TRADING_PERIOD_DICT = dict()

STOCK_TRADING_PERIOD = [
    TimeRange(start=time(9, 31), end=time(11, 30)),
    TimeRange(start=time(13, 1), end=time(15, 0)),
]

# | 商品期货 WR, FU, BB, FB, JD, WH, PM, RI, SF, SM, RS, JR, LR, AP, CJ, UR
# | 09:01~10:15, 10:31~11:30, 13:31~15:00 |
time_period1 = [
    TimeRange(start=time(9, 1), end=time(10, 15)),
    TimeRange(start=time(10, 31), end=time(11, 30)),
    TimeRange(start=time(13, 31), end=time(15, 0)),
]
TRADING_PERIOD_DICT.update({
    underlying_symbol: time_period1
    for underlying_symbol in [
        "WR", "FU", "BB", "FB", "JD", "WH", "PM", "RI", "SF", "SM", "RS", "JR",
        "LR", "AP", "SP", "CJ", "UR"
Esempio n. 3
0
    return Environment.get_instance().data_proxy.is_night_trading(universe)


def merge_trading_period(trading_period):
    result = []
    for time_range in sorted(set(trading_period)):
        if result and result[-1].end >= time_range.start:
            result[-1] = TimeRange(start=result[-1].start,
                                   end=max(result[-1].end, time_range.end))
        else:
            result.append(time_range)
    return result


STOCK_TRADING_PERIOD = [
    TimeRange(start=time(9, 31), end=time(11, 30)),
    TimeRange(start=time(13, 1), end=time(15, 0)),
]


def get_trading_period(universe, accounts):
    # for compatible
    from rqalpha.environment import Environment
    trading_period = STOCK_TRADING_PERIOD if DEFAULT_ACCOUNT_TYPE.STOCK.name in accounts else []
    return Environment.get_instance().data_proxy.get_trading_period(
        universe, trading_period)


def is_trading(dt, trading_period):
    t = dt.time()
    for time_range in trading_period: