Пример #1
0
    def subscript_order(self, symbol, on_sub):
        on_sub_event = WebSocketEvent(False)

        def on_sub_event_trigger(msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            json_checker = JsonChecker()
            json_checker.check_equal("action", "sub", root_obj)
            json_checker.value_include("ch", "orders", root_obj)
            return json_checker.complete()

        on_sub_event.set_trigger(on_sub_event_trigger)

        def on_sub_event_event(connection, msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            code_var = Code()
            code_var.code = root_obj.get_int("code")
            on_sub(code_var)

        on_sub_event.set_event(on_sub_event_event)
        self.__connection.register_event(on_sub_event)
        json = JsonWrapper()
        json.add_json_string("action", "sub")
        json.add_json_string("ch",
                             CEIUtils.string_replace("orders#{0}", symbol))
        self.__connection.send(json.to_json_string())
Пример #2
0
 def request_echo(self, name, price, number, status, on_echo):
     on_echo_event = WebSocketEvent(False)
 
     def on_echo_event_trigger(msg):
         root_obj = JsonWrapper.parse_from_string(msg.get_string())
         json_checker = JsonChecker()
         json_checker.check_equal("op", "echo", root_obj)
         obj = root_obj.get_object_or_none("param")
         json_checker.check_equal("Name", name, obj)
         return json_checker.complete()
     on_echo_event.set_trigger(on_echo_event_trigger)
 
     def on_echo_event_event(connection, msg):
         root_obj = JsonWrapper.parse_from_string(msg.get_string())
         simple_info_var = SimpleInfo()
         obj = root_obj.get_object("param")
         simple_info_var.name = obj.get_string("Name")
         simple_info_var.number = obj.get_int("Number")
         simple_info_var.price = obj.get_decimal("Price")
         simple_info_var.status = obj.get_bool("Status")
         on_echo(simple_info_var)
     on_echo_event.set_event(on_echo_event_event)
     self.__connection.register_event(on_echo_event)
     json_result = JsonWrapper()
     json_result.add_json_string("op", "echo")
     obj = JsonWrapper()
     obj.add_json_string("Name", name)
     obj.add_json_number("Price", price)
     obj.add_json_number("Number", number)
     obj.add_json_boolean("Status", status)
     json_result.add_json_object("param", obj)
     self.__connection.send(json_result.to_json_string())
Пример #3
0
 def on_ping_event_event(connection, msg):
     root_obj = JsonWrapper.parse_from_string(msg.get_string())
     ts = Timestamp()
     obj = root_obj.get_object("data")
     ts.timestamp = obj.get_int("ts")
     json_result = JsonWrapper()
     json_result.add_json_string("op", "pong")
     json_result.add_json_number("ts", ts.timestamp)
     connection.send(json_result.to_json_string())
Пример #4
0
 def on_connect_event(connection):
     login = JsonWrapper()
     login.add_json_string("op", "login")
     obj = JsonWrapper()
     obj.add_json_string("Name", name)
     login.add_json_object("param", obj)
     obj0 = JsonWrapper()
     obj0.add_json_number("[]", float("1"))
     obj0.add_json_number("[]", float("2"))
     login.add_json_object("array", obj0)
     connection.send(login.to_json_string())
     on_connect(connection)
Пример #5
0
 def authentication(self, name, number):
     request = RestfulRequest(self.__option)
     post_msg = JsonWrapper()
     post_msg.add_json_number("Number", number)
     request.set_target("/restful/post/authentication")
     request.set_method(RestfulRequest.Method.POST)
     request.add_query_string("Name", name)
     request.set_post_body(post_msg.to_json_string())
     Procedures.restful_auth(request, self.__option)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     simple_info_var = SimpleInfo()
     simple_info_var.name = root_obj.get_string("Name")
     simple_info_var.number = root_obj.get_int("Number")
     simple_info_var.price = root_obj.get_decimal("Price")
     return simple_info_var
Пример #6
0
    def request_depth(self, symbol, type_u, on_depth):
        on_depth_event = WebSocketEvent(True)

        def on_depth_event_trigger(msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            json_checker = JsonChecker()
            json_checker.check_equal(
                "ch",
                CEIUtils.string_replace("market.{0}.depth.{1}", symbol,
                                        type_u), root_obj)
            return json_checker.complete()

        on_depth_event.set_trigger(on_depth_event_trigger)

        def on_depth_event_event(connection, msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            depth_var = Depth()
            depth_var.ch = root_obj.get_string("ch")
            obj = root_obj.get_object("tick")
            obj0 = obj.get_array("bids")
            for item in obj0.array():
                quote_var = Quote()
                quote_var.price = item.get_decimal("[0]")
                quote_var.amount = item.get_decimal("[1]")
                if depth_var.bids is None:
                    depth_var.bids = list()
                depth_var.bids.append(quote_var)
            obj1 = obj.get_array("asks")
            for item2 in obj1.array():
                quote_var3 = Quote()
                quote_var3.price = item2.get_decimal("[0]")
                quote_var3.amount = item2.get_decimal("[1]")
                if depth_var.asks is None:
                    depth_var.asks = list()
                depth_var.asks.append(quote_var3)
            on_depth(depth_var)

        on_depth_event.set_event(on_depth_event_event)
        self.__connection.register_event(on_depth_event)
        ts = CEIUtils.get_now("Unix_ms")
        json = JsonWrapper()
        json.add_json_string(
            "sub",
            CEIUtils.string_replace("market.{0}.depth.{1}", symbol, type_u))
        json.add_json_string("id", ts)
        self.__connection.send(json.to_json_string())
Пример #7
0
 def place_order(self, account_id, symbol, order_type, amount, price):
     request = RestfulRequest(self.__option)
     post_msg = JsonWrapper()
     post_msg.add_json_string("account-Id", account_id)
     post_msg.add_json_string("symbol", symbol)
     post_msg.add_json_string("orderType", order_type)
     post_msg.add_json_string("amount", amount)
     post_msg.add_json_string("price", price)
     request.set_target("/v1/order/orders/place")
     request.set_method(RestfulRequest.Method.POST)
     request.set_post_body(post_msg.to_json_string())
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     order_idvar = OrderID()
     order_idvar.status = root_obj.get_string("status")
     order_idvar.data = root_obj.get_int("data")
     return order_idvar
Пример #8
0
 def post_inputs(self, this, price, number, status):
     request = RestfulRequest(self.__option)
     post_msg = JsonWrapper()
     post_msg.add_json_string("Name", this)
     post_msg.add_json_number("Price", price)
     post_msg.add_json_number("Number", number)
     post_msg.add_json_boolean("Status_1", status)
     request.set_target("/restful/post/echo")
     request.set_method(RestfulRequest.Method.POST)
     request.set_post_body(post_msg.to_json_string())
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     simple_info_var = SimpleInfo()
     simple_info_var.name = root_obj.get_string("Name")
     simple_info_var.number = root_obj.get_int("Number")
     simple_info_var.price = root_obj.get_decimal("Price")
     simple_info_var.status = root_obj.get_bool("Status_1")
     return simple_info_var
Пример #9
0
    def request_candlestick(self, symbol, period, on_candlestick):
        on_candlestick_event = WebSocketEvent(False)

        def on_candlestick_event_trigger(msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            json_checker = JsonChecker()
            json_checker.check_equal(
                "rep",
                CEIUtils.string_replace("market.{0}.kline.{1}", symbol,
                                        period), root_obj)
            return json_checker.complete()

        on_candlestick_event.set_trigger(on_candlestick_event_trigger)

        def on_candlestick_event_event(connection, msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            candlestick_var = Candlestick()
            obj = root_obj.get_array("data")
            for item in obj.array():
                candlestick_data_var = CandlestickData()
                candlestick_data_var.id = item.get_int("id")
                candlestick_data_var.amount = item.get_decimal("amount")
                candlestick_data_var.count = item.get_int("count")
                candlestick_data_var.open = item.get_decimal("open")
                candlestick_data_var.close = item.get_decimal("close")
                candlestick_data_var.low = item.get_decimal("low")
                candlestick_data_var.high = item.get_decimal("high")
                candlestick_data_var.vol = item.get_decimal("vol")
                if candlestick_var.data is None:
                    candlestick_var.data = list()
                candlestick_var.data.append(candlestick_data_var)
            on_candlestick(candlestick_var)

        on_candlestick_event.set_event(on_candlestick_event_event)
        self.__connection.register_event(on_candlestick_event)
        ts = CEIUtils.get_now("Unix_ms")
        json = JsonWrapper()
        json.add_json_string(
            "req",
            CEIUtils.string_replace("market.{0}.kline.{1}", symbol, period))
        json.add_json_string("id", ts)
        self.__connection.send(json.to_json_string())
Пример #10
0
    def subscript_candlestick(self, symbol, period, on_candlestick):
        on_candlestick_event = WebSocketEvent(True)

        def on_candlestick_event_trigger(msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            json_checker = JsonChecker()
            json_checker.check_equal(
                "ch",
                CEIUtils.string_replace("market.{0}.kline.{1}", symbol,
                                        period), root_obj)
            return json_checker.complete()

        on_candlestick_event.set_trigger(on_candlestick_event_trigger)

        def on_candlestick_event_event(connection, msg):
            root_obj = JsonWrapper.parse_from_string(msg.get_string())
            candlestick_data_var = CandlestickData()
            obj = root_obj.get_object("tick")
            candlestick_data_var.id = obj.get_int("id")
            candlestick_data_var.amount = obj.get_decimal("amount")
            candlestick_data_var.count = obj.get_int("count")
            candlestick_data_var.open = obj.get_decimal("open")
            candlestick_data_var.close = obj.get_decimal("close")
            candlestick_data_var.low = obj.get_decimal("low")
            candlestick_data_var.high = obj.get_decimal("high")
            candlestick_data_var.vol = obj.get_decimal("vol")
            on_candlestick(candlestick_data_var)

        on_candlestick_event.set_event(on_candlestick_event_event)
        self.__connection.register_event(on_candlestick_event)
        ts = CEIUtils.get_now("Unix_ms")
        json = JsonWrapper()
        json.add_json_string(
            "sub",
            CEIUtils.string_replace("market.{0}.kline.{1}", symbol, period))
        json.add_json_string("id", ts)
        self.__connection.send(json.to_json_string())
Пример #11
0
 def subscribe_second1(self, on_second1):
     on_second1event = WebSocketEvent(True)
 
     def on_second1event_trigger(msg):
         root_obj = JsonWrapper.parse_from_string(msg.get_string())
         json_checker = JsonChecker()
         json_checker.check_equal("ch", "Second1", root_obj)
         return json_checker.complete()
     on_second1event.set_trigger(on_second1event_trigger)
 
     def on_second1event_event(connection, msg):
         root_obj = JsonWrapper.parse_from_string(msg.get_string())
         simple_info_var = SimpleInfo()
         simple_info_var.name = root_obj.get_string("Name")
         simple_info_var.number = root_obj.get_int("Number")
         simple_info_var.price = root_obj.get_decimal("Price")
         simple_info_var.status = root_obj.get_bool("Status")
         on_second1(simple_info_var)
     on_second1event.set_event(on_second1event_event)
     self.__connection.register_event(on_second1event)
     json_result = JsonWrapper()
     json_result.add_json_string("op", "sub")
     json_result.add_json_string("name", "Second1")
     self.__connection.send(json_result.to_json_string())
Пример #12
0
 def on_ping_event_event(connection, msg):
     ts = CEIUtils.get_now("Unix_ms")
     json_result = JsonWrapper()
     json_result.add_json_string("op", "pong")
     json_result.add_json_string("ts", ts)
     connection.send(json_result.to_json_string())