-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EricWang
committed
Apr 11, 2017
1 parent
8f1a498
commit aadb59e
Showing
10 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2017 Ricequant, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# 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. | ||
|
49 changes: 49 additions & 0 deletions
49
rqalpha/examples/extend_api/rqalpha_mod_extend_api_demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2017 Ricequant, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# 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. | ||
|
||
import os | ||
import pandas as pd | ||
from rqalpha.interface import AbstractMod | ||
|
||
|
||
__config__ = { | ||
"csv_path": None | ||
} | ||
|
||
|
||
def load_mod(): | ||
return ExtendAPIDemoMod() | ||
|
||
|
||
class ExtendAPIDemoMod(AbstractMod): | ||
def __init__(self): | ||
# 注入API 一定要在初始化阶段,否则无法成功注入 | ||
self._csv_path = None | ||
self._inject_api() | ||
|
||
def start_up(self, env, mod_config): | ||
self._csv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), mod_config.csv_path)) | ||
|
||
def tear_down(self, code, exception=None): | ||
pass | ||
|
||
def _inject_api(self): | ||
from rqalpha import export_as_api | ||
|
||
@export_as_api | ||
def get_csv_as_df(): | ||
data = pd.read_csv(self._csv_path) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from rqalpha.api import * | ||
|
||
|
||
def init(context): | ||
IF1706_df = get_csv_as_df() | ||
context.IF1706_df = IF1706_df | ||
|
||
|
||
def before_trading(context): | ||
logger.info(context.IF1706_df) | ||
|
||
|
||
__config__ = { | ||
"base": { | ||
"securities": "future", | ||
"start_date": "2015-01-09", | ||
"end_date": "2015-01-10", | ||
"frequency": "1d", | ||
"matching_type": "current_bar", | ||
"future_starting_cash": 1000000, | ||
"benchmark": None, | ||
}, | ||
"extra": { | ||
"log_level": "verbose", | ||
}, | ||
"mod": { | ||
"extend_api_demo": { | ||
"enabled": True, | ||
"lib": "rqalpha.examples.extend_api.rqalpha_mod_extend_api_demo", | ||
"csv_path": "../IF1706_20161108.csv" | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters