コード例 #1
0
    def on_account(self, data: dict) -> None:
        """"""
        if not data:
            return

        currency = data["currency"]

        change_type = data["changeType"]
        if not change_type:
            balance = float(data["balance"])
            frozen = balance - float(data["available"])
            currency_balance[currency] = balance

        elif "place" in change_type:
            if "available" not in data:
                return
            balance = currency_balance[currency]
            frozen = balance - float(data["available"])
        else:
            frozen = 0.0
            if "balance" in data:
                balance = float(data["balance"])
            else:
                balance = float(data["available"])
            currency_balance[currency] = balance

        account = AccountData(
            accountid=currency,
            balance=balance,
            frozen=frozen,
            gateway_name=self.gateway_name,
        )
        self.gateway.on_account(account)
コード例 #2
0
ファイル: okexo_gateway.py プロジェクト: phybrain/mytrader
 def on_account(self, data: dict) -> None:
     """"""
     account = AccountData(accountid=data["underlying"],
                           balance=float(data["equity"]),
                           frozen=float(data.get("margin_for_unfilled", 0)),
                           gateway_name=self.gateway_name)
     self.gateway.on_account(account)
コード例 #3
0
ファイル: okex_gateway.py プロジェクト: phybrain/mytrader
    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))
コード例 #4
0
ファイル: okex_gateway.py プロジェクト: phybrain/mytrader
    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("账户资金查询成功")
コード例 #5
0
ファイル: binance_gateway.py プロジェクト: phybrain/mytrader
    def on_account(self, 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)
コード例 #6
0
ファイル: okexf_gateway.py プロジェクト: phybrain/mytrader
 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)
コード例 #7
0
ファイル: okexf_gateway.py プロジェクト: phybrain/mytrader
 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("账户资金查询成功")
コード例 #8
0
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
コード例 #9
0
    def on_query_account(self, data: dict, request: Request) -> None:
        """"""
        for asset in data["assets"]:
            account = AccountData(accountid=asset["asset"],
                                  balance=float(asset["walletBalance"]),
                                  frozen=float(asset["maintMargin"]),
                                  gateway_name=self.gateway_name)

            if account.balance:
                self.gateway.on_account(account)

        self.gateway.write_log("账户资金查询成功")
コード例 #10
0
ファイル: okexo_gateway.py プロジェクト: phybrain/mytrader
    def on_query_account(self, data: dict, request: Request) -> None:
        """"""
        equity = float(data["equity"])
        if equity:
            account = AccountData(
                accountid=data["underlying"],
                balance=float(data["equity"]),
                frozen=float(data.get("margin_for_unfilled", 0)),
                gateway_name=self.gateway_name,
            )
            self.gateway.on_account(account)

            self.gateway.write_log(f"{account.accountid}账户资金查询成功")
コード例 #11
0
ファイル: binance_gateway.py プロジェクト: phybrain/mytrader
    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("账户资金查询成功")
コード例 #12
0
ファイル: huobis_gateway.py プロジェクト: phybrain/mytrader
    def on_query_account(self, data: dict, request: Request) -> None:
        """"""
        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)
コード例 #13
0
    def on_query_account(self, data, request):
        """"""
        self.account_id = str(data["user"])

        account = AccountData(
            accountid=self.account_id,
            balance=float(data["total"]),
            frozen=float(data["total"]) - float(data["available"]),
            gateway_name=self.gateway_name,
        )
        self.gateway.on_account(account)

        if not self.symbols:
            self.query_contract()
コード例 #14
0
    def on_account(self, packet: dict) -> None:
        """"""
        for acc_data in packet["a"]["B"]:
            account = AccountData(accountid=acc_data["a"],
                                  balance=float(acc_data["wb"]),
                                  frozen=float(acc_data["wb"]) -
                                  float(acc_data["cw"]),
                                  gateway_name=self.gateway_name)

            if account.balance:
                self.gateway.on_account(account)

        for pos_data in packet["a"]["P"]:
            position = PositionData(
                symbol=pos_data["s"],
                exchange=Exchange.BINANCE,
                direction=Direction.NET,
                volume=int(float(pos_data["pa"])),
                price=float(pos_data["ep"]),
                pnl=float(pos_data["cr"]),
                gateway_name=self.gateway_name,
            )
            self.gateway.on_position(position)