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.1.tar.gz (17.9 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.1-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for inquant-1.3.1.tar.gz
Algorithm Hash digest
SHA256 0796c34f020d00410987770454e77fb5c57b6ad0f4e5475f42bcdb920957de87
MD5 f2766eba407ec6be458c6f15b54d0282
BLAKE2b-256 626341b23ea15c89171daed6a6c6e5ea9eb9edada3ebe389dbffd47c930a118d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for inquant-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92872f1537e058874a6512cee428f6c9aab617481159e88fce2ddfe8c9056a65
MD5 94c5c36fbd914f8fef9493889fa2c76e
BLAKE2b-256 7c35800a40fba92eaa5f0e8ee31d2fbfc1305bf07463144079703c885d1bb004

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