from gmsdk.api import md


def on_tick(tick):
    print('tick: ', tick.sec_id, ' ', tick.last_price, ' ', tick.utc_time)


def on_bar(bar):
    print('bar: ', bar.symbol, ' ', bar.open, ' ', bar.bar_time)


md.ev_tick += on_tick
md.ev_bar += on_bar
ret = md.init(username='******',
              password='******',
              mode=4,
              subscribe_symbols='CFFEX.IF1512.tick',
              start_time='2015-05-27 00:00:00',
              end_time='2015-05-27 09:30:00')

print('init result: ', ret)
md.run()
示例#2
0
import time
from gmsdk.api import md


def on_tick(tick):
    print('%s %s %s %s' % (time.time(), tick.sec_id, tick.last_price, tick.utc_time))


def on_bar(bar):
    print('%s:%s %s:%s: %s %s %s' % (time.time(), bar.sec_id, bar.bar_type, bar.open, bar.high, bar.low, bar.close))


def on_error(code, message):
    print(code, message)


md.ev_tick += on_tick
md.ev_bar += on_bar
md.ev_error += on_error

ret = md.init(
    username='******',
    password='******',
    mode=3,
    subscribe_symbols='CFFEX.IF1512.tick,CFFEX.IC1512.tick,CFFEX.IH1512.tick,CFFEX.TF1512.tick',
)

print('init result: ', ret)
md.run()
示例#3
0
from gmsdk.api import md


def on_tick(tick):
    print('tick: %s %s %s' % (tick.sec_id, tick.last_price, tick.strtime))


def on_bar(bar):
    print('bar: %s %s %s' % (bar.sec_id, bar.open, bar.strtime))


md.ev_tick += on_tick
md.ev_bar += on_bar
ret = md.init(username='******',
              password='******',
              mode=4,
              subscribe_symbols='SZSE.000001.bar.daily',
              start_time='2015-05-27 00:00:00',
              end_time='2015-06-27 09:30:00')

print('init result: ', ret)
md.run()
示例#4
0
import arrow

def to_local(utc):
  return arrow.get(utc).to('local')


def on_tick(tick):
    print('%s %s %s %s' % (to_local(time.time()), tick.strtime, tick.sec_id, tick.last_price))

def on_bar(bar):
    print('%s %s %s %s %s %s %s %s' % (to_local(time.time()), bar.strtime, bar.sec_id, bar.bar_type, bar.open, bar.high, bar.low, bar.close))

def on_error(code, message):
    print (code, message)


md.ev_tick += on_tick
md.ev_bar += on_bar
md.ev_error += on_error


ret = md.init(
              username='******',
              password='******',
              mode=2,
              subscribe_symbols="SZSE.000001.tick,SHSE.600000.tick",
              )

print('init result: ', ret)
md.run()
示例#5
0

def on_tick(tick):
    print('%s %s %s %s' %
          (to_local(time.time()), tick.strtime, tick.sec_id, tick.last_price))


def on_bar(bar):
    print('%s %s %s %s %s %s %s %s' %
          (to_local(time.time()), bar.strtime, bar.sec_id, bar.bar_type,
           bar.open, bar.high, bar.low, bar.close))


def on_error(code, message):
    print(code, message)


md.ev_tick += on_tick
md.ev_bar += on_bar
md.ev_error += on_error

ret = md.init(
    username='******',
    password='******',
    mode=2,
    subscribe_symbols="SZSE.000001.tick,SHSE.600000.tick",
)

print('init result: ', ret)
md.run()
示例#6
0

def on_tick(tick):
    print('%s %s %s %s' %
          (to_local(time.time()), tick.strtime, tick.sec_id, tick.last_price))


def on_bar(bar):
    print('%s %s %s %s %s %s %s %s' %
          (to_local(time.time()), bar.strtime, bar.sec_id, bar.bar_type,
           bar.open, bar.high, bar.low, bar.close))


def on_error(code, message):
    print(code, message)


md.ev_tick += on_tick
md.ev_bar += on_bar
md.ev_error += on_error

ret = md.init(
    username='******',
    password='******',
    mode=2,
    subscribe_symbols="SZSE.000001.tick,SHSE.600000.tick",
)

print('init result: ', ret)
md.run()
示例#7
0
            imbalance += volume* (vwap - lastMid)/tickSize
            imbalance1 += volume * sign(vwap - lastMid)
            #imbalance2 += volume * (vwap - lastWMid) / tickSize
            imbalance2 += volume * sign(vwap - lastWMid)
            if vwap>lastAsk[0]:
                if volume>lastAskQty[0]:
                    imbalanceAsk += volume - lastAskQty[0]
                else:
                    cancelAsk += lastAskQty[0]-volume
            if vwap<lastBid[0]:
                if volume > lastBidQty[0]:
                    imbalanceBid += volume - lastBidQty[0]
                else:
                    cancelBid += lastBidQty[0] - volume
            print('tick: %s,%s,%s,%s\n' % (tick.strtime,volume,lastMid,vwap))

md.ev_tick += on_tick
md.ev_bar += on_bar

ret = md.init(username='******',
              password='******',
              mode=4,
              subscribe_symbols=symbol+'.tick,'+symbol+'.bar.60',
              start_time='2016-03-01 09:30:00',
              end_time='2016-03-03 14:59:00')


print('init result: ', ret)
md.run()

csvFile.close()