{"id":22938193,"url":"https://github.com/hootnot/oanda-trading-environment","last_synced_at":"2025-08-12T18:32:36.761Z","repository":{"id":57447513,"uuid":"43329156","full_name":"hootnot/oanda-trading-environment","owner":"hootnot","description":"Base Environment to create trading applications using publisher/subscribe pattern. The OANDAd daemon parses the tick stream of configured instruments into streaming candles of specified timeframes. The tickstream is saved. Different configurations apply","archived":false,"fork":false,"pushed_at":"2024-01-29T11:32:11.000Z","size":75,"stargazers_count":47,"open_issues_count":2,"forks_count":28,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-08-09T14:34:10.574Z","etag":null,"topics":["finance","forex","trading","trading-bot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hootnot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-28T21:55:47.000Z","updated_at":"2024-01-29T13:48:18.000Z","dependencies_parsed_at":"2022-09-15T22:00:24.748Z","dependency_job_id":null,"html_url":"https://github.com/hootnot/oanda-trading-environment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootnot%2Foanda-trading-environment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootnot%2Foanda-trading-environment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootnot%2Foanda-trading-environment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hootnot%2Foanda-trading-environment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hootnot","download_url":"https://codeload.github.com/hootnot/oanda-trading-environment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229699815,"owners_count":18109856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finance","forex","trading","trading-bot"],"created_at":"2024-12-14T12:16:26.138Z","updated_at":"2024-12-14T12:16:26.665Z","avatar_url":"https://github.com/hootnot.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"OANDA Trading Environment\n===================================\n\n[![PyPI version](https://badge.fury.io/py/oanda-trading-environment.svg)](http://badge.fury.io/py/oanda-trading-environment)\n\nThe OANDA Trading Environment is built using the OANDA REST-API by making use of the [https://github.com/oanda/oandapy](https://github.com/oanda/oandapy) API-wrapper.\n\nStreaming Candles\n-----------------\n\nMain part is the **OANDAd** daemon that parses the streaming quotes in \nconfigurable timeframes, by 1 minute, 5 minutes, 15 minutes etc. This makes it\nproduce streaming candles.\n\nAs of version 0.3.0 **OANDAd** detects automatically the use of\nREST-V1 / REST-V20, by the _account\\_id_ string in the _OANDAd.cfg_.\n\n\nCandle data:\n```python\n      {\"data\": {\"instrument\": \"EUR_JPY\",\n                \"granularity\" : \"M1\",\n                \"start\": \"2015-09-02 15:36:00\"\n                \"end\": \"2015-09-02 15:37:00\",\n                \"completed\": True,\n                \"data\": {\"high\": 134.967, \n                         \"open\": 134.962,\n                         \"last\": 134.9565,\n                          \"low\": 134.9475,\n                       \"volume\": 19\n                 },\n               }\n       }\n```\nThe larger timeframes can be requested using the API.\n\nStreaming data can be controlled by the 'fabricate' setting in the 'streamer:' \nconfig section. \n\n* atEndOfTimeFrame - the default mode is to fabricate completed timeframes\n* dancingBear - generates _dancing bear_ records with the 'completed' : False, until the record is completed. At that moment the record gets the status 'completed' : True.\n* dancingBearHighLowExtreme - generate _dancing bear_ records *only* when the high or the low changes\n\nThe _dancingBear_ setting generates as many records as ticks are received. This\ncan be a lot. A compromise is the _dancingBearHighLowExtreme_. In case of extreme\nmarket moves the records will be generated also, but in a less volatile market\nless records will be generated.\n\nActions\n-------\n\nWhen a timeframe is completed it can be handled by one or more plugins.\nPlugins have a configfile based on the name of the plugin-file, but in lowercase.\nThe plugins can be found under _etc/OANDA/plugins_ and the plugin configs under _etc/OANDA/config/plugins_.\n\nPlugins need to be enabled in the config file, see the 'plugins:' section in _etc/OANDA/config/OANDAd.cfg_.\n\nThe environment comes with a few plugins:\n\n### Publish/Subscribe - plugin\n\nThis plugin can be configured to 'publish' the candle using a publisher/subscriber mechanism. This is achieved by using the [0MQ](http://zeromq.org)\nlibrary and the python binding for it: pyzmq\n\nOther trading applications can easily subscribe to receive the candle data. See [here](#zmq_example) for a ZMQ subscription example.\n\nThis plugin is enabled by default.\n\n### Plainfile - plugin\n\nThis plugin can be configured to write candle records to a flatfile in a directory structure. \n\nExample:\n\n     /tmp/oandadb\n     |-- BCO_USD\n     |   |-- M1\n     |   |   `-- cache\n     |   |-- M15\n     |   |   `-- cache\n     |   `-- M5\n     |       `-- cache\n     |-- DE30_EUR\n     |   |-- M1\n     |   |   `-- cache\n     |   |-- M15\n     |   |   `-- cache\n     |   `-- M5\n     |       `-- cache\n     |-- EUR_CHF\n     |   |-- M1\n     |   |   `-- cache\n     |   |-- M15\n     |   |   `-- cache\n     |   `-- M5\n     |       `-- cache\n     |-- EUR_GBP\n     |   |-- M1\n     |   |   `-- cache\n     |   |-- M15\n     |   |   `-- cache\n     |   `-- M5\n     |       `-- cache\n     |-- EUR_JPY\n     |   |-- M1\n     |   |   `-- cache\n     |   |-- M15\n     |   |   `-- cache\n     |   `-- M5\n     |       `-- cache\n     |-- EUR_USD\n         |-- M1\n         |   `-- cache\n         |-- M15\n         |   `-- cache\n         `-- M5\n             `-- cache\n\n\n### MySQL - plugin\n\nThe MySQL plugin can be configured to insert records into a database. This plugin is provided as an example, since it needs details that depend on your\ndatabasemodel.\n\nAuto trading\n-------------\n\n### By using a ZMQ client\n\nThe desired approach is to create stand-alone applications that subscribe for quotes,\nsee, [example](#zmq_example) for a ZMQ subscription example.\n\n### By using plugins\n\nThough it is possible to use the plugin facility to perform auto-trading, the\nway to go is to use ZMQ client and subscribe for quotes. This way you can\ncompletely isolate your trading code from the OANDAd daemon.\n\n\nSecurity\n----------------\n\nThe enviroment makes use of a token that gives access to crucial information.\n\nPlease pay attention to where you install this software. **Never** use this on\na system that is not owned by you. \n\nMake sure to secure your system as much as possible:\n\n* restrict network access\n* make no use of, or limit other network services (NFS, SAMBA, printserver etc.)\n* limit user access, preferable only you\n* use encryption\n* who about physical access ?\n\n\nSpecs and Prerequisites\n------------------------\n\nTo access the OANDA services you will need a token, see [https://developer.oanda.com](https://developer.oanda.com) for details.\n\nInstall\n-------\n\n### Git\n\nInstall by using a virtual environment and git:\n```bash\n      $ cd \u003csomewhere\u003e\n      $ mkdir OANDA\n      $ cd OANDA\n      $ virtualenv venv\n```\n\nOptionally use _--system-site-packages_ to use the standard available packages for the python modules available\non your system: _pyyaml_, _pyzmq_. Check for the packages on the distribution you use.\n\n```bash\n      $ . ./venv/bin/activate\n      $ git clone https://github.com/hootnot/oanda-trading-environment.git\n      $ cd oanda-trading-environment\n      $ python setup.py install\n```\n\nOANDA has not made the oandapy module pip installable.\nA hack to get oandapy installed as a standalone module:\n\n```bash\n      $ pip install git+https://github.com/hootnot/oandapy\n```\n\nThis will install the latest oandapy using the setup.py from the oandapy fork.\n```bash\n      $ pip list | grep oanda\n      oanda-trading-environment (0.0.1)\n      oandapy (0.1)\n```\n\n### pip\n\nInstall from pypi:\n\nusing a virtual environment:\n\n```bash\n      $ cd \u003csomewhere\u003e\n      $ mkdir OANDA\n      $ cd OANDA\n      $ virtualenv [--system-site-packages] venv\n      $ . ./venv/bin/activate\n      $ pip install git+https://github.com/hootnot/oandapy\n      $ pip install --no-binary :all: oanda-trading-environment\n```\n\nusing a system install:\n\n```bash\n      $ sudo pip install oanda-trading-environment\n      $ sudo pip install git+https://github.com/hootnot/oandapy\n```\n\nConfigure the OANDAd.cfg config file and start the daemon.\n\n### Quick start\n\nAfter installing you **need** to configure the environment by editing the\nconfig file _etc/OANDA/config/OANDAd.cfg_. This is a YAML based configfile.\n\nConfigure the **environment**, default set to _practice_ and the **token**. Alter\n the list of instruments you want to follow.\n\nThough accounts can be requested using the API, the environment uses the\n**account** setting primarily to initialize the OANDAd for the streaming quotes.\nTherefore you need to configure the **account_id** also.\n\nThe pubsub plugin publishes by default at localhost, port 5550. These can \nbe altered in the 'pubsub' config: _etc/OANDA/config/plugins/pubsub.cfg_.\n\n#### Controlling OANDAd\n\nOANDAd is built using [daemoncle](https://github.com/jnrbsn/daemonocle). The 'start',\n'status' and 'stop' commands are implemented. The daemon forks itself and the child\nwill process the stream. When there are issues, TIME-OUT for instance, the child will\nexit and a new child will be spawned. \n\n```bash\n      $ OANDAd start \n      Starting OANDAd ... OK\n\n      $ OANDAd status\n      OANDAd -- pid: 51931, status: sleeping, uptime: 0m, %cpu: 0.0, %mem: 1.8\n\n      $ OANDAd stop\n      Stopping OANDAd ... OK\n```\n\nThe daemon will process streaming quotes now and process the timeframes\nas configured. Timeframes are currently based on the midprice of bid/ask.\n\n### Logging\n\nThe ticks received from the stream are written to a logfile:\n\n     streamdata.\u003cdate\u003e\n\nThe daemon itself logs to OANDAd.log\n\nLoglevel and the streamdata logfile extension is configurable. Check the _OANDAd.cfg_ file\nfor details.\n\n\n### \u003ca name=\"zmq_example\"\u003e\u003c/a\u003eZMQ - client\n\n\nThis simple piece of code acts as a subscriber to the daemon. All completed timeframes are written to stdout.\nUsing ZMQ make it easy to program different strategies completely independent from each other. By using 'topics' \nit is possible to subscribe for a certain time granularity like M1, M5 etc. Check the ZMQ for details.\n\n```python\n     import zmq\n\n     context = zmq.Context()\n     socket = context.socket( zmq.SUB)\n     socket.connect(\"tcp://127.0.0.1:5550\")\n     socket.setsockopt(zmq.SUBSCRIBE, \"\")\n\n     socket.setsockopt( zmq.RCVBUF, 1000)\n     while True:\n         msg = socket.recv()\n         print \"GOT: \", msg\n```\n\nThis will show candle data like below, every time a timeframe is completed.\n\n```python\n     GOT:  {\"data\": {\n                     \"instrument\": \"EUR_GBP\",\n                     \"granularity\": \"M1\",\n                     \"start\": \"2015-09-04 17:45:00\",\n                     \"end\": \"2015-09-04 17:46:00\",\n                     \"completed\": True,\n                     \"data\": {\n                              \"high\": 0.734445,\n                              \"open\": 0.734399,\n                              \"last\": 0.73437,\n                              \"low\": 0.734345,\n                              \"volume\": 16\n                             }\n                    }\n           }\n\n     GOT:  {\"data\": {\n                     \"instrument\": \"EUR_JPY\",\n                     \"granularity\": \"M1\",\n                     \"start\": \"2015-09-04 17:45:00\",\n                     \"end\": \"2015-09-04 17:46:00\",\n                     \"completed\": True,\n                     \"data\": {\n                              \"high\": 132.629,\n                              \"open\": 132.619,\n                              \"last\": 132.6185,\n                              \"low\": 132.608,\n                              \"volume\": 15\n                             }\n                    }\n            }\n\n     GOT:  {\"data\": {\n                     \"instrument\": \"SPX500_USD\",\n                     \"granularity\": \"M1\",\n                     \"start\": \"2015-09-04 17:45:00\",\n                     \"end\": \"2015-09-04 17:46:00\",\n                     \"completed\": True,\n                     \"data\": {\n                              \"high\": 1915.35,\n                              \"open\": 1914.75,\n                              \"last\": 1915.25,\n                              \"low\": 1914.75,\n                              \"volume\": 33\n                             }\n                    }\n            }\n```\n\nAbout this software\n-------------------\nThe *oanda-trading-environment* software is a personal project.\nI have no prior or existing relationship with OANDA.\n\nIf you have any questions regarding this software, please take a look at\nthe documentation first.\n\nIf you still have questions/issues you can open an *issue* on Gitub: https://github.com/hootnot/oanda-trading-environment\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhootnot%2Foanda-trading-environment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhootnot%2Foanda-trading-environment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhootnot%2Foanda-trading-environment/lists"}