Ejemplo n.º 1
0
 def get_symbol(self):
     request = RestfulRequest(self.__option)
     request.set_target("/v1/common/symbols")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     json_checker = JsonChecker()
     json_checker.check_not_equal("stauts", "ok", root_obj)
     json_checker.report_error()
     symbols_var = Symbols()
     symbols_var.status = root_obj.get_string("status")
     obj = root_obj.get_array("data")
     for item in obj.array():
         symbols_data_var = SymbolsData()
         symbols_data_var.base_currency = item.get_string("base-currency")
         symbols_data_var.quote_currency = item.get_string("quote-currency")
         symbols_data_var.price_precision = item.get_int("price-precision")
         symbols_data_var.amount_precision = item.get_int(
             "amount-precision")
         symbols_data_var.symbol_partition = item.get_string(
             "symbol-partition")
         symbols_data_var.symbol = item.get_string("symbol")
         symbols_data_var.state = item.get_string("state")
         symbols_data_var.value_precision = item.get_int("value-precision")
         symbols_data_var.min_order_amt = item.get_decimal("min-order-amt")
         symbols_data_var.max_order_amt = item.get_decimal("max-order-amt")
         symbols_data_var.min_order_value = item.get_decimal(
             "min-order-value")
         symbols_data_var.leverage_ratio = item.get_int("leverage-ratio")
         if symbols_var.data is None:
             symbols_var.data = list()
         symbols_var.data.append(symbols_data_var)
     return symbols_var
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def get_timestamp(self):
     request = RestfulRequest(self.__option)
     request.set_target("/api/v3/time")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     timestamp_var = Timestamp()
     timestamp_var.server_time = root_obj.get_int("serverTime")
     return timestamp_var
Ejemplo n.º 8
0
 def get_currencies(self):
     request = RestfulRequest(self.__option)
     request.set_target("/v1/common/currencys")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     currencies_var = Currencies()
     currencies_var.status = root_obj.get_string("status")
     currencies_var.data = root_obj.get_string_array("data")
     return currencies_var
Ejemplo n.º 9
0
 def get_timestamp(self):
     request = RestfulRequest(self.__option)
     request.set_target("/v1/common/timestamp")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     json_checker = JsonChecker()
     json_checker.check_not_equal("stauts", "ok", root_obj)
     json_checker.report_error()
     timestamp_var = Timestamp()
     timestamp_var.timestamp = root_obj.get_int("data")
     return timestamp_var
Ejemplo n.º 10
0
Archivo: test.py Proyecto: macomfan/cei
 def get_simple_info(self):
     request = RestfulRequest(self.__option)
     request.set_target("/restful/get/simpleInfo")
     request.set_method(RestfulRequest.Method.GET)
     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
Ejemplo n.º 11
0
 def cancel_order(self, order_id):
     request = RestfulRequest(self.__option)
     request.set_target(
         CEIUtils.string_replace("/v1/order/orders/{0}/submitcancel",
                                 str(order_id)))
     request.set_method(RestfulRequest.Method.POST)
     Procedures.restful_auth(request, self.__option)
     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
Ejemplo n.º 12
0
 def get_accounts(self):
     request = RestfulRequest(self.__option)
     request.set_target("/v1/account/accounts")
     request.set_method(RestfulRequest.Method.GET)
     Procedures.restful_auth(request, self.__option)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     account_var = Account()
     account_var.status = root_obj.get_string("status")
     account_data_var = AccountData()
     obj = root_obj.get_object("data")
     account_data_var.id = obj.get_int("id")
     account_data_var.state = obj.get_string("state")
     account_data_var.type = obj.get_string("type")
     account_data_var.subtype = obj.get_string("subtype")
     return account_var
Ejemplo n.º 13
0
Archivo: test.py Proyecto: macomfan/cei
 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
Ejemplo n.º 14
0
Archivo: test.py Proyecto: macomfan/cei
 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
Ejemplo n.º 15
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
Ejemplo n.º 16
0
Archivo: test.py Proyecto: macomfan/cei
 def get_price_list(self):
     request = RestfulRequest(self.__option)
     request.set_target("/restful/get/priceList")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     price_list_var = PriceList()
     price_list_var.name = root_obj.get_string("Name")
     obj = root_obj.get_array("Prices")
     for item in obj.array():
         price_entity_var = PriceEntity()
         price_entity_var.price = item.get_decimal("[0]")
         price_entity_var.volume = item.get_decimal("[1]")
         if price_list_var.prices is None:
             price_list_var.prices = list()
         price_list_var.prices.append(price_entity_var)
     return price_list_var
Ejemplo n.º 17
0
Archivo: test.py Proyecto: macomfan/cei
 def get_info_list(self):
     request = RestfulRequest(self.__option)
     request.set_target("/restful/get/infoList")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     info_list_var = InfoList()
     info_list_var.name = root_obj.get_string("Name")
     obj = root_obj.get_array("Values")
     for item in obj.array():
         info_entity_var = InfoEntity()
         info_entity_var.name = item.get_string("Name")
         info_entity_var.info_value = item.get_string("InfoValue")
         if info_list_var.values is None:
             info_list_var.values = list()
         info_list_var.values.append(info_entity_var)
     return info_list_var
Ejemplo n.º 18
0
Archivo: test.py Proyecto: macomfan/cei
 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
Ejemplo n.º 19
0
Archivo: test.py Proyecto: macomfan/cei
 def get_model_info(self):
     request = RestfulRequest(self.__option)
     request.set_target("/restful/get/modelInfo")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     json_checker = JsonChecker()
     json_checker.check_equal("aaa", "aa", root_obj)
     json_checker.report_error()
     model_info_var = ModelInfo()
     model_info_var.name = root_obj.get_string("Name")
     obj = root_obj.get_object("DataL1")
     obj0 = obj.get_object("DataL2")
     model_value_var = ModelValue()
     obj1 = obj0.get_object("Value")
     model_value_var.name = obj1.get_string("Name")
     model_value_var.value = obj1.get_int("Value")
     model_info_var.value = model_value_var
     return model_info_var
Ejemplo n.º 20
0
 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
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
 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
Ejemplo n.º 23
0
 def get_exchange_info(self):
     request = RestfulRequest(self.__option)
     request.set_target("/api/v3/exchangeInfo")
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     root_obj = JsonWrapper.parse_from_string(response.get_string())
     exchange_info_var = ExchangeInfo()
     exchange_info_var.timezone = root_obj.get_string("timezone")
     exchange_info_var.server_time = root_obj.get_int("serverTime")
     obj = root_obj.get_array("rateLimits")
     for item in obj.array():
         rate_limits_var = RateLimits()
         rate_limits_var.rate_limit_type = item.get_string("rateLimitType")
         rate_limits_var.interval = item.get_string("interval")
         rate_limits_var.interval_num = item.get_int("intervalNum")
         rate_limits_var.limit = item.get_int("limit")
         if exchange_info_var.rate_limits is None:
             exchange_info_var.rate_limits = list()
         exchange_info_var.rate_limits.append(rate_limits_var)
     obj0 = root_obj.get_array("symbols")
     for item1 in obj0.array():
         symbol_var = Symbol()
         symbol_var.symbol = item1.get_string("symbol")
         symbol_var.status = item1.get_string("status")
         symbol_var.base_asset = item1.get_string("baseAsset")
         symbol_var.base_asset_precision = item1.get_int(
             "baseAssetPrecision")
         symbol_var.quote_asset = item1.get_string("quoteAsset")
         symbol_var.quote_precision = item1.get_int("quotePrecision")
         symbol_var.order_types = item1.get_string_array("orderTypes")
         symbol_var.iceberg_allowed = item1.get_bool("icebergAllowed")
         symbol_var.oco_allowed = item1.get_bool("ocoAllowed")
         if exchange_info_var.symbols is None:
             exchange_info_var.symbols = list()
         exchange_info_var.symbols.append(symbol_var)
     return exchange_info_var
Ejemplo n.º 24
0
 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
Ejemplo n.º 25
0
Archivo: test.py Proyecto: macomfan/cei
 def url(self, input_u):
     request = RestfulRequest(self.__option)
     request.set_target(CEIUtils.string_replace("/restful/get/url/{0}", input_u))
     request.set_method(RestfulRequest.Method.GET)
     response = RestfulConnection.query(request)
     return response.get_string()