def order(self, pair, price, amount, side, order_type): try: res = prv.order(pair, price, amount, side, order_type) except Exception as e: if parse_error(e) == '70009': raise MarketOrderLimitError elif parse_error(e) == '20001': raise APIAuthenticicationError else: raise Exception # 約定が完了するまで待つ order_id = res['order_id'] status = self.get_order(pair, order_id)['status'] order_time = datetime.fromtimestamp( float(self.get_order(pair, order_id)['ordered_at']) / 1000) while (status == 'UNFILLED') or (status == 'PARTIALLY_FILLED'): # 5分以上経つとキャンセル dt_delta = (datetime.now() - order_time).total_seconds() if dt_delta > 300: try: self.cancel_order(pair, order_id) logger.debug( 'cancel order {}, side: {}, dt delta: {}'.format( order_id, side, dt_delta)) except CancelFailedError: pass except Exception: raise Exception time.sleep(5) status = self.get_order(pair, order_id)['status'] return self.get_order(pair, order_id)
def cancel_orders(self, pair, order_ids): try: prv.cancel_orders(pair, order_ids) except Exception as e: if parse_error(e) == '20001': raise APIAuthenticicationError elif parse_error(e) == '50010': raise CancelFailedError else: raise Exception
def get_asset(self): try: return float(prv.get_asset()['assets'][0]['onhand_amount']) except Exception as e: if parse_error(e) == '20001': raise APIAuthenticicationError else: raise Exception
def get_order(self, pair, order_id): try: return prv.get_order(pair, order_id) except Exception as e: if parse_error(e) == '20001': raise APIAuthenticicationError else: raise Exception
def get_trade_history(self, pair, order_count): try: return prv.get_trade_history(pair, order_count) except Exception as e: if parse_error(e) == '20001': raise APIAuthenticicationError else: raise Exception
def get_active_orders(self, pair, options=None): try: return prv.get_active_orders(pair, options) except Exception as e: if parse_error(e) == '20001': raise APIAuthenticicationError else: raise Exception