Example #1
0
class Server:
    MAX_RETRY = 5

    def start(self, port=50666):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REP)
        self.socket.bind("tcp://*:" + str(port))
        self.session = Session()
        self.done = False
        while not self.done:
            try:
                self.loop()
            except Exception as e:
                log.critical("There exist unhandled exception!", e.args)
        self.clean()

    def loop(self):
        topic = self.socket.recv()
        if topic == b"ping":
            self.socket.send(b"Hello, World!")
        if topic == b"login":
            args = unpack(self.socket.recv())
            res = self.login(**args)
            self.socket.send(pack(res))
        if topic == b"logout":
            self.logout()
            self.socket.send(b"ok")
        if topic == b"shutdown":
            self.done = True
        if topic == b"query":
            tr, args = unpack(self.socket.recv())
            try:
                res = Query(tr).send(**args)
                self.socket.send(b"ok", zmq.SNDMORE)
                self.socket.send(pack(res))
            except Exception as e:
                log.critical(e.args)
                self.socket.send(b"error", zmq.SNDMORE)
                self.socket.send(pack(e.args))
        else:
            pass

    def clean(self):
        self.logout()
        self.socket.close()
        self.context.destroy()

    def login(self, **kwargs):
        self.session = Session()
        self.session.login(**kwargs)
        return True

    def logout(self):
        self.session.logout()
        self.session = None
Example #2
0
class Server:
    MAX_RETRY = 5

    def start(self, port=50666):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REP)
        self.socket.bind("tcp://*:" + str(port))
        self.session = Session()
        self.done = False
        while not self.done:
            try:
                self.loop()
            except Exception as e:
                log.critical("There exist unhandled exception!", e.args)
        self.clean()

    def loop(self):
        topic = self.socket.recv()
        if topic == b"ping":
            self.socket.send(b"Hello, World!")
        if topic == b"login":
            args = unpack(self.socket.recv())
            res = self.login(**args)
            self.socket.send(pack(res))
        if topic == b"logout":
            self.logout()
            self.socket.send(b"ok")
        if topic == b"shutdown":
            self.done = True
        if topic == b"query":
            tr, args = unpack(self.socket.recv())
            try:
                res = Query(tr).send(**args)
                self.socket.send(b"ok", zmq.SNDMORE)
                self.socket.send(pack(res))
            except Exception as e:
                log.critical(e.args)
                self.socket.send(b"error", zmq.SNDMORE)
                self.socket.send(pack(e.args))
        else:
            pass

    def clean(self):
        self.logout()
        self.socket.close()
        self.context.destroy()

    def login(self, **kwargs):
        self.session = Session()
        self.session.login(**kwargs)
        return True

    def logout(self):
        self.session.logout()
        self.session = None
Example #3
0
from xing.xasession import Session

session = Session()
session.login('credential.conf')

print(session.account())
print(session.heartbeat())

session.logout()
            "RSI" : 14,  # period
        })

        # 테스트를 위한 루프
        while running:
            session.heartbeat()
            chart.load({
                5 : ["20151202"]
            }).process(5, {
                "SMA" : [ 5, 10, 20, 60],   # 이동평균선
                "BBANDS" : [20, 2], #볼랜져 밴드 period, 승수
                "ATR" : 14, #ATR 지표 period
                "STOCH" : [ 5, 3, 0],   #스토케스틱 K period, D period, D type
                "MACD" : [12, 26, 9],  # short, long, signal
                "RSI" : 14,  # period
            })
            _5df = chart.get(5)
            _dayDf = chart.get(Chartdata.DAY)
            _weekDf = chart.get(Chartdata.WEEK)
            _monthDf = chart.get(Chartdata.MONTH)
            print(_5df)
            print("5분 데이터 : %s ~ %s" % (_5df.iloc[0]["date"], _5df.iloc[len(_5df)-1]["date"]) )
            print("일 데이터 : %s ~ %s" % (_dayDf.iloc[0]["date"], _dayDf.iloc[len(_dayDf)-1]["date"]) )
            print("주 데이터 : %s ~ %s" % (_weekDf.iloc[0]["date"], _weekDf.iloc[len(_weekDf)-1]["date"]) )
            print("월 데이터 : %s ~ %s" % (_monthDf.iloc[0]["date"], _monthDf.iloc[len(_monthDf)-1]["date"]) )

            pythoncom.PumpWaitingMessages()
            time.sleep(1)
    finally:
        session.logout()
        exit()