Ejemplo n.º 1
0
def SimulateTrade(Kind,AccountInfo,ActFlag,ActualAmount,TaxRate,LivePX,TodayMoney,TodayPos):
    if ActFlag == 1:    #开
        data1 = w.tlogon(BrokerID=AccountInfo[0], DepartmentID=0, LogonAccount=AccountInfo[1], Password=AccountInfo[2], AccountType='shf')  #登录模拟账户
        data21 = w.torder(SecurityCode=Kind, TradeSide='Buy', OrderPrice=LivePX, OrderVolume=ActualAmount, MarketType='SHF')  #模拟开仓
        TodayPos += ActualAmount
        TodayMoney -= LivePX*ActualAmount*(1+TaxRate)
    elif ActFlag == -1:     #平
        data1 = w.tlogon(BrokerID=AccountInfo[0], DepartmentID=0, LogonAccount=AccountInfo[1], Password=AccountInfo[2], AccountType='shf')  #登录模拟账户
        data21 = w.torder(SecurityCode=Kind, TradeSide='Sell', OrderPrice=LivePX, OrderVolume=ActualAmount,MarketType='SHF')  #模拟平仓
        TodayPos -= ActualAmount
        TodayMoney += LivePX*ActualAmount*(1-TaxRate)
    #print(TodayMoney, TodayPos)
    return TodayMoney, TodayPos
Ejemplo n.º 2
0
def ForceSell(Kind, AccountInfo,LivePX,TodayMoney, TodayPos,TaxRate):
    data1 = w.tlogon(BrokerID=AccountInfo[0], DepartmentID=0, LogonAccount=AccountInfo[1], Password=AccountInfo[2], AccountType='shf')  # 登录模拟账户
    data21 = w.torder(SecurityCode=Kind, TradeSide='Sell', OrderPrice=LivePX, OrderVolume=TodayPos, MarketType='SHF')  # 模拟平仓
    TodayMoney += LivePX*TodayPos*(1-TaxRate)
    TodayPos = 0
    LastAct = -2
    OriginMAFlag = [0,0,0]
    return TodayMoney, TodayPos, LivePX, LastAct, OriginMAFlag
Ejemplo n.º 3
0
 def tradelogon(self):
     #仅登陆期权帐户
     if self._tradeaccid[0]>0:
         print('已登陆')
         return
         
     acc=[g.config_wind_account+'03']
     acctype=['sho']
     logon=w.tlogon('0000',0,acc,g.config_wind_password, acctype)
     
     if logon.ErrorCode <0:
         self._tradeaccid=0            
         print('登陆失败:%s' %(logon.Data))
     else:
         self._tradeaccid=logon.Data[0]
         print('期权交易帐户登陆成功')
Ejemplo n.º 4
0
import MySQLdb
from WindPy import w
from datetime import *
from Execution import *

LogonID = w.tlogon("00000010","","M:1881053498701","******","SHSZ")

try:
    WhiteList=[]
    CurrentPosition=[]
    Bamboo_db = MySQLdb.connect(host='localhost',user='******',passwd='root',db='Bamboo',port=3306)
    cur = Bamboo_db.cursor()

    #Get record in WhiteList table and store them into array WhiteList
    WhiteList_count = cur.execute('select * from WhiteList')
    print 'there are %d raws record in WhiteList' % count

    WhiteList_results = cur.fetchall()
    for r in White_results:
        WhiteList.append(r[0])

    print WhiteList

    #Get record in CurrentPosition table and store them into array CurrentPosition
    CurrentPosition_count = cur.execute('select * from CurrentPosition')
    print 'there are %d raws record in Position' % count

    CurrentPosition_results = cur.fetchall()
    for r in CurrentPosition_results:
        CurrentPosition.append(r[0])
    print CurrentPosition
Ejemplo n.º 5
0
daima = '000413'
nian = '2015'
yue = ''

print("登入万得\n")

from WindPy import w

#from datetime import *

w.start()

print("已经启动")
print("登入期货账户\n")
w.tlogon("20420401", "0", "25300042", "121522", "CFE")

mo = w.tquery("Capital").Data[1][0]
print("现有资金:", "%.2f" % mo)

po = w.tquery("Position").Data
print("现有持仓:", "\n", po[0], "\n", po[1], "\n", po[2], "\n", po[10], "\n",
      po[11], "\n", po[12], "\n", po[13])
'''股品  主要看成长
'''

rd = w.wsd("603883.SH",
           "roa2,stmnote_others_4504,researchanddevelopmentexpenses",
           "2012-01-01", "2014-12-31", "rptType=1;Period=Y;Fill=Previous")
rd.Data[0]

v = w.wsi("600010.SH", "amt", "2015-04-24 09:00:00", "2015-04-26 17:08:25", "")
Ejemplo n.º 6
0
                    print'it is trading spread order between %s and %s'%(self.tradingOrder[i][0],self.tradingOrder[i][1])
                    instrument_id=self.tradingOrder[i][0]
                    direction='buy'
                    limitPrice=w.wsq(instrument_id,'rt_last').Data[0]
                    volume=1
                    logonid=2
                    w.torder(instrument_id,direction,limitPrice,volume,logonid=logonid)
                    
                    #定义卖单下单参数,并下单
                  
                    instrument_id=self.tradingOrder[i][1]
                    direction='short'
                    limitPrice=w.wsq(instrument_id,'rt_last').Data[0]
                    volume=self.tradingOrder[i][2]
                    logonid=2
                    w.torder(instrument_id,direction,limitPrice,volume,logonid=logonid)        

     
#定义交易对象,此对象来自于计算机器结果
tradingOrder=[['RU1401.SHF', 'FG401.CZC', 36.011767364126612, -28373.745064529503, -33208.077687938567], ['ZN1401.SHF', 'TA401.CZC', 1.2126731163504074, 5500.6030064563192, 4893.9256643498748], ['RU1401.SHF', 'J1401.DCE', 17.642695764706176, -6310.4765649161745, -8590.0412593592864], ['RU1401.SHF', 'TA401.CZC', 7.6723619297322729, -38316.284059386315, -42628.309323957808], ['CU1401.SHF', 'RU1401.SHF', 1.0815425178390803, 31978.191774908541, 29644.633609589815], ['AG1312.SHF', 'AU1312.SHF', 30.191027322441442, -3600.9750756256853, -3970.7648976048631]]

TSNames=list(set([str(x[0]) for x in tradingOrder]+[str(x[1]) for x in tradingOrder]))
#登陆下单
TD=w.tlogon('0000',0,['W675324301','W675324302'],'000000',['sh','cfe'])
print TD
#启动OnTickSpread交易策略
#print w.wsq("000001.sz","rt_last")
data=w.wsq("000001.sz","rt_last",func=Trading(TD,tradingOrder).OnTickSpread)
print data
while True:
    time.sleep(1)
Ejemplo n.º 7
0
                ],
                [
                    'RU1401.SHF', 'J1401.DCE', 17.642695764706176,
                    -6310.4765649161745, -8590.0412593592864
                ],
                [
                    'RU1401.SHF', 'TA401.CZC', 7.6723619297322729,
                    -38316.284059386315, -42628.309323957808
                ],
                [
                    'CU1401.SHF', 'RU1401.SHF', 1.0815425178390803,
                    31978.191774908541, 29644.633609589815
                ],
                [
                    'AG1312.SHF', 'AU1312.SHF', 30.191027322441442,
                    -3600.9750756256853, -3970.7648976048631
                ]]

TSNames = list(
    set([str(x[0]) for x in tradingOrder] + [str(x[1]) for x in tradingOrder]))
#登陆下单
TD = w.tlogon('0000', 0, ['W675324301', 'W675324302'], '000000', ['sh', 'cfe'])
print TD
#启动OnTickSpread交易策略
#print w.wsq("000001.sz","rt_last")
data = w.wsq("000001.sz",
             "rt_last",
             func=Trading(TD, tradingOrder).OnTickSpread)
print data
while True:
    time.sleep(1)