# Robokami Client Python SDK (robokami-py)
Robokami Client is the client to connect to Robokami IDM Server. Although it is not necessary to use this package to connect to RK-Server, it is recommended to use this package to as an initiation to Robokami IDM commands and structure.
_Note: Robokami Client is in alpha phase, so there will be breaking changes very soon._
+ For more detailed documentation, see [Wiki](https://github.com/Tideseed/robokami-py/wiki).
+ For bugs, enhancements and other issues see [Issues](https://github.com/Tideseed/robokami-py/issues)
+ See [Discussions](https://github.com/Tideseed/robokami-py/discussions) to add feedback
## Installation
First download this repository or directly install it [pip](https://pypi.org).
```bash
pip install robokami-py
```
Alternatively you can choose to install from GitHub
```bash
pip install git+https://github.com/Tideseed/robokami-py.git
```
## Authentication
> **Warning**
> During the open beta of Robokami, it is recommended to use only test CAS (EKYS) accounts.
Prepare a JSON file in the following format. Your user should have IDM access privileges for both test server (`test-ekys`, `giptest`) and live server. (If you just want to do testing with live data you only need test user IDM access privileges.)
```json
{
"trade": {
"v2": false,
"test_server": true,
"username": "USERNAME",
"password": "PASSWORD"
},
"stream": {
"v2": false,
"test_server": true,
"stream_anonymous": false
},
"real_stream_test_trade": true
}
```
```python
import json
with open("credfile.json", "r") as f:
creds = json.load(f)
```
Alternatively, you can directly create the dictionary in Python.
```python
creds = {
"trade": {
"v2": False,
"test_server": True,
"username": "USERNAME",
"password": "PASSWORD"
},
"stream": {
"v2": False,
"test_server": True,
"stream_anonymous": False
},
"real_stream_test_trade": True
}
```
+ `v2`: Placeholder for IDM v2. Currently not active.
+ `test_server`: `true` for test server, `false` for live server.
+ `username`: Your EPIAS username.
+ `password`: Your EPIAS password.
+ `stream_anonymous`: `true` for anonymous stream, `false` for authenticated stream. The difference is you get to see private events (e.g. your own orders) in authenticated stream.
+ `real_stream_test_trade`: If `true` you will get streaming data from the live server but your orders will be executed in the test server and private events will be streamed from the test server. Although not perfect, this is the recommended setting for testing your algorithms.
## RKClient
Suppose your file is named `credfile.json`. You can load it and call the client by
```python
from robokami.main import RKClient
rkc = RKClient(creds=creds, initiate_stream=True)
```
## Streaming Data
Stream data uses SSE (Server-Sent Events) protocol. You can simply access the stream by
```python
for event in rkc.stream_client.events():
e_d = event.__dict__
print(e_d)
```
## Trading
### Orders
You can place orders and update orders. Suppose you are going to send a new order for PH23052010 (i.e, hourly contract for 2023-05-20 for 10:00-11:00)
```python
order_d = {
"c": "PH23070112",
"position": "bid",
"price": 100,
"lots": 1,
"order_status": "active",
"order_note": "RK test order"
}
```
+ `c`: Name of the contract. Hourly contracts are in PHyyMMDDHH format. Block contracts are in PByyMMDDHH-XX format where XX is the number of hours.
+ `position`: `bid` for buy, `ask` for sell.
+ `price`: Price of the order.
+ `lots`: Number of lots.
+ `order_status`: `active` for active orders, `inactive` for inactive orders.
+ `order_note`: order_note for the order.
Then simply place the order using `rkc`.
```python
res = rkc.place_order(order_d)
```
If the result is successful, you can obtain its order id.
```python
if res["status"] == "success":
order_id = res["order_id"]
```
You can also update the order by using the order id and changing `order_d`.
```python
my_order["price"] = 101
res = rkc.update_order(order_id, my_order)
```
### Other Trade Commands
`place_order` and `update_order` are just wrappers for `trade` command. You can use `trade` command directly to place orders, update orders, cancel orders, and get order status.
```python
rkc.trade_command(command, d)
```
where `command` is a command phrase (e.g. `"place_order"`, `"update_order"`) and `d` is the dictionary of parameters required by the command.
+ `limit_details`: With this command you can get the limit details (e.g. min/max price, lots etc.) of your account.
+ `net_positions`: Get your net position with this command. You need to specify the contract type `python {"contract_type":"hourly"}` or `python {"contract_type":"block"}` in the parameter dictionary.
+ `orders_by_id`: You can get order details by order ids. You can add a list `python {"order_ids": ["order_id1", "order_id2"]}` to the parameter dictionary.
+ `contract_details`: You can get details about contracts. (p.s. not very useful)
+ `order_detail`: Similar to `orders_by_id` but with more detail.
+ `order_book`: Get the order book for hourly and block offers.
+ `open_contracts`: Returns the list of open contracts.
+ `organization_orders`: Returns the list of orders belonging to the organization. You need to specify `contract_type` (i.e. "hourly", "block", or "both"). You can filter by time using `after_dt` parameter and order status by using `order_status` parameter (values are "active","cancelled","passive","matched", and "partially_matched").
+ `saved_order_notes`: Returns saved order notes.
+ `matched_orders`: Returns matched orders. You need to specify `start_date` and `end_date` parameters.
+ `make_active_orders_passive`: Make all active orders passive.
+ `make_passive_orders_active`: Make all passive orders active.
Raw data
{
"_id": null,
"home_page": "https://github.com/Tideseed/robokami-py",
"name": "robokami-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Robokami",
"author_email": "",
"download_url": "",
"platform": null,
"description": "# Robokami Client Python SDK (robokami-py)\n\nRobokami Client is the client to connect to Robokami IDM Server. Although it is not necessary to use this package to connect to RK-Server, it is recommended to use this package to as an initiation to Robokami IDM commands and structure.\n\n_Note: Robokami Client is in alpha phase, so there will be breaking changes very soon._\n\n+ For more detailed documentation, see [Wiki](https://github.com/Tideseed/robokami-py/wiki). \n+ For bugs, enhancements and other issues see [Issues](https://github.com/Tideseed/robokami-py/issues)\n+ See [Discussions](https://github.com/Tideseed/robokami-py/discussions) to add feedback\n\n## Installation\n\nFirst download this repository or directly install it [pip](https://pypi.org).\n\n```bash\npip install robokami-py\n```\n\nAlternatively you can choose to install from GitHub\n\n```bash\npip install git+https://github.com/Tideseed/robokami-py.git\n```\n\n## Authentication\n\n> **Warning**\n> During the open beta of Robokami, it is recommended to use only test CAS (EKYS) accounts.\n\nPrepare a JSON file in the following format. Your user should have IDM access privileges for both test server (`test-ekys`, `giptest`) and live server. (If you just want to do testing with live data you only need test user IDM access privileges.)\n\n```json\n{\n \"trade\": {\n \"v2\": false,\n \"test_server\": true,\n \"username\": \"USERNAME\",\n \"password\": \"PASSWORD\"\n },\n \"stream\": {\n \"v2\": false,\n \"test_server\": true,\n \"stream_anonymous\": false\n },\n \"real_stream_test_trade\": true\n}\n```\n\n```python\nimport json \nwith open(\"credfile.json\", \"r\") as f:\n creds = json.load(f)\n```\n\nAlternatively, you can directly create the dictionary in Python.\n\n```python\ncreds = {\n \"trade\": {\n \"v2\": False,\n \"test_server\": True,\n \"username\": \"USERNAME\",\n \"password\": \"PASSWORD\"\n },\n \"stream\": {\n \"v2\": False,\n \"test_server\": True,\n \"stream_anonymous\": False\n },\n \"real_stream_test_trade\": True\n}\n```\n\n+ `v2`: Placeholder for IDM v2. Currently not active.\n+ `test_server`: `true` for test server, `false` for live server.\n+ `username`: Your EPIAS username.\n+ `password`: Your EPIAS password.\n+ `stream_anonymous`: `true` for anonymous stream, `false` for authenticated stream. The difference is you get to see private events (e.g. your own orders) in authenticated stream.\n+ `real_stream_test_trade`: If `true` you will get streaming data from the live server but your orders will be executed in the test server and private events will be streamed from the test server. Although not perfect, this is the recommended setting for testing your algorithms.\n\n\n## RKClient\n\nSuppose your file is named `credfile.json`. You can load it and call the client by\n\n```python\nfrom robokami.main import RKClient\n\nrkc = RKClient(creds=creds, initiate_stream=True)\n```\n\n## Streaming Data\n\nStream data uses SSE (Server-Sent Events) protocol. You can simply access the stream by\n\n```python\nfor event in rkc.stream_client.events():\n e_d = event.__dict__\n print(e_d)\n```\n\n## Trading\n\n### Orders\n\nYou can place orders and update orders. Suppose you are going to send a new order for PH23052010 (i.e, hourly contract for 2023-05-20 for 10:00-11:00)\n\n```python\norder_d = {\n \"c\": \"PH23070112\",\n \"position\": \"bid\",\n \"price\": 100,\n \"lots\": 1,\n \"order_status\": \"active\",\n \"order_note\": \"RK test order\"\n}\n```\n\n+ `c`: Name of the contract. Hourly contracts are in PHyyMMDDHH format. Block contracts are in PByyMMDDHH-XX format where XX is the number of hours.\n+ `position`: `bid` for buy, `ask` for sell.\n+ `price`: Price of the order.\n+ `lots`: Number of lots.\n+ `order_status`: `active` for active orders, `inactive` for inactive orders.\n+ `order_note`: order_note for the order.\n\n\nThen simply place the order using `rkc`.\n\n```python\nres = rkc.place_order(order_d)\n```\n\nIf the result is successful, you can obtain its order id.\n\n```python\nif res[\"status\"] == \"success\":\n order_id = res[\"order_id\"]\n```\n\nYou can also update the order by using the order id and changing `order_d`.\n\n```python\nmy_order[\"price\"] = 101\nres = rkc.update_order(order_id, my_order)\n```\n\n### Other Trade Commands\n\n`place_order` and `update_order` are just wrappers for `trade` command. You can use `trade` command directly to place orders, update orders, cancel orders, and get order status.\n\n```python\nrkc.trade_command(command, d)\n```\n\nwhere `command` is a command phrase (e.g. `\"place_order\"`, `\"update_order\"`) and `d` is the dictionary of parameters required by the command.\n\n+ `limit_details`: With this command you can get the limit details (e.g. min/max price, lots etc.) of your account.\n+ `net_positions`: Get your net position with this command. You need to specify the contract type `python {\"contract_type\":\"hourly\"}` or `python {\"contract_type\":\"block\"}` in the parameter dictionary.\n+ `orders_by_id`: You can get order details by order ids. You can add a list `python {\"order_ids\": [\"order_id1\", \"order_id2\"]}` to the parameter dictionary.\n+ `contract_details`: You can get details about contracts. (p.s. not very useful)\n+ `order_detail`: Similar to `orders_by_id` but with more detail.\n+ `order_book`: Get the order book for hourly and block offers. \n+ `open_contracts`: Returns the list of open contracts.\n+ `organization_orders`: Returns the list of orders belonging to the organization. You need to specify `contract_type` (i.e. \"hourly\", \"block\", or \"both\"). You can filter by time using `after_dt` parameter and order status by using `order_status` parameter (values are \"active\",\"cancelled\",\"passive\",\"matched\", and \"partially_matched\").\n+ `saved_order_notes`: Returns saved order notes.\n+ `matched_orders`: Returns matched orders. You need to specify `start_date` and `end_date` parameters.\n+ `make_active_orders_passive`: Make all active orders passive.\n+ `make_passive_orders_active`: Make all passive orders active.\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Robokami Client Python SDK",
"version": "0.21",
"project_urls": {
"Homepage": "https://github.com/Tideseed/robokami-py"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b44295f7c4790a49787dbf117c4b5601a9f682252c66309e673151c4fc25f21",
"md5": "b17e80c934c1f64fe2768ffd4c74b238",
"sha256": "80a17eebbd989cc744b471288a3f153f4e3f9612e06153ca2f53351390935d4d"
},
"downloads": -1,
"filename": "robokami_py-0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b17e80c934c1f64fe2768ffd4c74b238",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6200,
"upload_time": "2023-10-12T13:24:26",
"upload_time_iso_8601": "2023-10-12T13:24:26.827634Z",
"url": "https://files.pythonhosted.org/packages/6b/44/295f7c4790a49787dbf117c4b5601a9f682252c66309e673151c4fc25f21/robokami_py-0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-12 13:24:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Tideseed",
"github_project": "robokami-py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "sseclient_py",
"specs": [
[
"==",
"1.7.2"
]
]
}
],
"lcname": "robokami-py"
}