Exemplo n.º 1
0
 def subscribe_real_time(sub_code, sub_cb, param=None):
     rs = bs.login_real_time()
     while BaoStock.retried_num < BaoStock.RETRY_MAX_NUM and rs.error_code != '0':
         sleep(BaoStock.RETRY_DELAY_S)
         rs = bs.login_real_time()
         BaoStock.retried_num += 1
     assert('0' == rs.error_code)
     BaoStock.retried_num = 0
     BaoStock.subscribe_rs = bs.subscribe_by_code(sub_code, 0, sub_cb, param)
     while BaoStock.retried_num < BaoStock.RETRY_MAX_NUM and BaoStock.subscribe_rs.error_code != '0':
         sleep(BaoStock.RETRY_DELAY_S)
         BaoStock.subscribe_rs = bs.subscribe_by_code(sub_code, 0, sub_cb, param)
         BaoStock.retried_num += 1
     assert('0' == BaoStock.subscribe_rs.error_code)
     BaoStock.retried_num = 0
Exemplo n.º 2
0
def test_real_time_stock_price(stockcode):
    login_result = bs.login_real_time(user_id='anonymous', password='******')
    # 订阅
    rs = bs.subscribe_by_code(stockcode, 0, callbackFunc, "", "user_params")
    #     rs = bs.subscribe_by_code("sz.300009", 0, callbackFunc, "", "user_params")
    if rs.error_code != '0':
        print("request real time error", rs.error_msg)
    else:
        # 使主程序不再向下执行。使用time.sleep()等方法也可以
        text = input("press any key to cancel real time \r\n")
        # 取消订阅
        cancel_rs = bs.cancel_subscribe(rs.serial_id)
    # 登出
    login_result = bs.logout_real_time("anonymous")
Exemplo n.º 3
0
def callbackFunc(ResultData):
    pufa_bank = ResultData.data["sh.600000"]
    send_msg("sh.600000 当前价格小于10了")
    if float(pufa_bank[6]) < 10.0:
      send_msg("sh.600000 当前价格小于10了")
    if __name__ == '__main__':  # 登陆
      login_result = bs.login_real_time()
      print('login respond error_code:' + login_result.error_code)
      print('login respond error_msg:' + login_result.error_msg)
    # 订阅
    rs = bs.subscribe_by_code("sh.600000", 0, callbackFunc, "",
                          "user_params")
    if rs.error_code != '0':
       print("request real time error", rs.error_msg)
    else:
         # 使主程序不再向下执行。使用time.sleep()等方法也可以
         text = input("press any key to cancel real time \r\n")
    # 取消订阅
    cancel_rs = bs.cancel_subscribe(rs.serial_id)
    # 登出
    login_result = bs.logout_real_time()
Exemplo n.º 4
0
import baostock as bs


# 每次收到实时行情后,回调此方法
def callbackFunc(ResultData):
    print(ResultData.data)


if __name__ == '__main__':
    # 登陆
    login_result = bs.login_real_time()
    print('login respond error_code:' + login_result.error_code)
    print('login respond  error_msg:' + login_result.error_msg)
    # 订阅
    rs = bs.subscribe_by_code("sh.600000,sz.000001", 0, callbackFunc, "", "user_params")
    if rs.error_code != '0':
        print("request real time error", rs.error_msg)
    else:
        # 使主程序不再向下执行。使用time.sleep()等方法也可以
        text = input("press any key to cancel real time \r\n")
        # 取消订阅
        cancel_rs = bs.cancel_subscribe(rs.serial_id)
    # 登出
    login_result = bs.logout_real_time()