Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
File: test.py Progetto: 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
Esempio n. 4
0
File: test.py Progetto: 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
Esempio n. 5
0
File: test.py Progetto: 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
Esempio n. 6
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
Esempio n. 7
0
 def query(request: RestfulRequest):
     if request.get_method() == RestfulRequest.Method.GET:
         path = request.get_url() + request.get_target(
         ) + request.build_query_string()
         response = requests.get(path, headers=request.get_header())
         return RestfulResponse(response)
     elif request.get_method() == RestfulRequest.Method.POST:
         path = request.get_url() + request.get_target(
         ) + request.build_query_string()
         response = requests.post(path,
                                  headers=request.get_header(),
                                  data=request.get_post_body())
         return RestfulResponse(response)
     else:
         pass
     pass
Esempio n. 8
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
Esempio n. 9
0
 def historical_trades(self, symbol, limit, from_id):
     request = RestfulRequest(self.__option)
     request.set_target("/api/v3/historicalTrades")
     request.set_method(RestfulRequest.Method.GET)
     request.add_query_string("symbol", symbol)
     request.add_query_string("limit", str(limit))
     request.add_query_string("fromId", str(from_id))
     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
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
0
File: test.py Progetto: 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()
Esempio n. 14
0
File: test.py Progetto: 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