Skip to main content
Copyright (c) 2015 Rafael da Silva Rocha

Build Windows Build Coverage Status Code Climate Python Versions Live Demo

What problem does it solve?

trade calculates the results of investments. You inform a series of assets, a series of operations with those assets, and trade tells the money you invested in each asset, the profits from buying and selling each asset, and more. It is focused in, but not limited to, stock exchange operations.

trade is still in early development, but you can already try it live!

Installation

The trade module can be installed with pip:

$ pip install trade

To check if everything went OK, open the Python console and import the module:

import trade
asset = trade.Asset(symbol='AMZN')

Quickstart

A basic example of the trade module in action:

import trade
interface = trade.TradeJSON()

json_input = '''{
    "subjects": {
        "GOOG": {
            "type": "Asset",
            "name": "Google Inc",
            "expiration_date": ""
        },
        "AAPL": {
            "type": "Asset",
            "name": "Apple, Inc.",
            "expiration_date": ""
        }
    },
    "occurrences": [
        {
            "type": "Operation",
            "subject": "AAPL",
            "date": "2015-11-10",
            "quantity": 10,
            "price": 120.15,
            "commissions": {},
            "raw_results": {},
            "operations": []
        },
        {
            "type": "Operation",
            "subject": "GOOG",
            "date": "2015-11-10",
            "quantity": 10,
            "price": 724.89,
            "commissions": {},
            "raw_results": {},
            "operations": []
        },
        {
            "type": "Operation",
            "subject": "GOOG",
            "date": "2015-11-10",
            "quantity": -5,
            "price": 724.98,
            "commissions": {},
            "raw_results": {},
            "operations": []
        }
    ],
    "initial state": {
        "AAPL": {
            "date": "2015-10-09",
            "quantity": 92,
            "price": 119.27,
            "results": {"trades": 5021.72}
        }
    }
}'''

json_output = interface.get_trade_results(json_input)

print(json_output)
#$ {
#  "assets": {
#    "AAPL": {
#      "states": {
#        "2015-10-09": {
#          "price": 119.27,
#          "quantity": 92,
#          "results": {
#            "trades": 5021.7200000000003
#          }
#        },
#        "2015-11-10": {
#          "price": 119.35627450980392,
#          "quantity": 102,
#          "results": {
#            "trades": 5021.7200000000003
#          }
#        }
#      },
#      "totals": {
#        "daytrades": 0,
#        "operations": 1,
#        "purchases": 1,
#        "results": {
#          "trades": 5021.7200000000003
#        },
#        "sales": 0
#      }
#    },
#    "GOOG": {
#      "states": {
#        "2015-11-10": {
#          "price": 724.88999999999999,
#          "quantity": 5,
#          "results": {
#            "daytrades": 0.45000000000027285
#          }
#        }
#      },
#      "totals": {
#        "daytrades": 1,
#        "operations": 2,
#        "purchases": 1,
#        "results": {
#          "daytrades": 0.45000000000027285
#        },
#        "sales": 1
#      }
#    }
#  },
#  "totals": {
#    "daytrades": 1,
#    "operations": 3,
#    "purchases": {
#      "operations": 2,
#      "volume": 8450.3999999999996
#    },
#    "results": {
#      "daytrades": 0.45000000000027285,
#      "trades": 5021.7200000000003
#    },
#    "sales": {
#      "operations": 1,
#      "volume": 3624.9000000000001
#    }
#  }
#}

Compatibility

trade is compatible with Python 2.7, 3.3, 3.4 and 3.5.

Version

The current version is 0.2.6 alpha.

License

Copyright (c) 2015 Rafael da Silva Rocha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for trade 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for trade 0.2.6
File Interpreter ABI Platform
trade-0.2.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / trade-0.2.6-py2.py3-none-any.whl

Download URL trade-0.2.6-py2.py3-none-any.whl
Size 23.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
03131c39cb91c32542199f04c251a511ac1a71207703c01f87d3de2bde8cd450
BLAKE2b-256 checksum
How to use checksums
acbe49f466e7b05dbd46d9ad3da6ea2845442949f3fa9b57a737e882e5876045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

1 release file

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

This release

0.2.6 This release

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page