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
from xing.xasession import Session session = Session() session.login('credential.conf') print(session.account()) print(session.heartbeat()) session.logout()
# -*- coding: utf-8 -*- from pandas import DataFrame from xing.xasession import Session import time import pythoncom from xing.logger import LoggerSetting from xing.logger import Logger from xing.xachartdata import Chartdata LoggerSetting.FILE = "test_xachartdata.log" log = Logger(__name__) if __name__ == "__main__": try: session = Session() running = session.login("../config.conf") chart = Chartdata("012510") chart.load({ Chartdata.DAY : [ "20150101" ], Chartdata.WEEK : [ "20070101" ], Chartdata.MONTH : ("20100101", "20161231") }).process({ "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 }) # 테스트를 위한 루프
# -*- coding: utf-8 -*- from pandas import DataFrame from xing.xasession import Session import time import pythoncom from xing.logger import LoggerSetting from xing.logger import Logger from modules.information import Information LoggerSetting.FILE = "xing-plus-app.log" log = Logger(__name__) if __name__ == "__main__": try: info = Information.load("config.conf"); session = Session() session.login(info["server"], info["user"]) running = True # 루프가 필요함. while running: session.heartbeat() # @todo pythoncom.PumpWaitingMessages() time.sleep(3) finally: session.logout() exit()
# -*- coding: utf-8 -*- from pandas import DataFrame from xing.xasession import Session import time import pythoncom from xing.logger import LoggerSetting from xing.logger import Logger from xing.xaquery import Query LoggerSetting.FILE = "test_xaquery.log" log = Logger(__name__) if __name__ == "__main__": try: session = Session() session.login("../config.conf") running = True # 테스트를 위한 루프 while running: session.heartbeat() xadata = Query("t1101").request({ "InBlock" : { "shcode" : "122630" }, }, { "OutBlock" : ("hname","price", "sign", "change", "diff", "volume", "jnilclose", "offerho1", "bidho1", "offerrem1", "bidrem1", "preoffercha1","prebidcha1", "offerho2", "bidho2", "offerrem2", "bidrem2", "preoffercha2","prebidcha2", "offerho3", "bidho3", "offerrem3", "bidrem3", "preoffercha3","prebidcha3", "offerho4", "bidho4", "offerrem4", "bidrem4", "preoffercha4","prebidcha4",
from xing.xasession import Session from xing.query import Query from getpass import getpass userid = input("Id: ") passwd = getpass() session = Session() session.login(id=userid, passwd=passwd) print(session.account()) print(Query("서버시간조회").send()) print(Query("t0167").send()) print(session.heartbeat())