def cancelOrder(self, symbol, orderId): CANCEL_ORDER_RESOURCE = "/api/v1/cancel_order.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'order_id': orderId } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, CANCEL_ORDER_RESOURCE, params)
def cancel_order(self, currency_pair, order_id): CANCEL_ORDER_RESOURCE = "/api/v1/cancel_order.do" params = { 'api_key': self.account.api_key, 'symbol': currency_pair, 'order_id': order_id } params['sign'] = buildMySign(params, self.account.secret_key) return httpPost(self.base_url, CANCEL_ORDER_RESOURCE, params)
def future_position(self,symbol,contractType): FUTURE_POSITION = "/api/v1/future_position.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_POSITION,params)
def trade_history(self, currency_pair, since): TRADE_HISTORY_RESOURCE = "/api/v1/trade_history.do" params = { 'api_key': self.account.api_key, 'symbol': currency_pair, 'since': since, } params['sign'] = buildMySign(params, self.account.secret_key) return httpPost(self.base_url, TRADE_HISTORY_RESOURCE, params)
def orderinfo(self,symbol,orderId): ORDER_INFO_RESOURCE = "/api/v1/order_info.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'order_id':orderId } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,ORDER_INFO_RESOURCE,params)
def future_return_chart_2000(self, symbol, contractType): FUTURE_CHART = "/api/v1/future_kline.do?" params = { 'api_key': self.__apikey, 'symbol': symbol, 'contract_type': contractType } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, FUTURE_CHART, params)
def cancelOrder(self,symbol,orderId): CANCEL_ORDER_RESOURCE = "/api/v1/cancel_order.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'order_id':orderId } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,CANCEL_ORDER_RESOURCE,params)
def orderinfo(self, symbol, orderId): ORDER_INFO_RESOURCE = "/api/v1/order_info.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'order_id': orderId } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, ORDER_INFO_RESOURCE, params)
def future_cancel(self,symbol,contractType,orderId): FUTURE_CANCEL = "/api/v1/future_cancel.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'order_id':orderId } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_CANCEL,params)
def future_position_4fix(self,symbol,contractType,type1): FUTURE_POSITION_4FIX = "/api/v1/future_position_4fix.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'type':type1 } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_POSITION_4FIX,params)
def future_userinfo(self): FUTURE_USERINFO = "/api/v1/future_userinfo.do?" params = {} params['api_key'] = self.__apikey params['sign'] = buildMySign(params, self.__secretkey) try: res = httpPost(self.__url, FUTURE_USERINFO, params) except Exception as e: res = '{"result":false}' return res
def get_fee(self,symbol, order_id): TRADE_RESOURCE = "/api/v1/order_fee.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'order_id':order_id } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,TRADE_RESOURCE,params)
def future_devolve(self, symbol, type='2', amount='0.01'): FUTURE_DEPTH_RESOURCE = "/api/v1/future_devolve.do" params = { 'symbol': symbol, 'type': type, 'amount': amount, } params['api_key'] = self.__apikey params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, FUTURE_DEPTH_RESOURCE, params)
def batchTrade(self, symbol, tradeType, orders_data): BATCH_TRADE_RESOURCE = "/api/v1/batch_trade.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'type': tradeType, 'orders_data': orders_data } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, BATCH_TRADE_RESOURCE, params)
def batch_trade(self,currency_pair,type,orders_data): BATCH_TRADE_RESOURCE = "/api/v1/batch_trade.do" params = { 'api_key':self.account.api_key, 'symbol':currency_pair, 'type':type, 'orders_data':orders_data } params['sign'] = buildMySign(params,self.account.secret_key) return httpPost(self.base_url,BATCH_TRADE_RESOURCE,params)
def batchTrade(self,symbol,tradeType,orders_data): BATCH_TRADE_RESOURCE = "/api/v1/batch_trade.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'type':tradeType, 'orders_data':orders_data } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,BATCH_TRADE_RESOURCE,params)
def ordersinfo(self,symbol,orderId,tradeType): ORDERS_INFO_RESOURCE = u"/api/v1/orders_info.do" params = { u'api_key':self.__apikey, u'symbol':symbol, u'order_id':orderId, u'type':tradeType } params[u'sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,ORDERS_INFO_RESOURCE,params)
def getFuturePosition(sym, contractType): post_data = { 'symbol': sym, 'contract_type': contractType, 'api_key': apiKey } post_data['sign'] = buildMySign(post_data, secretKey) res = json.loads( httpPost("www.okex.com", "/api/v1/future_position", post_data)) return res
def orders_info(self, symbol, order_ids, tradeType=0): ORDERS_INFO_RESOURCE = "/api/v1/orders_info.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'order_id': ','.join(order_ids), 'type': tradeType } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, ORDERS_INFO_RESOURCE, params)
def query_withdraw(self, currency, id): QUERY_WITHDRAW_RESOURCE = '/api/v1/withdraw_info.do' params = { 'api_key': self.__apikey, 'symbol': currency, 'withdraw_id': id } params['sign'] = buildMySign(params, self.__secretkey) #print params return httpPost(self.__url, QUERY_WITHDRAW_RESOURCE, params)
def getFutureOrderInfo(sym, contractType, orderId): post_data = { 'symbol': sym, 'contract_type': contractType, 'api_key': apiKey, 'order_id': orderId } post_data['sign'] = buildMySign(post_data, secretKey) res = json.loads( httpPost("www.okex.com", "/api/v1/future_order_info", post_data)) return res['orders']
def funds_transfer(self, amount, From, To, symbol=""): # 转出账户(1:币币账户 3:合约账户 6:我的钱包) USERINFO_RESOURCE = "/api/v1/funds_transfer.do" params = {'api_key': self.__apikey, "symbol": symbol, "amount": amount, "from": From, "to": To} params['sign'] = buildMySign(params, self.__secretkey) #print params return httpPost(self.__url, USERINFO_RESOURCE, params)
def future_cancelorders(self, symbol, contractType, orderIds): FUTURE_CANCEL = "/api/v1/future_cancel.do?" orderIds = ",".join([str(x) for x in orderIds]) params = { 'api_key': self.__apikey, 'symbol': symbol, 'contract_type': contractType, 'order_id': orderIds } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, FUTURE_CANCEL, params)
def trade(self,symbol,tradeType,price,amount): TRADE_RESOURCE = "/api/v1/trade.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'type':tradeType, 'price':price, 'amount':amount } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,TRADE_RESOURCE,params)
def userinfo(self): USERINFO_RESOURCE = "/api/v1/userinfo.do" params = {} params['api_key'] = self.__apikey params['sign'] = buildMySign(params, self.__secretkey) result = httpPost(self.__url, USERINFO_RESOURCE, params) for elem in result['info']['funds'].values(): for key in elem.keys(): elem[key] = float(elem[key]) return result
def future_batchTrade(self,symbol,contractType,orders_data,leverRate): FUTURE_BATCH_TRADE = "/api/v1/future_batch_trade.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'orders_data':orders_data, 'lever_rate':leverRate } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_BATCH_TRADE,params)
def orderHistory(self,symbol,status,currentPage,pageLength): ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'status':status, 'current_page':currentPage, 'page_length':pageLength } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,ORDER_HISTORY_RESOURCE,params)
def trade_list(self,currency_pair, current_page=1, page_length=200): ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do" params = { 'api_key': self.account.api_key, 'symbol': currency_pair, 'status': 1, 'current_page': current_page, 'page_length': page_length } params['sign'] = buildMySign(params, self.account.secret_key) return httpPost(self.base_url, ORDER_HISTORY_RESOURCE, params)
def orderHistory(self, symbol, status, currentPage, pageLength): ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'status': status, 'current_page': currentPage, 'page_length': pageLength } params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, ORDER_HISTORY_RESOURCE, params)
def fundDevolve(sym, transType, amount): post_data = { "api_key": apiKey, 'symbol': sym, 'amount': amount, 'type': transType } post_data['sign'] = buildMySign(post_data, secretKey) res = {} res = json.loads( httpPost("www.okex.com", "/api/v1/future_devolve.do", post_data)) return res
def future_orderinfo(self,symbol,contractType,orderId,status,currentPage,pageLength): FUTURE_ORDERINFO = "/api/v1/future_order_info.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'order_id':orderId, 'status':status, 'current_page':currentPage, 'page_length':pageLength } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_ORDERINFO,params)
def order_list(self, currency_pair, current_page=1, page_length=200): ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do" params = { 'api_key': self.account.api_key, 'symbol': currency_pair, 'status': 0, 'current_page': current_page, 'page_length': page_length } params['sign'] = buildMySign(params, self.account.secret_key) result = httpPost(self.base_url, ORDER_HISTORY_RESOURCE, params) result = universal.SubmittedOrderList(currency_pair, result) return result
def get_all_currencies(self): import json USERINFO_RESOURCE = "/api/v1/userinfo.do" params = {} params['api_key'] = self.account.api_key params['sign'] = buildMySign(params, self.account.secret_key) result = json.loads(httpPost(self.base_url, USERINFO_RESOURCE, params)) result = result["info"]["funds"]["free"] result = dict(result).keys() currencies = [] for item in result: currencies.append(item) return currencies
def future_trade(self,symbol,contractType,price,amount,tradeType,matchPrice,leverRate): FUTURE_TRADE = "/api/v1/future_trade.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'price':price, 'amount':amount, 'type':tradeType, 'match_price':matchPrice, 'lever_rate':leverRate } params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_TRADE,params)
def trade(self,symbol,tradeType,price='',amount=''): TRADE_RESOURCE = "/api/v1/trade.do" params = { 'api_key':self.__apikey, 'symbol':symbol, 'type':tradeType } if price: params['price'] = price if amount: params['amount'] = amount params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,TRADE_RESOURCE,params)
def trade(self, symbol, tradeType, price='', amount=''): TRADE_RESOURCE = "/api/v1/trade.do" params = { 'api_key': self.__apikey, 'symbol': symbol, 'type': tradeType } if price: params['price'] = price if amount: params['amount'] = amount params['sign'] = buildMySign(params, self.__secretkey) return httpPost(self.__url, TRADE_RESOURCE, params)
def account_info(self): USERINFO_RESOURCE = "/api/v1/userinfo.do" params = {} params['api_key'] = self.__apikey params['sign'] = buildMySign(params, self.__secretkey) ok_res = httpPost(self.__url, USERINFO_RESOURCE, params) res = {} for i in ok_res['info']['funds']['free'].keys(): dic = { 'available': float(ok_res['info']['funds']['free'][i]), 'lock': float(ok_res['info']['funds']['freezed'][i]) } res[i] = dic return res
def future_trade(self,symbol,contractType,price='',amount='',tradeType='',matchPrice='',leverRate=''): FUTURE_TRADE = "/api/v1/future_trade.do?" params = { 'api_key':self.__apikey, 'symbol':symbol, 'contract_type':contractType, 'amount':amount, 'type':tradeType, 'match_price':matchPrice, 'lever_rate':leverRate } if price: params['price'] = price params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_TRADE,params)
def future_trade(self,symbol,contractType,price=u'',amount=u'',tradeType=u'',matchPrice=u'',leverRate=u''): FUTURE_TRADE = u"/api/v1/future_trade.do?" params = { u'api_key':self.__apikey, u'symbol':symbol, u'contract_type':contractType, u'amount':amount, u'type':tradeType, u'match_price':matchPrice, u'lever_rate':leverRate } if price: params[u'price'] = price params[u'sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_TRADE,params)
def future_userinfo(self): FUTURE_USERINFO = "/api/v1/future_userinfo.do?" params ={} params['api_key'] = self.__apikey params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_USERINFO,params)
def future_userinfo_4fix(self): FUTURE_INFO_4FIX = "/api/v1/future_userinfo_4fix.do?" params = {'api_key':self.__apikey} params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,FUTURE_INFO_4FIX,params)
def userinfo(self): USERINFO_RESOURCE = "/api/v1/userinfo.do" params ={} params['api_key'] = self.__apikey params['sign'] = buildMySign(params,self.__secretkey) return httpPost(self.__url,USERINFO_RESOURCE,params)