def get_depth(self, symbol, limit): request = RestfulRequest(self.__option) request.set_target("/api/v3/depth") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("limit", str(limit)) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) depth_var = Depth() depth_var.last_update_id = root_obj.get_int("lastUpdateId") obj = root_obj.get_array("bids") for item in obj.array(): depth_entity_var = DepthEntity() depth_entity_var.price = item.get_decimal("[0]") depth_entity_var.qty = item.get_decimal("[1]") if depth_var.bids is None: depth_var.bids = list() depth_var.bids.append(depth_entity_var) obj0 = root_obj.get_array("asks") for item1 in obj0.array(): depth_entity_var2 = DepthEntity() depth_entity_var2.price = item1.get_decimal("[0]") depth_entity_var2.qty = item1.get_decimal("[1]") if depth_var.asks is None: depth_var.asks = list() depth_var.asks.append(depth_entity_var2) return depth_var
def get_aggregate_trades(self, symbol, from_id, start_time, end_time, limit): request = RestfulRequest(self.__option) request.set_target("/api/v3/aggTrades") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("fromId", str(from_id)) request.add_query_string("startTime", str(start_time)) request.add_query_string("startTime", str(end_time)) request.add_query_string("limit", str(limit)) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) aggregate_trade_list_var = AggregateTradeList() for item in root_obj.array(): aggregate_trade_var = AggregateTrade() aggregate_trade_var.id = item.get_int("a") aggregate_trade_var.price = item.get_decimal("p") aggregate_trade_var.qty = item.get_decimal("q") aggregate_trade_var.first_trade_id = item.get_int("f") aggregate_trade_var.last_trade_id = item.get_int("l") aggregate_trade_var.timestamp = item.get_int("T") aggregate_trade_var.is_buyer_maker = item.get_bool("m") aggregate_trade_var.is_best_match = item.get_bool("M") if aggregate_trade_list_var.data is None: aggregate_trade_list_var.data = list() aggregate_trade_list_var.data.append(aggregate_trade_var) return aggregate_trade_list_var
def get_last_trade(self, symbol): request = RestfulRequest(self.__option) request.set_target("/market/trade") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) last_trade_var = LastTrade() last_trade_var.status = root_obj.get_string("status") last_trade_var.ts = root_obj.get_int("ts") last_trade_var.ch = root_obj.get_string("ch") obj = root_obj.get_object("tick") last_trade_var.ts_in_tick = obj.get_int("ts") last_trade_var.id_in_tick = obj.get_int("id") obj0 = obj.get_array("data") for item in obj0.array(): trade_var = Trade() trade_var.amount = item.get_decimal("amount") trade_var.price = item.get_decimal("price") trade_var.ts = item.get_int("ts") trade_var.id = item.get_int("id") trade_var.direction = item.get_string("direction") trade_var.trade_id = item.get_int("trade-id") if last_trade_var.data is None: last_trade_var.data = list() last_trade_var.data.append(trade_var) return last_trade_var
def get_candlestick(self, symbol, period, size): request = RestfulRequest(self.__option) request.set_target("/market/history/kline") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("period", period) request.add_query_string("size", str(size)) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) candlestick_var = Candlestick() candlestick_var.status = root_obj.get_string("status") 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) return candlestick_var
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
def get_candlestick_data(self, symbol, interval, start_time, end_time, limit): request = RestfulRequest(self.__option) request.set_target("/api/v3/klines") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("interval", interval) request.add_query_string("startTime", str(start_time)) request.add_query_string("endTime", str(end_time)) request.add_query_string("limit", str(limit)) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) candlestick_data_list_var = CandlestickDataList() for item in root_obj.array(): candlestick_data_var = CandlestickData() candlestick_data_var.open = item.get_decimal("\\[0]") candlestick_data_var.high = item.get_decimal("\\[1]") if candlestick_data_list_var.data is None: candlestick_data_list_var.data = list() candlestick_data_list_var.data.append(candlestick_data_var) return candlestick_data_list_var
def get_market_depth(self, symbol, depth, merge_type): request = RestfulRequest(self.__option) request.set_target("/market/depth") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("depth", str(depth)) request.add_query_string("type", merge_type) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) depth_var = Depth() depth_var.status = root_obj.get_string("status") depth_var.ts = root_obj.get_int("ts") 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) return depth_var
def get_trade(self, symbol, limit): request = RestfulRequest(self.__option) request.set_target("/api/v3/trades") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("limit", str(limit)) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) trade_list_var = TradeList() for item in root_obj.array(): trade_var = Trade() trade_var.id = item.get_int("id") trade_var.price = item.get_decimal("price") trade_var.qty = item.get_decimal("qty") trade_var.quote_qty = item.get_decimal("quoteQty") trade_var.time = item.get_int("time") trade_var.is_buyer_maker = item.get_bool("isBuyerMaker") trade_var.is_best_match = item.get_bool("isBestMatch") if trade_list_var.data is None: trade_list_var.data = list() trade_list_var.data.append(trade_var) return trade_list_var
def inputs_by_get(self, name, number, price, status): request = RestfulRequest(self.__option) request.set_target("/restful/get/inputsByGet") request.set_method(RestfulRequest.Method.GET) request.add_query_string("Name", name) request.add_query_string("Number", str(number)) request.add_query_string("Price", str(price)) request.add_query_string("Status", str(status)) 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") return simple_info_var
def get_latest_aggregated_ticker(self, symbol): request = RestfulRequest(self.__option) request.set_target("/market/detail/merged") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) aggregated_market_data_var = AggregatedMarketData() obj = root_obj.get_object("data") aggregated_market_data_var.id = obj.get_int("id") aggregated_market_data_var.amount = obj.get_decimal("amount") aggregated_market_data_var.count = obj.get_int("count") aggregated_market_data_var.open = obj.get_decimal("open") aggregated_market_data_var.close = obj.get_decimal("close") aggregated_market_data_var.low = obj.get_decimal("low") aggregated_market_data_var.high = obj.get_decimal("high") aggregated_market_data_var.vol = obj.get_decimal("vol") obj0 = obj.get_object("bid") aggregated_market_data_var.bid_price = obj0.get_decimal("[0]") aggregated_market_data_var.bid_size = obj0.get_decimal("[1]") obj1 = obj.get_object("ask") aggregated_market_data_var.ask_price = obj1.get_decimal("[0]") aggregated_market_data_var.ask_size = obj1.get_decimal("[1]") return aggregated_market_data_var
def get_best_quote(self, symbol): request = RestfulRequest(self.__option) request.set_target("/market/depth") request.set_method(RestfulRequest.Method.GET) request.add_query_string("symbol", symbol) request.add_query_string("depth", "5") request.add_query_string("type", "step0") response = RestfulConnection.query(request) root_obj = JsonWrapper.parse_from_string(response.get_string()) best_quote_var = BestQuote() best_quote_var.status = root_obj.get_string("status") best_quote_var.ts = root_obj.get_int("ts") obj = root_obj.get_object("tick") obj0 = obj.get_object("bids") obj1 = obj0.get_object("[0]") best_quote_var.best_bid_price = obj1.get_decimal("[0]") best_quote_var.best_bid_amount = obj1.get_decimal("[1]") obj2 = obj.get_object("asks") obj3 = obj2.get_object("[0]") best_quote_var.best_ask_price = obj3.get_decimal("[0]") best_quote_var.best_ask_amount = obj3.get_decimal("[1]") best_quote_var.ch = root_obj.get_string("ch") return best_quote_var