コード例 #1
0
options_codes = sys.argv[1].split(',')

# get snapshots and caculate APY
stock_price = 0
sort_options = []
page_size = 300  # futu api level2 limit
now = datetime.now() + TIMEZONE_OFFSET
today = datetime(now.year, now.month, now.day)
page_options_codes = []

while len(options_codes) > 0:
    page_options_codes.append(options_codes.pop(0))
    if len(page_options_codes) == page_size or len(
            options_codes) == 0:  # full pagination or last page
        while True:  # insure this pagination request processing successfully
            ret_code, snapshots = quote_ctx.get_market_snapshot(
                page_options_codes)
            if ret_code != RET_OK:
                print("get_market_snapshot, ret_code: %s, error: %s" %
                      (ret_code, snapshots))
                time.sleep(
                    1.5
                )  # error before maybe because of futu api level2 limit, 20 snapshots requests per 30s
                continue

            page_options_codes.clear()
            for i, snapshot in snapshots.iterrows(
            ):  # here each row is a tuple
                if snapshot["option_valid"] == False:
                    stock_price = snapshot["last_price"]
                    continue
                price = snapshot["bid_price"]
コード例 #2
0
ファイル: basic_usage.py プロジェクト: zjxrx917/stock
def deep_print(obj):
    sep = '=' * 20 + '\n'
    print(sep)
    print(obj)
    print(sep)
    for item in dir(obj):
        if not item.startswith('__'):
            print(item, sep='\t')
    if isinstance(obj, Iterable):
        for item in obj:
            if isinstance(item, list):
                for _item in item:
                    print(_item)
            elif isinstance(item, dict):
                for k, v in item.items():
                    print(k, ' : ', v)
            else:
                print(item)


quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

data = quote_ctx.get_market_snapshot('HK.01024')
deep_print(data)
status = quote_ctx.get_global_state()
deep_print(status)

quote_ctx.close()
print('program end')
コード例 #3
0
ファイル: ftnn.py プロジェクト: chriswck/Indicators
from futu import OpenQuoteContext, OpenHKTradeContext, TrdSide, TrdEnv

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)  # 创建行情对象
print(quote_ctx.get_market_snapshot('HK.00700'))  # 获取港股 HK.00700 的快照数据
quote_ctx.close()  # 关闭对象,防止连接条数用尽

trd_ctx = OpenHKTradeContext(host='127.0.0.1', port=11111)  # 创建交易对象
print(
    trd_ctx.place_order(price=500.0,
                        qty=100,
                        code="HK.00700",
                        trd_side=TrdSide.BUY,
                        trd_env=TrdEnv.SIMULATE))
# 模拟交易,下单(如果是真实环境交易,在此之前需要先解锁交易密码)

trd_ctx.close()  # 关闭对象,防止连接条数用尽