def api_get(self, method, params={}): # 现货API if self.account: apikey, secretkey = get_account_key("okex", self.account) okcoinSpot = OKCoinFuture(okcoinRESTURL, apikey, secretkey) if method == "future_userinfo_4fix": api_do = "okcoinSpot.%s()" % (method) return eval(api_do) elif method == "future_position_4fix": return okcoinSpot.future_position_4fix(params["symbol"], params["contractType"], params["type"]) elif method == "trade": return okcoinSpot.future_trade(params["symbol"], params["contractType"], params["price"], params["amount"], params["type"], params["match_price"], params["lever_rate"]) elif method == "ticker": return okcoinSpot.future_ticker(params["symbol"], params["contractType"]) elif method == "order_info": return okcoinSpot.future_orderinfo(params["symbol"], params["contractType"], params["id"]) elif method == "cancelOrder": return okcoinSpot.future_cancel(params["symbol"], params["contractType"], params["id"])
from OkcoinSpotAPI import OKCoinSpot from OkcoinFutureAPI import OKCoinFuture from HttpMD5Util import * #初始化apikey,secretkey,url apikey = '4b36c965-a577-497a-a216-665cedd68655' secretkey = 'D0AB97E9CFE3F57131162952CE368191' okcoinRESTURL = 'www.okex.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL,apikey,secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL,apikey,secretkey) okcoinFuture.future_trade(symbol='eos_usd',contractType='next_week',price=str(json_eos_next_week['asks'][0][0]), amount='1',tradeType='1',matchPrice='0',leverRate='') params = {'api_key': '4b36c965-a577-497a-a216-665cedd68655', 'amount': '1', 'symbol': 'btc_usd'} params['sign'] = buildMySign(params,secretkey) okcoinFuture.futureFundTransfer('btc_usd','1', '1') okcoinFuture.futureFundTransfer('eos_usd','1', '4.98997989') param = 'symbol=eos_usdt&contract_type=quarter' httpGet("www.okex.com", "/api/v1/future_hold_amount.do", param) okcoinFuture.future_position_4fix('eos_usd','next_week','1') def getAmount(amountJson): if amountJson['holding'] == []: return 0. else: return amountJson['holding']['buy_amount']
print u'获取预估交割价' print okcoinFuture.future_estimated_price('ltc_usd') print u'获取全仓账户信息' print okcoinFuture.future_userinfo() print u'获取全仓持仓信息' print okcoinFuture.future_position('ltc_usd','this_week') print u'期货下单' print okcoinFuture.future_trade('ltc_usd','this_week','0.1','1','1','0','20') print u'期货批量下单' print okcoinFuture.future_batchTrade('ltc_usd','this_week','[{price:0.1,amount:1,type:1,match_price:0},{price:0.1,amount:3,type:1,match_price:0}]','20') print u'期货取消订单' print okcoinFuture.future_cancel('ltc_usd','this_week','47231499') print u'期货获取订单信息' print okcoinFuture.future_orderinfo('ltc_usd','this_week','47231812','0','1','2') print u'期货逐仓账户信息' print okcoinFuture.future_userinfo_4fix() print u'期货逐仓持仓信息' print okcoinFuture.future_position_4fix('ltc_usd','this_week',1)
# nbdev=2 stop_N = 2 entry_price = 0 last_entry_price = 0 entry_atr = 0 units = 0 while True: time.sleep(1) try: print(u'------') print(u'当季期货行情信息') trades = okcoinFuture.future_trades('btc_usd', contract_type) klines = okcoinFuture.kline('btc_usd', kline_type, contract_type, 1001) future_userinfo_4fix = okcoinFuture.future_userinfo_4fix() future_position_4fix = okcoinFuture.future_position_4fix( 'btc_usd', contract_type, 1) future_order_info = okcoinFuture.future_orderinfo( 'btc_usd', contract_type, '-1', '2', 1, 45) future_ticker = okcoinFuture.future_ticker('btc_usd', contract_type) if future_userinfo_4fix == '': continue if future_position_4fix == '': continue if future_order_info == '': continue future_userinfo_4fix_json = json.loads(future_userinfo_4fix) future_position_4fix_json = json.loads(future_position_4fix) future_order_info_json = json.loads(future_order_info) holding = future_position_4fix_json['holding'] orders = future_order_info_json['orders'] rights = future_userinfo_4fix_json['info']['btc']['rights']