Skip to content

Commit ee90c1f

Browse files
christophersanbornxeroc
authored andcommitted
Add exchange_with_liquidity_pool() method.
1 parent 048318e commit ee90c1f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

bitshares/bitshares.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,3 +1869,36 @@ def delete_liquidity_pool(self, pool, account=None, **kwargs):
18691869
}
18701870
)
18711871
return self.finalizeOp(op, account, "active", **kwargs)
1872+
1873+
1874+
def exchange_with_liquidity_pool(self, pool, amount_to_sell, min_to_receive, account=None, **kwargs):
1875+
"""Exchange assets against a liquidity pool
1876+
1877+
:param str,Asset pool: The liquidity pool to use. Can be the pool id
1878+
as a string, or can be an Asset, asset_id, or symbol of the
1879+
share asset for the pool.
1880+
1881+
:param Amount amount_to_sell:
1882+
:param Amount min_to_receive:
1883+
1884+
"""
1885+
if not account:
1886+
if "default_account" in self.config:
1887+
account = self.config["default_account"]
1888+
if not account:
1889+
raise ValueError("You need to provide an account")
1890+
account = Account(account, blockchain_instance=self)
1891+
1892+
pool_id = self._find_liquidity_pool(pool)
1893+
1894+
op = operations.Liquidity_pool_exchange(
1895+
**{
1896+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1897+
"account": account["id"],
1898+
"pool": pool_id,
1899+
"amount_to_sell": amount_to_sell.json(),
1900+
"min_to_receive": min_to_receive.json(),
1901+
"extensions": [],
1902+
}
1903+
)
1904+
return self.finalizeOp(op, account, "active", **kwargs)

0 commit comments

Comments
 (0)