Skip to main content

Build Windows Build Coverage Status Code Climate Python Versions Live Demo

trade

trade is a framework for the development of financial applications. It operates on the concept of subjects and occurrences. A subject represents anything that can be traded, while an occurrence represents anything that affects one or more subjects, like a stock exchange operation or a stock split.

It was developed to work with any kind of subject and occurrence related to the financial market, and also to work under specific rules of different markets across the World, by following these principles:

  • different subjects may have different attributes

  • a subject may be related to none or many other subjects

  • an occurrence must involve one or many subjects

  • there may be an existing context for any subject

  • different occurrences can implement different processes with their subjects

  • an occurrence may update the state of none or many subjects

Extending the framework with market-specific rules and operations should be as simple as creating new types of subjects and occurrences.

You can try it live.

There is an ongoing effort in documenting this project. Check it out.

In a nutshell

trade works like a service. The user informs the items he have in stock and a series of subsequent occurrences (purchases, sales, whatsoever) with those or other items. trade then calculates the effects of those occurrences and gives back the new amounts and costs of the items in stock.

Quickstart

An example of the JSON interface:

from trade import trade
from trade.trade_json import TradeJSON


interface = TradeJSON(
    [trade.fetch_daytrades],
    {
        'Asset': trade.Asset,
        'Operation': trade.Operation,
    }
)

json_input = '''{
    "subjects": {
        "GOOG": {
            "type": "Asset",
            "name": "Google Inc"
        },
        "AAPL": {
            "type": "Asset",
            "name": "Apple, Inc."
        }
    },
    "occurrences": [
        {
            "type": "Operation",
            "subject": "AAPL",
            "date": "2015-11-10",
            "quantity": 10,
            "price": 120.15
        },
        {
            "type": "Operation",
            "subject": "GOOG",
            "date": "2015-11-10",
            "quantity": 10,
            "price": 724.89
        },
        {
            "type": "Operation",
            "subject": "GOOG",
            "date": "2015-11-10",
            "quantity": -5,
            "price": 724.98
        }
    ],
    "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.9 alpha.

Installation

The module can be installed with pip:

$ pip install trade

License

Copyright (c) 2016 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trade-0.2.9.zip (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trade-0.2.9-py2.py3-none-any.whl (18.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file trade-0.2.9.zip.

File metadata

  • Download URL: trade-0.2.9.zip
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for trade-0.2.9.zip
Algorithm Hash digest
SHA256 f7d9bb523f435c1668f02e55f645c9a71c2911be4c0974591e261dffddad437e
MD5 07cceea71ae3c9a87611db1480d4d702
BLAKE2b-256 9fcd9ed27ebd690fcd1d898a49c427433bd73ab035a0d9501a31c64699fe3e9e

See more details on using hashes here.

File details

Details for the file trade-0.2.9-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for trade-0.2.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e08506149f1e6d41cdfe429f1cd55d4c91521034c2c1090c448b147f6585236a
MD5 f07b5ceae25ab462e440795ad54b10d5
BLAKE2b-256 e5235b5945127b9ac05921a74373f823637565e3228ce513679fdca51195b896

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

1 file

0.4.2

2 files

0.4.1

2 files

0.4

2 files

This release

0.2.9 This release

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 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