def test_http_post(self): # curl -s 'https://www.okex.com/api/v1/ticker.do?symbol=ltc_btc' | jq . url = 'www.okex.com' resource = '/api/v1/ticker.do' params = {'symbol': 'ltc_btc'} json = httpmd5util.http_get(url, resource, params) print(json) self.assertEqual(1,1)
def future_trades(self, symbol, contractType): FUTURE_TRADES_RESOURCE = "/api/v1/future_trades.do" params = '' if symbol: params += '&symbol=' + symbol if params else 'symbol=' + symbol if contractType: params += '&contract_type=' + contractType if params else 'contract_type=' + symbol return http_get(self.__url, FUTURE_TRADES_RESOURCE, params)
def orderinfo(self, symbol, orderId): ORDER_INFO_RESOURCE = "/api/v1/order_info.do" params = { 'api_key': self.__api_key, 'symbol': symbol, 'order_id': orderId } params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, ORDER_INFO_RESOURCE, params)
def cancelOrder(self, symbol, orderId): CANCEL_ORDER_RESOURCE = "/api/v1/cancel_order.do" params = { 'api_key': self.__api_key, 'symbol': symbol, 'order_id': orderId } params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, CANCEL_ORDER_RESOURCE, params)
def batchTrade(self, symbol, tradeType, orders_data): BATCH_TRADE_RESOURCE = "/api/v1/batch_trade.do" params = { 'api_key': self.__api_key, 'symbol': symbol, 'type': tradeType, 'orders_data': orders_data } params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, BATCH_TRADE_RESOURCE, params)
def future_depth(self, symbol, contractType, size): FUTURE_DEPTH_RESOURCE = "/api/v1/future_depth.do" params = '' if symbol: params += '&symbol=' + symbol if params else 'symbol=' + symbol if contractType: params += '&contract_type=' + contractType if params else 'contract_type=' + symbol if size: params += '&size=' + size if params else 'size=' + size return http_get(self.__url, FUTURE_DEPTH_RESOURCE, params)
def orderHistory(self, symbol, status, currentPage, pageLength): ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do" params = { 'api_key': self.__api_key, 'symbol': symbol, 'status': status, 'current_page': currentPage, 'page_length': pageLength } params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, ORDER_HISTORY_RESOURCE, params)
def trade(self, symbol, tradeType, price='', amount=''): TRADE_RESOURCE = "/api/v1/trade.do" params = { 'api_key': self.__api_key, 'symbol': symbol, 'type': tradeType } if price: params['price'] = price if amount: params['amount'] = amount params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, TRADE_RESOURCE, params)
def userinfo(self): USERINFO_RESOURCE = "/api/v1/userinfo.do" params = {} params['api_key'] = self.__api_key params['sign'] = build_sign(params, self.__secret_key) return http_get(self.__url, USERINFO_RESOURCE, params)
def trades(self, symbol=''): TRADES_RESOURCE = "/api/v1/trades.do" params = '' if symbol: params = 'symbol=%(symbol)s' % {'symbol': symbol} return http_get(self.__url, TRADES_RESOURCE, params)
def depth(self, symbol=''): DEPTH_RESOURCE = "/api/v1/depth.do" params = '' if symbol: params = 'symbol=%(symbol)s' % {'symbol': symbol} return http_get(self.__url, DEPTH_RESOURCE, params)
def ticker(self, symbol=''): TICKER_RESOURCE = "/api/v1/ticker.do" params = '' if symbol: params = 'symbol=%(symbol)s' % {'symbol': symbol} return http_get(self.__url, TICKER_RESOURCE, params)
def future_estimated_price(self, symbol): FUTURE_ESTIMATED_PRICE = "/api/v1/future_estimated_price.do" params = '' if symbol: params = 'symbol=' + symbol return http_get(self.__url, FUTURE_ESTIMATED_PRICE, params)
def exchange_rate(self): EXCHANGE_RATE = "/api/v1/exchange_rate.do" return http_get(self.__url, EXCHANGE_RATE, '')
def future_index(self, symbol): FUTURE_INDEX = "/api/v1/future_index.do" params = '' if symbol: params = 'symbol=' + symbol return http_get(self.__url, FUTURE_INDEX, params)