Пример #1
0
from trading_calendars import get_calendar

from se import config, AccountRepo, BeanContainer
from se.domain2.engine.engine import Engine, Scope
from se.infras.ib import IBAccount
from strategies.strategy import TestStrategy3

engine = Engine()
scope = Scope(["GSX_STK_USD_SMART"], trading_calendar=get_calendar("NYSE"))
strategy = TestStrategy3(scope)

account_name = "ib_real2"
repo: AccountRepo = BeanContainer.getBean(AccountRepo)
acc = repo.find_one(account_name)
if not acc:
    acc = IBAccount(account_name, 10000)

acc.with_order_callback(strategy).with_client(
    config.get('ib_account', 'host'), config.getint('ib_account', 'port'),
    config.getint('ib_account', 'client_id'))
acc.start_save_thread()
acc.start_sync_order_executions_thread()

engine.run(strategy, acc)
Пример #2
0
from pandas._libs.tslibs.timestamps import Timestamp

os.environ[
    'config.dir'] = "/Users/zhang/PycharmProjects/strategy_engine_v2/interface"
# 如果没有日志目录的话,则创建
if not os.path.exists("log"):
    os.makedirs("log")

from se.domain2.time_series.time_series import TimeSeries, TimeSeriesRepo, TimeSeriesSubscriber, TSData
from se.domain2.engine.engine import DataPortal
from se import config, BeanContainer
from ibapi.order import Order as IBOrder
from se.infras.ib import IBAccount, IBClient, Request

client: IBClient = IBClient.find_client(config.get('ib_data', 'host'),
                                        config.getint('ib_data', 'port'),
                                        config.getint('ib_data', 'client_id'))
if not client:
    client: IBClient = IBClient(config.get('ib_data', 'host'),
                                config.getint('ib_data', 'port'),
                                config.getint('ib_data', 'client_id'))
contract: Contract = Contract()
contract.symbol = 'CL'
contract.secType = 'FUT'
contract.exchange = "NYMEX"
# contract.multiplier = 5000
contract.lastTradeDateOrContractMonth = "202104"
# contract: Contract = Contract()
# contract.symbol = '700'
# contract.secType = 'STK'
# contract.exchange = "SEHK"
Пример #3
0
from trading_calendars import get_calendar

from se import config, BeanContainer, AccountRepo
from se.domain2.engine.engine import Engine, Scope
from se.infras.ib import IBAccount
from strategies.spce import SPCEStrategy

engine = Engine()
scope = Scope(["SPCE_STK_USD_SMART"], trading_calendar=get_calendar("NYSE"))
strategy = SPCEStrategy(scope)

account_name = "ib_real1"
repo: AccountRepo = BeanContainer.getBean(AccountRepo)
acc = repo.find_one(account_name)
if not acc:
    acc = IBAccount(account_name, 10000)

acc.with_order_callback(strategy).with_client(config.get('ib_account', 'host'), config.getint('ib_account', 'port'),
                                              config.getint('ib_account', 'client_id'))
acc.valid_scope(scope)
acc.start_save_thread()
acc.start_sync_order_executions_thread()

engine.run(strategy, acc)