Skip to content

Commit

Permalink
Add support for editing existing orders (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qluxzz authored Oct 22, 2020
1 parent ef496f5 commit 3c99bd7
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 1 deletion.
39 changes: 39 additions & 0 deletions avanza/avanza.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,45 @@ def place_order(
}
)

def edit_order(
self,
instrument_type: InstrumentType,
order_id: str,
account_id: str,
order_book_id: str,
order_type: OrderType,
price: float,
valid_until: date,
volume: int
):

""" Update an existing order
Returns:
{
messages: List[str],
orderId: str,
requestId: str,
status: str
}
"""

return self.__call(
HttpMethod.PUT,
Route.ORDER_EDIT_PATH.value.format(
instrument_type.value,
order_id
),
{
'accountId': account_id,
'orderbookId': order_book_id,
'orderType': order_type.value,
'price': price,
'validUntil': valid_until.isoformat(),
'volume': volume
}
)

def get_order(
self,
account_id: str,
Expand Down
1 change: 1 addition & 0 deletions avanza/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Route(enum.Enum):
ORDER_DELETE_PATH = '/_api/order?accountId={}&orderId={}'
ORDER_GET_PATH = '/_mobile/order/{}?accountId={}&orderId={}'
ORDER_PLACE_PATH = '/_api/order'
ORDER_EDIT_PATH = '/_api/order/{}/{}'
ORDERBOOK_LIST_PATH = '/_mobile/market/orderbooklist/{}'
ORDERBOOK_PATH = '/_mobile/order/{}?orderbookId={}'
OVERVIEW_PATH = '/_mobile/account/overview'
Expand Down
139 changes: 139 additions & 0 deletions docs/avanza.html
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,45 @@ <h1 class="title">Module <code>avanza.avanza</code></h1>
}
)

def edit_order(
self,
instrument_type: InstrumentType,
order_id: str,
account_id: str,
order_book_id: str,
order_type: OrderType,
price: float,
valid_until: date,
volume: int
):

&#34;&#34;&#34; Update an existing order

Returns:
{
messages: List[str],
orderId: str,
requestId: str,
status: str
}
&#34;&#34;&#34;

return self.__call(
HttpMethod.PUT,
Route.ORDER_EDIT_PATH.value.format(
instrument_type.value,
order_id
),
{
&#39;accountId&#39;: account_id,
&#39;orderbookId&#39;: order_book_id,
&#39;orderType&#39;: order_type.value,
&#39;price&#39;: price,
&#39;validUntil&#39;: valid_until.isoformat(),
&#39;volume&#39;: volume
}
)

def get_order(
self,
account_id: str,
Expand Down Expand Up @@ -3014,6 +3053,45 @@ <h2 class="section-title" id="header-classes">Classes</h2>
}
)

def edit_order(
self,
instrument_type: InstrumentType,
order_id: str,
account_id: str,
order_book_id: str,
order_type: OrderType,
price: float,
valid_until: date,
volume: int
):

&#34;&#34;&#34; Update an existing order

Returns:
{
messages: List[str],
orderId: str,
requestId: str,
status: str
}
&#34;&#34;&#34;

return self.__call(
HttpMethod.PUT,
Route.ORDER_EDIT_PATH.value.format(
instrument_type.value,
order_id
),
{
&#39;accountId&#39;: account_id,
&#39;orderbookId&#39;: order_book_id,
&#39;orderType&#39;: order_type.value,
&#39;price&#39;: price,
&#39;validUntil&#39;: valid_until.isoformat(),
&#39;volume&#39;: volume
}
)

def get_order(
self,
account_id: str,
Expand Down Expand Up @@ -3607,6 +3685,66 @@ <h2 id="returns">Returns</h2>
)</code></pre>
</details>
</dd>
<dt id="avanza.avanza.Avanza.edit_order"><code class="name flex">
<span>def <span class="ident">edit_order</span></span>(<span>self, instrument_type: <a title="avanza.constants.InstrumentType" href="constants.html#avanza.constants.InstrumentType">InstrumentType</a>, order_id: str, account_id: str, order_book_id: str, order_type: <a title="avanza.constants.OrderType" href="constants.html#avanza.constants.OrderType">OrderType</a>, price: float, valid_until: datetime.date, volume: int)</span>
</code></dt>
<dd>
<div class="desc"><p>Update an existing order</p>
<h2 id="returns">Returns</h2>
<dl>
<dt>{</dt>
<dt><code>
messages</code></dt>
<dd>List[str],
orderId: str,
requestId: str,
status: str</dd>
</dl>
<p>}</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def edit_order(
self,
instrument_type: InstrumentType,
order_id: str,
account_id: str,
order_book_id: str,
order_type: OrderType,
price: float,
valid_until: date,
volume: int
):

&#34;&#34;&#34; Update an existing order

Returns:
{
messages: List[str],
orderId: str,
requestId: str,
status: str
}
&#34;&#34;&#34;

return self.__call(
HttpMethod.PUT,
Route.ORDER_EDIT_PATH.value.format(
instrument_type.value,
order_id
),
{
&#39;accountId&#39;: account_id,
&#39;orderbookId&#39;: order_book_id,
&#39;orderType&#39;: order_type.value,
&#39;price&#39;: price,
&#39;validUntil&#39;: valid_until.isoformat(),
&#39;volume&#39;: volume
}
)</code></pre>
</details>
</dd>
<dt id="avanza.avanza.Avanza.get_account_overview"><code class="name flex">
<span>def <span class="ident">get_account_overview</span></span>(<span>self, account_id: str)</span>
</code></dt>
Expand Down Expand Up @@ -6345,6 +6483,7 @@ <h4><code><a title="avanza.avanza.Avanza" href="#avanza.avanza.Avanza">Avanza</a
<li><code><a title="avanza.avanza.Avanza.create_monthly_saving" href="#avanza.avanza.Avanza.create_monthly_saving">create_monthly_saving</a></code></li>
<li><code><a title="avanza.avanza.Avanza.delete_monthly_saving" href="#avanza.avanza.Avanza.delete_monthly_saving">delete_monthly_saving</a></code></li>
<li><code><a title="avanza.avanza.Avanza.delete_order" href="#avanza.avanza.Avanza.delete_order">delete_order</a></code></li>
<li><code><a title="avanza.avanza.Avanza.edit_order" href="#avanza.avanza.Avanza.edit_order">edit_order</a></code></li>
<li><code><a title="avanza.avanza.Avanza.get_account_overview" href="#avanza.avanza.Avanza.get_account_overview">get_account_overview</a></code></li>
<li><code><a title="avanza.avanza.Avanza.get_all_monthly_savings" href="#avanza.avanza.Avanza.get_all_monthly_savings">get_all_monthly_savings</a></code></li>
<li><code><a title="avanza.avanza.Avanza.get_certificate_info" href="#avanza.avanza.Avanza.get_certificate_info">get_certificate_info</a></code></li>
Expand Down
7 changes: 7 additions & 0 deletions docs/constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h1 class="title">Module <code>avanza.constants</code></h1>
ORDER_DELETE_PATH = &#39;/_api/order?accountId={}&amp;orderId={}&#39;
ORDER_GET_PATH = &#39;/_mobile/order/{}?accountId={}&amp;orderId={}&#39;
ORDER_PLACE_PATH = &#39;/_api/order&#39;
ORDER_EDIT_PATH = &#39;/_api/order/{}/{}&#39;
ORDERBOOK_LIST_PATH = &#39;/_mobile/market/orderbooklist/{}&#39;
ORDERBOOK_PATH = &#39;/_mobile/order/{}?orderbookId={}&#39;
OVERVIEW_PATH = &#39;/_mobile/account/overview&#39;
Expand Down Expand Up @@ -413,6 +414,7 @@ <h3>Class variables</h3>
ORDER_DELETE_PATH = &#39;/_api/order?accountId={}&amp;orderId={}&#39;
ORDER_GET_PATH = &#39;/_mobile/order/{}?accountId={}&amp;orderId={}&#39;
ORDER_PLACE_PATH = &#39;/_api/order&#39;
ORDER_EDIT_PATH = &#39;/_api/order/{}/{}&#39;
ORDERBOOK_LIST_PATH = &#39;/_mobile/market/orderbooklist/{}&#39;
ORDERBOOK_PATH = &#39;/_mobile/order/{}?orderbookId={}&#39;
OVERVIEW_PATH = &#39;/_mobile/account/overview&#39;
Expand Down Expand Up @@ -492,6 +494,10 @@ <h3>Class variables</h3>
<dd>
<div class="desc"></div>
</dd>
<dt id="avanza.constants.Route.ORDER_EDIT_PATH"><code class="name">var <span class="ident">ORDER_EDIT_PATH</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="avanza.constants.Route.ORDER_GET_PATH"><code class="name">var <span class="ident">ORDER_GET_PATH</span></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -727,6 +733,7 @@ <h4><code><a title="avanza.constants.Route" href="#avanza.constants.Route">Route
<li><code><a title="avanza.constants.Route.ORDERBOOK_LIST_PATH" href="#avanza.constants.Route.ORDERBOOK_LIST_PATH">ORDERBOOK_LIST_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.ORDERBOOK_PATH" href="#avanza.constants.Route.ORDERBOOK_PATH">ORDERBOOK_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.ORDER_DELETE_PATH" href="#avanza.constants.Route.ORDER_DELETE_PATH">ORDER_DELETE_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.ORDER_EDIT_PATH" href="#avanza.constants.Route.ORDER_EDIT_PATH">ORDER_EDIT_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.ORDER_GET_PATH" href="#avanza.constants.Route.ORDER_GET_PATH">ORDER_GET_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.ORDER_PLACE_PATH" href="#avanza.constants.Route.ORDER_PLACE_PATH">ORDER_PLACE_PATH</a></code></li>
<li><code><a title="avanza.constants.Route.OVERVIEW_PATH" href="#avanza.constants.Route.OVERVIEW_PATH">OVERVIEW_PATH</a></code></li>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = '[email protected]'
AUTHOR = 'André Andersson'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '2.2.1'
VERSION = '2.3.0'

REQUIRED = [
'requests>=2',
Expand Down

0 comments on commit 3c99bd7

Please sign in to comment.