{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Login Shioaji." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Response Code: 0 | Event Code: 0 | Info: host '203.66.91.161:80', IP 203.66.91.161:80 (host 1 of 1) (host connection attempt 1 of 1) (total connection attempt 1 of 1) | Event: Session up\n" ] } ], "source": [ "import shioaji as sj\n", "api = sj.Shioaji()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ca Initial Done.\n" ] }, { "data": { "text/plain": [ "0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "accounts = api.login(\"YOUR_PERSON_ID\", \"YOUR_PASSWORD\")\n", "accounts" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "api.activate_ca(\n", " ca_path=\"/c/your/ca/path/Sinopac.pfx\",\n", " ca_passwd=\"YOUR_CA_PASSWORD\",\n", " person_id=\"Person of this Ca\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Contract Object." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "contract = api.Contracts.Futures.TXF.TXF202004\n", "contract" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Making Order Object.\n", "### Buy" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "order = api.Order(\n", " action=\"Buy\",\n", " price=10200,\n", " quantity=2,\n", " order_type=\"ROD\",\n", " price_type=\"LMT\",\n", " octype=\"Auto\",\n", " account=api.futopt_account\n", " )\n", "order" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Place Order" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "trade = api.place_order(contract, order)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trade" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example For\n", "### Place Order ROD LMT" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import shioaji as sj\n", "\n", "api = sj.Shioaji()\n", "accounts = api.login(\"YOUR_PERSON_ID\", \"YOUR_PASSWORD\", contracts_timeout=10000)\n", "api.activate_ca(\n", " ca_path=\"/c/your/ca/path/Sinopac.pfx\",\n", " ca_passwd=\"YOUR_CA_PASSWORD\",\n", " person_id=\"Person of this Ca\",\n", ")\n", "\n", "contract = api.Contracts.Futures.TXF.TXF202004\n", "order = api.Order(\n", " action=\"Buy\",\n", " price=10200,\n", " quantity=2,\n", " order_type=\"ROD\",\n", " price_type=\"LMT\",\n", " octype=\"Auto\",\n", " account=api.futopt_account\n", " )\n", "trade = api.place_order(contract, order)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trade" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Cancel Order" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "api.update_status(api.futopt_account)\n", "api.cancel_order(trade)\n", "api.update_status(api.futopt_account)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trade" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Update Order" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "api.update_status(api.futopt_account)\n", "api.update_order(trade=trade, price=10200, qty=1)\n", "api.update_status(api.futopt_account)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "trade" ] } ], "metadata": { "file_extension": ".py", "kernelspec": { "display_name": "Python 3.7.0 64-bit ('base': conda)", "language": "python", "name": "python37064bitbaseconda95fb4fb9cd7e40e6997e19823a541114" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" }, "mimetype": "text/x-python", "name": "python", "npconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 }, "nbformat": 4, "nbformat_minor": 4 }