Skip to content

Commit

Permalink
Fix sell (issue #104) (#107)
Browse files Browse the repository at this point in the history
* updated sells

* Updated fixtures
  • Loading branch information
stabacco authored Apr 6, 2021
1 parent 848eb07 commit 8b8e741
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 4,263 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ To perform multiple requests at once you can use an `asyncio.gather` operation t
import asyncio
import stake

async def example_stop_sell():
async def example_stop_sell(symbol='TSLA'):
"""THis example will add a stop sell request for one of your equities"""
async with stake.StakeClient() as stake_session:
my_equities = await stake_session.equities.list()
symbol = "TSLA" # mispelt on purpose so that no trade actually happens, should be TSLA.
tsla_equity = [equity for equity in my_equities.equity_positions if equity.symbol == symbol][0]
stop_price = round(tsla_equity.market_price - 0.025 * tsla_equity.market_price)
stop_sell_request = stake.StopSellRequest(symbol=tsla_equity.symbol,
Expand All @@ -167,7 +166,7 @@ async def example_stop_sell():
quantity=tsla_equity.available_for_trading_qty)
return await stake_session.trades.sell(request=stop_sell_request)

asyncio.run(example_stop_sell())
asyncio.run(example_stop_sell('MSFT'))
~~~

## Contributors
Expand Down
7 changes: 4 additions & 3 deletions stake/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ async def _trade(
Raises:
RuntimeError
"""
product = await self._client.products.get(request.symbol)
assert product
request_dict = request.dict(by_alias=True)
product = await self._client.products.get(request_dict.pop("symbol"))
assert product

request_dict["orderType"] = request_dict["orderType"].value
request_dict["userId"] = str(self._client.user.id)
request_dict["itemId"] = str(product.id)
Expand Down Expand Up @@ -220,7 +221,7 @@ async def _verify_successful_trade(self, trade: TradeResponse) -> None:
)

# wait for the transaction to be available
for transaction in transactions:
for transaction in transactions["transactions"]:
if transaction["orderId"] == trade.dw_order_id:
if re.search(failed_transaction_regex, transaction["updatedReason"]):
raise RuntimeError(
Expand Down
Loading

0 comments on commit 8b8e741

Please sign in to comment.