def on_account(self, d): """""" account = AccountData(accountid=d["currency"], balance=float(d["balance"]), frozen=float(d["hold"]), gateway_name=self.gateway_name) self.gateway.on_account(copy(account))
def on_query_account(self, data, request): """""" for account_data in data: account = AccountData(accountid=account_data["currency"], balance=float(account_data["balance"]), frozen=float(account_data["hold"]), gateway_name=self.gateway_name) self.gateway.on_account(account) self.gateway.write_log("账户资金查询成功")
def on_account(self, d): """""" for key in d: account_data = d[key] account = AccountData(accountid=key, balance=float(account_data["equity"]), frozen=float(d.get("margin_for_unfilled", 0)), gateway_name=self.gateway_name) self.gateway.on_account(account)
def _parse_account_info(info, gateway_name): """ parse single 'info' record inside account reply to AccountData. """ account = AccountData( accountid=info['instrument_id'].upper(), balance=float(info["equity"]), frozen=float(info["margin_frozen"]), gateway_name=gateway_name, ) return account
def on_query_account(self, data, request): """""" for currency, d in data["info"].items(): account = AccountData( accountid=currency.upper(), balance=float(d["equity"]), frozen=float(d.get("margin_for_unfilled", 0)), gateway_name=self.gateway_name, ) self.gateway.on_account(account) self.gateway.write_log("账户资金查询成功")
def on_account(self, packet): """""" # print('gateway on_account') # print(packet) for d in packet["B"]: account = AccountData(accountid=d["a"], balance=float(d["wb"]), frozen=float(d["wb"]) - float(d["cw"]), gateway_name=self.gateway_name) if account.balance: self.gateway.on_account(account)
def on_account(self, packet): """""" # print('margin trader websocket on_account*'*10) # print(packet) for d in packet["B"]: account = AccountData(accountid=d["a"], balance=float(d["f"]) + float(d["l"]), frozen=float(d["l"]), gateway_name=self.gateway_name) if account.balance: self.gateway.on_account(account)
def on_query_account(self, data, request): """""" for account_data in data["balances"]: account = AccountData(accountid=account_data["asset"], balance=float(account_data["free"]) + float(account_data["locked"]), frozen=float(account_data["locked"]), gateway_name=self.gateway_name) if account.balance: self.gateway.on_account(account) self.gateway.write_log("<现货>账户资金查询成功")
def on_query_account(self, data, request): """""" futures_balance = 0 for account_data in data["assets"]: account = AccountData(accountid=account_data["asset"], balance=float(account_data["marginBalance"]), frozen=float(account_data["initialMargin"]) + float(account_data["maintMargin"]), gateway_name=self.gateway_name) if account.balance: self.gateway.on_account(account) futures_balance += account.balance self.gateway.write_log(f"FUTURES账户资金查询成功: {futures_balance}")
def on_query_account(self, data, request): """""" if self.check_error(data, "查询账户"): return for d in data["data"]: account = AccountData( accountid=d["symbol"], balance=d["margin_balance"], frozen=d["margin_frozen"], gateway_name=self.gateway_name, ) self.gateway.on_account(account)
def on_query_account_balance(self, data, request): """""" if self.check_error(data, "查询账户资金"): return buf = {} for d in data["data"]["list"]: currency = d["currency"] currency_data = buf.setdefault(currency, {}) currency_data[d["type"]] = float(d["balance"]) for currency, currency_data in buf.items(): account = AccountData( accountid=currency, balance=currency_data["trade"] + currency_data["frozen"], frozen=currency_data["frozen"], gateway_name=self.gateway_name, ) if account.balance: self.gateway.on_account(account)