Skip to main content

inquant future quant api

Project description

-- coding: utf-8 --

from inquant import *

class MyStrategy(StrategyTemplate): """我的策略"""

def __init__(self,strategyID,logPath):
    """构造函数"""
    super(MyStrategy,self).__init__(strategyID,logPath)
    self.isfirst = 0

def OnTick(self, data):
    """Tick数据处理 注data参数一次只有一条tick数据"""
    self.WriteInfo('tick : {0} {1} {2}'.format(data.Symbol,data.LocalTime,data.Exchange))
    pass

def OnBar(self, data):
    """Bar数据处理 注data参数一次只有一条bar数据"""
    self.WriteInfo('bar : {0} {1} {2}'.format(data.Symbol,data.LocalTime,data.Exchange))

    resp10 = strategy.GetLastBar(data.Symbol,data.Exchange,data.BarType,5)

    if self.isfirst == 0:
        self.isfirst = 1
        resp4 = self.SendOrder(data.Symbol,data.Exchange,OrderSide.Sell,data.LastPx,1,OrderType.LMT,Offset.Close)
    pass

def OnOrderChanged(self,order):
    """成交回报处理"""
    self.WriteInfo('OrderChanged : {0} {1} {2}'.format(order.Symbol,order.Price,order.Exchange))
    pass

def TaskCallback(self):
    print(datetime.now().time())

if name == 'main': #新建策略 strategy = MyStrategy('2-xk1211231243242314123534523453','/home/admin/logs/测试策略/')

strategy.SetMarketStatus(1)

ret = strategy.GetHisBar("rb1905",Exchange.SHFE,60 * 60,1000,20181015150000)

#创建定时任务
strategy.CreateScheduler(strategy.TaskCallback,[90000,161005])

contracts = strategy.GetFutContracts('rb',Exchange.SHFE,-1)
contracts = strategy.GetFutContracts('rb',Exchange.SHFE,0)
contracts = strategy.GetFutContracts('rb',Exchange.SHFE,1)
contracts = strategy.GetFutContracts('rb',Exchange.SHFE,2)
contracts = strategy.GetFutContracts('rb',Exchange.SHFE,3)

a1 = strategy.Subscribe(["rbM.SHFE.Tick.0", "rbM.SHFE.Bar.300"])

strategy.WriteInfo(u"开始启动策略...")
resp = strategy.Start()
if not resp:
    strategy.WriteError(u"策略启动失败!!")
    input(u"按任意键退出")
    sys.exit()
strategy.WriteInfo(u"策略启动成功")

resp4 = strategy.SendOrder('rb1905',Exchange.SHFE,OrderSide.Buy,0,1,OrderType.MKT,Offset.Open)
resp5 = strategy.CancelOrder('7ba0ab1c8319442299c835269f600f3f')

resp1 = strategy.GetAssetInfo()
resp2 = strategy.GetOrders()
resp3 = strategy.GetPositions()

resp6 = strategy.GetOrder('7ba0ab1c8319442299c835269f600f3f')
resp7 = strategy.GetOpenOrders()
resp8 = strategy.GetContract('rb1905',Exchange.SHFE)
resp9 = strategy.GetLastTick('rb1905',Exchange.SHFE,2)
resp10 = strategy.GetLastBar('rb1905',Exchange.SHFE,300,5)

input(u"策略执行中,按任意键退出...")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inquant-1.3.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inquant-1.3.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file inquant-1.3.0.tar.gz.

File metadata

  • Download URL: inquant-1.3.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for inquant-1.3.0.tar.gz
Algorithm Hash digest
SHA256 b3470a4f48efff6fc0b9048d6b9efeb9fb933ee10f05168434a2bfb81cdcf2a4
MD5 e05c7c63b5d62b43dcc8ce53b7aa0198
BLAKE2b-256 1ed66994613f3a71e710d0bc93b949ef520c47caaf0ca10e5676d22fae390972

See more details on using hashes here.

File details

Details for the file inquant-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: inquant-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for inquant-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4c478c69abacf20a09bb45a9768a773bcb500b493a11bf714d67e3b0e32d25e
MD5 e904c9d94a29e0e36c607e0933f6d841
BLAKE2b-256 b4e12e7afb7bcc1852d6015d566806c9d5175539d1bbb4b5158b8f4120cc2bbb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page