ranaroussi / qtpylib

QTPyLib, Pythonic Algorithmic Trading
http://qtpylib.io
Apache License 2.0
2.12k stars 508 forks source link

Could not get FUT data. #7

Closed homeyi closed 7 years ago

homeyi commented 7 years ago

Ran, Thank for you QTPyLib,I have tested severa weeks,It is very execllent!!!

I have a problem about FUT can not get quote and tick,

Because i use my live account to try get XINA50 FUT(i have subscribed data) quote and tick ,

Like this:(instruments = [("XINA50", "FUT", "SGX", "USD", 201610, 0.0, "")],) But can not get it.

I do not know how to right do it,Can you give me some advice,

Thanks and kind regards,

ranaroussi commented 7 years ago

Hi,

I'm not familiar with this contract, but it appears that you're doing everything right...

I tried getting contract specifications using Python and got it - which means the Tuple is correct.

However since I'm not subscribed to SGX, all I get are zeros for bid/ask/last. When I use a fake contract I don't even get that - so this also indicates to me that the tuple is correct.

Can see charts for this instrument directly on TWS?

dxrit commented 7 years ago

Hi Ran I have tried with ES, but I am not getting any data as well.

But checked with STK and CASH, which works fine. '------------------------------------------------------------------------------------------- My FUT test tuple is ("ES", "FUT", "GLOBEX", "USD", 201611, 0.0,"") and I can see entry in symbols.csv as: symbol,sec_type,exchange,currency,expiry,strike,opt_type ES,FUT,GLOBEX,USD,201611.0,0.0, '------------------------------------------------------------------------------------------- when I check the log msg, tws returns error code 200, which is "No security definition has been found for the request".

I am not sure, but is it to do with expiry field (201611.0 instead of 201611)

Thanks and kind Regards Sam

homeyi commented 7 years ago

Hi gitsamsit , ES must be subscribed by TWS,edemo/demouser can not get ES data.

ranaroussi commented 7 years ago

ES does not have November expiration. Please try using

("ES", "FUT", "GLOBEX", "USD", 201612, 0.0,"")

dxrit commented 7 years ago

Hi Ran, homeyi

Thanks for the response, tried with 201612 still getting the same msg. @homeyi I am using sim account for test not edemo, I guess it should work with sim account.

log msg: {"TimeStamp": "20161018 12:27:08 PM", "level": "INFO", "msg": "Connection established..."}, {"TimeStamp": "20161018 12:27:14 PM", "level": "INFO", "msg": "Contract Added [ESZ2016]"}, {"TimeStamp": "20161018 12:27:14 PM", "level": "INFO", "msg": "ibCallBack caller handleError, msg 200, kwargs {}"},

ranaroussi commented 7 years ago

I'm not sure how 201611.0 was added to your symbols.csv. Can you remove this line and restart blotter.py?

dxrit commented 7 years ago

Hi Ran removed .csv and restarted blotter. now symbols.csv looks as symbol,sec_type,exchange,currency,expiry,strike,opt_type ES,FUT,GLOBEX,USD,201612.0,0.0, and still getting same msg.

ranaroussi commented 7 years ago

Please post your complete code so I can run it locally and figure out what's happening.

Thanks!

dxrit commented 7 years ago

sure I will post it in few mints. meanwhile FYI I tried placing ES order using ezibpy, which works fine.

dxrit commented 7 years ago

Here is blotter and strategy code. Please letme know should I send the complete folder.

Thanks

blotter.py

#!/usr/bin/env python
import logging
logging.basicConfig(filename='log-ex-bl.json', level=logging.DEBUG,
    format='{"TimeStamp": "%(asctime)s", "level": "%(levelname)s", "msg": "%(message)s"},', datefmt='%Y%m%d %I:%M:%S %p')

from qtpylib.blotter import Blotter

class MainBlotter(Blotter):
    pass # we just need the name

# ===========================================
if __name__ == "__main__":
    blotter = MainBlotter( )
    blotter.run()

strategy.py

from qtpylib.algo import Algo

class StrBasicES(Algo):
    def on_bar(self, instrument):
        if instrument.positions['position'] == 0:
            instrument.buy(1)
        else:
            instrument.exit()

if __name__ == "__main__":
    strategy = StrBasicES(
        instruments = [ ("ES", "FUT", "GLOBEX", "USD", 201612, 0.0,"") ],
        resolution  = "1T"
    )
    strategy.run()
ranaroussi commented 7 years ago

Works great here!

I did notice the 201612.0 but it works just as well.. I did pushed version 1.4.91 that forces the expiry to be saved as int instead of float but that shouldn't prevent it from working in any case.

As for the 200 error. I see it once on every established connection - no matter which library I use (also when using IbPy only) - so I guess this is something we can feel comfortable ignoring :)

homeyi commented 7 years ago

Ran, i can see charts for this instrument. i found not some problem,i do not know how can i check it.

the contract info like this:


FTSE/Xinhua China A50
Security Type
  
FUT

Underlying
  
XINA50 IND

Contract Month
  
OCT16

Expiration Date
  
OCT 28 '16

Last Trading Date
  
OCT 28 '16 16:35 HKT

Currency
  
USD

Multiplier
  
1

Exchange
  
SGX

Trading Class
  
CN

Symbol
  
CNV16

Product Type
  
Equity Index

Settlement Method
  
Cash

 Trading Hours: October 18, 2016  Calendar 

Total Available Hours
  
17:15 HKT - 02:00 HKT (17:15 CST - 02:00 CST)
  
09:00 HKT - 16:35 HKT (09:00 CST - 16:35 CST)
  

Current Margin Requirements
Intraday Initial
  
1446.25

Intraday Maintenance
  
1157.00

Overnight Initial
  
1446.25

Overnight Maintenance
  
1157.00
dxrit commented 7 years ago

Ran

It works great here too!

Got new version 1.4.91 , and tested. Also yep now its int instead of float.

Thanks for the help :)

dxrit commented 7 years ago

@homeyi try using new version it may work

homeyi commented 7 years ago

@gitsamsit ok i try again

homeyi commented 7 years ago

@ranaroussi
yes! my here works great too! thanks for your fixed

ranaroussi commented 7 years ago

Glad to hear it!

Marking this as closed :)