Skip to main content

python_forex_types

Class models for Eight major Forex Currency Pairs.

Summary of Classes provided

class init example description
Calc -- Has class methods for doing calculations with other types.
Cash Cash("102.231", Currency.JPY) Cash represented by decimal number and currency.
Currency Currency("EUR") EUR, GBP, AUD, NZD, USD, CAD, CHF or JPY
FracPips FracPips(112345) Integer subclass for fractional pips.
LotSize LotSize(20000) Integer subclass for number of units in trade.
Pair Pair("AUD_USD") one of 28 forex pairs from the 8 currencies
Price Price("1.2342") Decimal based representation of forex price.

Quick Example

from forex_types import Pair, Currency, Price, LotSize, Calc, Direction

# Details of trade:
pair = Pair.EUR_USD
lot_size = LotSize(20000)
direction = Direction.LONG
entry_price = Price("1.2223")
exit_price = Price("1.2244")

# Figuring out the profit (or loss)
profit = Calc.get_trade_cash(lot_size, pair.quote, direction, entry_price, exit_price)

print(f"Trade Result: {profit.nearest_cent()}")

Quick note about Price class

Although the Price class represents price, it does not know its quote currency. When constructed it determines if the price is in a Japanese Yen kind of range, and if so a subclass called NinjaPrice is returned, otherwise if it is in a reasonable range for other currencies a Price object is returned. If the price is out of what is considered a reasonable range, an exception is raised. Note that an important difference between Japanese Yen based currencies is that there are 100 pips to a Yen, but for our other currencies there are 10,000 pips per unit.

Disclaimers:

  1. Only the eight major currencies are supported with the resulting 28 currency pairs. This might be expanded to include other currencies that are reasonably stable and whose central banks establish a record of responsibly managing them (the CHF is supported with a reluctant eye to that business with the Euro peg in 2015--but with the trust they have learned their lesson).
  2. There is no plan to ever support any crypto currency. Nor is there any chain saw juggling support for similar reasons.
  3. no API to any data or broker in this package. However, there is a separate oanda-candles API that is built on this package.
  4. The Calc class needs some more functionality. In particular, a function that converts one currency into another given the relevant forex price.
  5. There are parts that are not covered by unit tests and are a bit rough and likely to be changed in future updates.

Release files for forex-types 0.0.7

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

Source distribution (sdist)

Source distribution for forex-types 0.0.7
File Size Uploaded
forex-types-0.0.7.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forex-types 0.0.7
File Interpreter ABI Platform
forex_types-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / forex-types-0.0.7.tar.gz

Download URL forex-types-0.0.7.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
47cfa05b244c04edcf6780233202471231586cba5381dac0a455bc218f97c1c3
BLAKE2b-256 checksum
How to use checksums
e822e51aca05418d61176fa46fa4ea397da3b56e9afa3a4b03c969881e8c9ee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.2 Windows/10

Release files / forex_types-0.0.7-py3-none-any.whl

Download URL forex_types-0.0.7-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ef3dcfd434eecb4c97a0abfb71d0c6ee90a77b99ed98839975c21aad98130c4
BLAKE2b-256 checksum
How to use checksums
e275e4751a31b9bf09377a34631e3d33112a0ffc9d84560c438e629fc0e2e340
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.2 Windows/10

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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