def withdraw_info(self, symbol, withdraw_id): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'withdraw_id': withdraw_id } res = OKCoinBase.RESOURCES_URL['withdraw_info'] return self._signed_request(params, res)
def batch_trade(self, symbol, orders_data): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'orders_data':orders_data } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() params['lever_rate'] = 10 res = OKCoinBase.RESOURCES_URL['batch_trade'].format('future_' if cfg.is_future() else '') return self._signed_request(params, res)
def withdraw(self, symbol, charge_fee, trade_pwd, withdraw_address, withdraw_amount, target): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'charge_fee': charge_fee, 'trade_pwd': trade_pwd, 'withdraw_address': withdraw_address, 'withdraw_amount': withdraw_amount, 'target': target } res = OKCoinBase.RESOURCES_URL['withdraw'] return self._signed_request(params, res)
def batch_trade(self, symbol, orders_data): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'orders_data': orders_data } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() params['lever_rate'] = 10 res = OKCoinBase.RESOURCES_URL['batch_trade'].format( 'future_' if cfg.is_future() else '') return self._signed_request(params, res)
def user_info(self): """return: { info:{ xxx:{ account_rights:账户权益 keep_deposit:保证金 profit_real:已实现盈亏 profit_unreal:未实现盈亏 risk_rate:保证金率 } ... } result:... } or 4fix return: { info:{ xxx:{ balance:账户余额(可用保证金) contracts:[{ available:合约可用(可用保证金) balance:账户(合约)余额 bond:固定保证金(已用保证金) contract_id:合约ID contract_type:合约类别 freeze:冻结保证金 profit:已实现盈亏 unprofit:未实现盈亏 }] rights:账户权益 } ... } result:... } """ params = {'api_key': cfg.get_id()} if cfg.is_future(): res = OKCoinBase.RESOURCES_URL[ 'user_info' if cfg.is_future_mode_all( ) else 'user_info_4fix'].format('future_') else: res = OKCoinBase.RESOURCES_URL['user_info'] ret = self._signed_request(params, res) if ret['result'] == True: return ret['info'] else: log.err("user_info ret:%s" % ret) return None
def orders_info(self, symbol, order_id): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'order_id': order_id } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() res = OKCoinBase.RESOURCES_URL['orders_info'].format('future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return ret['orders'] else: return None
def user_info(self): """return: { info:{ xxx:{ account_rights:账户权益 keep_deposit:保证金 profit_real:已实现盈亏 profit_unreal:未实现盈亏 risk_rate:保证金率 } ... } result:... } or 4fix return: { info:{ xxx:{ balance:账户余额(可用保证金) contracts:[{ available:合约可用(可用保证金) balance:账户(合约)余额 bond:固定保证金(已用保证金) contract_id:合约ID contract_type:合约类别 freeze:冻结保证金 profit:已实现盈亏 unprofit:未实现盈亏 }] rights:账户权益 } ... } result:... } """ params = {'api_key': cfg.get_id()} if cfg.is_future(): res = OKCoinBase.RESOURCES_URL['user_info' if cfg.is_future_mode_all() else 'user_info_4fix'].format('future_') else: res = OKCoinBase.RESOURCES_URL['user_info'] ret = self._signed_request(params, res) if ret['result'] == True: return ret['info'] else: log.err("user_info ret:%s"%ret) return None
def future_cancel(self, symbol, order_id): """return: result:订单交易成功或失败(用于单笔订单) order_id:订单ID(用于单笔订单) success:成功的订单ID(用于多笔订单) error:失败的订单ID后跟失败错误码(用户多笔订单) """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'order_id': order_id, 'contract_type': cfg.get_future_contract_type() } res = OKCoinBase.RESOURCES_URL['cancel'] return self._signed_request(params, res)
def orders_info(self, symbol, order_id): params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'order_id': order_id } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() res = OKCoinBase.RESOURCES_URL['orders_info'].format( 'future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return ret['orders'] else: return None
def order_info(self, symbol, order_id, status, current_page=1, page_length=50): """params: status String 否 查询状态 1:未完成的订单 2:已经完成的订单 order_id String 是 订单ID -1:查询指定状态的订单,否则查询相应订单号的订单 current_page String 否 当前页数 page_length String 否 每页获取条数,最多不超过50 return: { orders:[{ amount: 委托数量 contract_name: 合约名称 create_date: 委托时间 deal_amount: 成交数量 fee: 手续费 order_id: 订单ID price: 订单价格 price_avg: 平均价格 status: 订单状态(0等待成交 1部分成交 2全部成交 -1撤单 4撤单处理中 5撤单中) symbol: btc_usd ltc_usd eth_usd etc_usd bch_usd type: 订单类型 1:开多 2:开空 3:平多 4: 平空 unit_amount:合约面值 lever_rate: 杠杆倍数 value:10\20 默认10 }] result:... } """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'status': status, 'order_id': order_id, 'current_page': current_page, 'page_length': page_length } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() res = OKCoinBase.RESOURCES_URL['order_info'].format( 'future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return ret['orders'] else: return None
def future_trades_history(self, symbol, date, since): """return: amount:交易数量 date:交易时间(毫秒) price:交易价格 tid:交易ID type:交易类型(buy/sell) """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'date': date, 'since': since } res = OKCoinBase.RESOURCES_URL['trades_history'] return self._signed_request(params, res)
def future_explosive(self, symbol, status, current_page, page_number, page_length): """return: amount:委托数量(张) create_date:创建时间 loss:穿仓用户亏损 price:委托价格 type:交易类型 1:买入开多 2:卖出开空 3:卖出平多 4:买入平空 """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'contract_type': cfg.get_future_contract_type(), 'status': status, 'current_page': current_page, 'page_number': page_number, 'page_length': page_length } res = OKCoinBase.RESOURCES_URL['explosive'] return self._signed_request(params, res)
def order_info(self, symbol, order_id, status, current_page=1, page_length=50): """params: status String 否 查询状态 1:未完成的订单 2:已经完成的订单 order_id String 是 订单ID -1:查询指定状态的订单,否则查询相应订单号的订单 current_page String 否 当前页数 page_length String 否 每页获取条数,最多不超过50 return: { orders:[{ amount: 委托数量 contract_name: 合约名称 create_date: 委托时间 deal_amount: 成交数量 fee: 手续费 order_id: 订单ID price: 订单价格 price_avg: 平均价格 status: 订单状态(0等待成交 1部分成交 2全部成交 -1撤单 4撤单处理中 5撤单中) symbol: btc_usd ltc_usd eth_usd etc_usd bch_usd type: 订单类型 1:开多 2:开空 3:平多 4: 平空 unit_amount:合约面值 lever_rate: 杠杆倍数 value:10\20 默认10 }] result:... } """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'status':status, 'order_id':order_id, 'current_page':current_page, 'page_length':page_length } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() res = OKCoinBase.RESOURCES_URL['order_info'].format('future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return ret['orders'] else: return None
def trade(self, symbol, price, amount, trade_type, match_price): """return: order_id : 订单ID result : true代表成功返回 """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'price': price, 'amount': amount, 'type': trade_type, 'match_price': match_price } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() params['lever_rate'] = 10 res = OKCoinBase.RESOURCES_URL['trade'].format('future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return True ##ret['order_id'] else: return False
def trade(self, symbol, price, amount, trade_type, match_price): """return: order_id : 订单ID result : true代表成功返回 """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'price': price, 'amount': amount, 'type': trade_type, 'match_price': match_price } if cfg.is_future(): params['contract_type'] = cfg.get_future_contract_type() params['lever_rate'] = 10 res = OKCoinBase.RESOURCES_URL['trade'].format( 'future_' if cfg.is_future() else '') ret = self._signed_request(params, res) if ret['result'] == True: return True ##ret['order_id'] else: return False
def future_position(self, symbol): """return: { force_liqu_price:预估爆仓价 holding:[{ buy_amount(double):多仓数量 buy_available:多仓可平仓数量 buy_price_avg(double):开仓平均价 buy_price_cost(double):结算基准价 buy_profit_real(double):多仓已实现盈余 contract_id(long):合约id create_date(long):创建日期 lever_rate:杠杆倍数 sell_amount(double):空仓数量 sell_available:空仓可平仓数量 sell_price_avg(double):开仓平均价 sell_price_cost(double):结算基准价 sell_profit_real(double):空仓已实现盈余 symbol:btc_usd ltc_usd eth_usd etc_usd bch_usd contract_type:合约类型 }] result:... } or 4fix return: { holding:[{ buy_amount:多仓数量 buy_available:多仓可平仓数量 buy_bond:多仓保证金 buy_flatprice:多仓强平价格 buy_profit_lossratio:多仓盈亏比 buy_price_avg:开仓平均价 buy_price_cost:结算基准价 buy_profit_real:多仓已实现盈余 contract_id:合约id contract_type:合约类型 create_date:创建日期 sell_amount:空仓数量 sell_available:空仓可平仓数量 sell_bond:空仓保证金 sell_flatprice:空仓强平价格 sell_profit_lossratio:空仓盈亏比 sell_price_avg:开仓平均价 sell_price_cost:结算基准价 sell_profit_real:空仓已实现盈余 symbol:btc_usd ltc_usd eth_usd etc_usd bch_usd lever_rate: 杠杆倍数 }] result:... } """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'contract_type':cfg.get_future_contract_type() } res = OKCoinBase.RESOURCES_URL['position' if cfg.is_future_mode_all() else 'position_4fix'] ret = self._signed_request(params, res) if ret['result'] == True: return ret['holding'][0] else: log.err("future_position ret:%s"%ret) return None
def future_position(self, symbol): """return: { force_liqu_price:预估爆仓价 holding:[{ buy_amount(double):多仓数量 buy_available:多仓可平仓数量 buy_price_avg(double):开仓平均价 buy_price_cost(double):结算基准价 buy_profit_real(double):多仓已实现盈余 contract_id(long):合约id create_date(long):创建日期 lever_rate:杠杆倍数 sell_amount(double):空仓数量 sell_available:空仓可平仓数量 sell_price_avg(double):开仓平均价 sell_price_cost(double):结算基准价 sell_profit_real(double):空仓已实现盈余 symbol:btc_usd ltc_usd eth_usd etc_usd bch_usd contract_type:合约类型 }] result:... } or 4fix return: { holding:[{ buy_amount:多仓数量 buy_available:多仓可平仓数量 buy_bond:多仓保证金 buy_flatprice:多仓强平价格 buy_profit_lossratio:多仓盈亏比 buy_price_avg:开仓平均价 buy_price_cost:结算基准价 buy_profit_real:多仓已实现盈余 contract_id:合约id contract_type:合约类型 create_date:创建日期 sell_amount:空仓数量 sell_available:空仓可平仓数量 sell_bond:空仓保证金 sell_flatprice:空仓强平价格 sell_profit_lossratio:空仓盈亏比 sell_price_avg:开仓平均价 sell_price_cost:结算基准价 sell_profit_real:空仓已实现盈余 symbol:btc_usd ltc_usd eth_usd etc_usd bch_usd lever_rate: 杠杆倍数 }] result:... } """ params = { 'api_key': cfg.get_id(), 'symbol': symbol, 'contract_type': cfg.get_future_contract_type() } res = OKCoinBase.RESOURCES_URL['position' if cfg.is_future_mode_all( ) else 'position_4fix'] ret = self._signed_request(params, res) if ret['result'] == True: return ret['holding'][0] else: log.err("future_position ret:%s" % ret) return None