def set_account(self, username, password): self._username = username self._password = password self._account = FDTAccount(self._username, self._password)
class FDTAccountManager(AccountManager): def __init__(self, parent=None): super().__init__(parent=parent) self._username = self.config.account self._password = self.config.password if self._username is not None and self._password is not None: self._account = FDTAccount(self._username, self._password) def set_account(self, username, password): self._username = username self._password = password self._account = FDTAccount(self._username, self._password) @property def fx_account(self): accounts = [] retry_time = 0 while not accounts and retry_time < 3: accounts = self._account.account_status()["accounts"] retry_time += 1 for account in accounts: if 'FX' in account['id']: return account raise RuntimeError("回去账户信息失败") @property def capital_base(self): self._capital_base = self.fx_account['cashDeposited'] return self._capital_base @property def capital_cash(self): self._capital_cash = self.fx_account['cash'] return self._capital_cash @property def capital_available(self): self._capital_available = self.fx_account['cashAvailable'] return self._capital_available @property def capital_margin(self): self._capital_margin = self.fx_account['marginHeld'] return self._capital_margin @property def capital_net(self): fx_account = self.fx_account self._capital_net = fx_account['cash'] + fx_account['urPnL'] return self._capital_net def initialize(self): pass def login(self): return self._account.login() def send_order_to_broker(self, order): res = {} if order.type == ORDER_TYPE_BUY: res = self._account.market_order('Buy', int(order.volume_initial * 100000), order.symbol) elif order.type == ORDER_TYPE_SELL: res = self._account.market_order('Sell', int(order.volume_initial * 100000), order.symbol) if not res.get('ok', False): return -1 else: return res.get('orderId') def order_status(self): return self._account.order_status() def profit_record(self, *args): time_ = time.time() return super().profit_record(time_) def position_status(self, symbol=None): res = self._account.open_positions() if res['ok']: positions = res['openPositions'] if symbol is None: return positions else: for position in positions: if position['symbol'] == symbol: return position return None else: return None
def __init__(self, parent=None): super().__init__(parent=parent) self._username = self.config.account self._password = self.config.password if self._username is not None and self._password is not None: self._account = FDTAccount(self._username, self._password)
def __init__(self, *args, **kwargs): self._username = kwargs.pop('account', None) self._password = kwargs.pop('password', None) if self._username is not None and self._password is not None: self._account = FDTAccount(self._username, self._password) super().__init__(*args, **kwargs)
class FDTAccountManager(AccountManager): def __init__(self, *args, **kwargs): self._username = kwargs.pop('account', None) self._password = kwargs.pop('password', None) if self._username is not None and self._password is not None: self._account = FDTAccount(self._username, self._password) super().__init__(*args, **kwargs) def set_account(self, username, password): self._username = username self._password = password @property def fx_account(self): for account in self._account.info['accounts']: if 'FX' in account['id']: return account @property @with_login def capital_base(self): self._capital_base = self.fx_account['cashDeposited'] return self._capital_base @capital_base.setter def capital_base(self, capital_base): pass @property @with_login def capital_cash(self): self._capital_cash = self.fx_account['cash'] return self._capital_cash @property @with_login def capital_available(self): self._capital_available = self.fx_account['cashAvailable'] return self._capital_available @property @with_login def capital_margin(self): self._capital_margin = self.fx_account['marginHeld'] return self._capital_margin @property @with_login def capital_net(self): fx_account = self.fx_account self._capital_net = fx_account['cash'] + fx_account['urPnL'] return self._capital_net def login(self): return self._account.login() def send_order_to_broker(self, order): res = {} if order.type == ORDER_TYPE_BUY: res = self._account.market_order('Buy', int(order.volume_initial * 100000), order.symbol) elif order.type == ORDER_TYPE_SELL: res = self._account.market_order('Sell', int(order.volume_initial * 100000), order.symbol) if not res.get('ok', False): return -1 else: return res.get('orderId') def order_status(self): return self._account.order_status() def update_cash(self, *args, **kwargs): self.capital_cash @with_login def profit_record(self): time = parse(self._account.info['user']['lastLogin']).timestamp() return super().profit_record(time) def position_status(self, symbol=None): res = self._account.open_positions() if res['ok']: positions = res['openPositions'] if symbol is None: return positions else: for position in positions: if position['symbol'] == symbol: return position return None else: return None
class FDTAccountManager(AccountManager): def __init__(self, parent=None): super().__init__(parent=parent) self._username = self.config.account self._password = self.config.password if self._username is not None and self._password is not None: self._account = FDTAccount(self._username, self._password) def set_account(self, username, password): self._username = username self._password = password self._account = FDTAccount(self._username, self._password) @property def fx_account(self): accounts = [] retry_time = 0 while not accounts and retry_time < 3: accounts = self._account.account_status()["accounts"] retry_time += 1 for account in accounts: if 'FX' in account['id']: return account raise RuntimeError("回去账户信息失败") @property def capital_base(self): self._capital_base = self.fx_account['cashDeposited'] return self._capital_base @property def capital_cash(self): self._capital_cash = self.fx_account['cash'] return self._capital_cash @property def capital_available(self): self._capital_available = self.fx_account['cashAvailable'] return self._capital_available @property def capital_margin(self): self._capital_margin = self.fx_account['marginHeld'] return self._capital_margin @property def capital_net(self): fx_account = self.fx_account self._capital_net = fx_account['cash'] + fx_account['urPnL'] return self._capital_net def initialize(self): pass def login(self): return self._account.login() def send_order_to_broker(self, order): res = {} if order.type == ORDER_TYPE_BUY: res = self._account.market_order( 'Buy', int(order.volume_initial * 100000), order.symbol) elif order.type == ORDER_TYPE_SELL: res = self._account.market_order( 'Sell', int(order.volume_initial * 100000), order.symbol) if not res.get('ok', False): return -1 else: return res.get('orderId') def order_status(self): return self._account.order_status() def profit_record(self, *args): time_ = time.time() return super().profit_record(time_) def position_status(self, symbol=None): res = self._account.open_positions() if res['ok']: positions = res['openPositions'] if symbol is None: return positions else: for position in positions: if position['symbol'] == symbol: return position return None else: return None