Package: robokami-py
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, seeWiki.For bugs, enhancements and other issues seeIssuesSeeDiscussionsto add feedbackInstallationFirst download this repository or directly install itpip.pipinstallrobokami-pyAlternatively you can choose to install from GitHubpipinstallgit+https://github.com/Tideseed/robokami-py.gitAuthenticationWarningDuring 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.){"trade":{"v2":false,"test_server":true,"username":"USERNAME","password":"PASSWORD"},"stream":{"v2":false,"test_server":true,"stream_anonymous":false},"real_stream_test_trade":true}importjsonwithopen("credfile.json","r")asf:creds=json.load(f)Alternatively, you can directly create the dictionary in 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:truefor test server,falsefor live server.username: Your EPIAS username.password: Your EPIAS password.stream_anonymous:truefor anonymous stream,falsefor authenticated stream. The difference is you get to see private events (e.g. your own orders) in authenticated stream.real_stream_test_trade: Iftrueyou 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.RKClientSuppose your file is namedcredfile.json. You can load it and call the client byfromrobokami.mainimportRKClientrkc=RKClient(creds=creds,initiate_stream=True)Streaming DataStream data uses SSE (Server-Sent Events) protocol. You can simply access the stream byforeventinrkc.stream_client.events():e_d=event.__dict__print(e_d)TradingOrdersYou 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)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:bidfor buy,askfor sell.price: Price of the order.lots: Number of lots.order_status:activefor active orders,inactivefor inactive orders.order_note: order_note for the order.Then simply place the order usingrkc.res=rkc.place_order(order_d)If the result is successful, you can obtain its order id.ifres["status"]=="success":order_id=res["order_id"]You can also update the order by using the order id and changingorder_d.my_order["price"]=101res=rkc.update_order(order_id,my_order)Other Trade Commandsplace_orderandupdate_orderare just wrappers fortradecommand. You can usetradecommand directly to place orders, update orders, cancel orders, and get order status.rkc.trade_command(command,d)wherecommandis a command phrase (e.g."place_order","update_order") anddis 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 typepython {"contract_type":"hourly"}orpython {"contract_type":"block"}in the parameter dictionary.orders_by_id: You can get order details by order ids. You can add a listpython {"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 toorders_by_idbut 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 specifycontract_type(i.e. "hourly", "block", or "both"). You can filter by time usingafter_dtparameter and order status by usingorder_statusparameter (values are "active","cancelled","passive","matched", and "partially_matched").saved_order_notes: Returns saved order notes.matched_orders: Returns matched orders. You need to specifystart_dateandend_dateparameters.make_active_orders_passive: Make all active orders passive.make_passive_orders_active: Make all passive orders active.