cryptotsla

command module
v0.0.0-...-2e80a61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

README

Overview

cryptotsla calculates the current Bitcoin spot price of a specific Tesla vehicle configuration, optionally taking a currency and regionally available Tesla vehicle configurations into account.

The information is made available via a JSON API that can be queried via http, e.g.:

curl -s "https://api.cryptotsla.com/model/Y" |jq .
{
  "Model": "Y",
  "BasePrice": 41990,
  "Variant": "StandardRange",
  "Options": {
    "DestinationFee": 1200
  },
  "BTCSpotPrice": "48026.86",
  "Currency": "USD",
  "Total": 43190,
  "TotalBTC": "0.8992884398438707",
  "GeneratedByURL": "https://api.cryptotsla.com",
  "Timestamp": "2021-02-15T17:28:59.903489389-05:00"
}

To get just the BTC total:

curl -s "https://api.cryptotsla.com/model/Y"  |jq .TotalBTC
0.8992884398438707

The default model Y variant, "StandardRange", was selected automatically. To request a different variant:

curl -s "https://api.cryptotsla.com/model/Y/LongRange" |jq .
{
  "Model": "Y",
  "BasePrice": 49990,
  "Variant": "LongRange",
  "Options": {
    "DestinationFee": 1200
  },
  "BTCSpotPrice": "48192.08",
  "Currency": "USD",
  "Total": 51190,
  "TotalBTC": "1.0622077320588777",
  "GeneratedByURL": "https://api.cryptotsla.com",
  "Timestamp": "2021-02-15T17:36:50.646497513-05:00"
}

It is also possible to specify vehicle options:

curl -s "https://api.cryptotsla.com/model/Y/LongRange?options=TowHitch,SevenSeatInterior" |jq .
{
  "Model": "Y",
  "BasePrice": 49990,
  "Variant": "LongRange",
  "Options": {
    "DestinationFee": 1200,
    "SevenSeatInterior": 3000,
    "TowHitch": 1000
  },
  "BTCSpotPrice": "48108.21",
  "Currency": "USD",
  "Total": 55190,
  "TotalBTC": "1.147205435413207",
  "GeneratedByURL": "https://api.cryptotsla.com",
  "Timestamp": "2021-02-15T17:37:36.980907053-05:00"
}

If an option is requested that does not exist, it will be ignored. Some options only exist in certain territories and will only be included when the relevant currency is selected.

A different currency can be selected. This also limits the response to the models, variants and options available in the relevant territory, for example:

curl -s "https://api.cryptotsla.com/model/3/LongRange?options=Red&currency=GBP" |jq .
{
  "Model": "3",
  "BasePrice": 46990,
  "Variant": "LongRange",
  "Options": {
    "Red": 2000
  },
  "BTCSpotPrice": "34697.26",
  "Currency": "GBP",
  "Total": 48990,
  "TotalBTC": "1.4119270513003044",
  "GeneratedByURL": "https://api.cryptotsla.com",
  "Timestamp": "2021-02-15T17:50:49.112942967-05:00"
}

Model, variant and option names are case insensitive.

Get a list of available models and options:

curl -s "https://api.cryptotsla.com/available" |jq .
{
  "Models": [
    {
      "Name": "S",
      "Options": [
        "Black",
        "Silver",
        "EnhancedAutopilot",
        "DestinationFee",
        "Blue",
        "CreamInterior",
        "ArachnidWheels",
        "BlackAndWhiteInterior",
        "FSD",
        "Red"
      ],
      "Variants": [
        "PlaidPlus",
        "LongRange",
        "Plaid"
      ]
    },
    {
      "Name": "3",
      "Options": [
        "TowHitch",
        "BlackAndWhiteInterior",
        "FSD",
        "Wintertires",
        "Blue",
        "Black",
        "Silver",
        "SportWheels",
        "DestinationFee",
        "Red",
        "EnhancedAutopilot"
      ],
      "Variants": [
        "StandardRangePlus",
        "LongRange",
        "Performance"
      ]
    },
    {
      "Name": "X",
      "Options": [
        "BlackAndWhiteInterior",
        "EnhancedAutopilot",
        "Black",
        "DestinationFee",
        "FSD",
        "TurbineWheels",
        "CreamInterior",
        "Red",
        "SixSeatInterior",
        "SevenSeatInterior",
        "Blue",
        "Silver"
      ],
      "Variants": [
        "LongRange",
        "Plaid"
      ]
    },
    {
      "Name": "Y",
      "Options": [
        "InductionWheels",
        "Silver",
        "TowHitch",
        "Black",
        "BlackAndWhiteInterior",
        "SevenSeatInterior",
        "DestinationFee",
        "FSD",
        "Red",
        "Blue"
      ],
      "Variants": [
        "LongRange",
        "Performance",
        "StandardRange"
      ]
    }
  ]
}

Room for improvement

  • There is no BTC-CAD order book via this Coinbase API. Use a different API? The Coinbase developer API seems to have a price endpoint for CAD.
  • We need some sort of locale option. Particularly for the Euro pricing, where there are differences between the countries that use the Euro.
  • Many currencies are missing from config.yml.example
  • Add tests

Building the software

GNU Make and a Go compiler, version 1.11 or higher are required.

Build with the make command from the root of the tree.

Running the software

Copy the config.yml.example file to config.yml and adjust as necessary. Run the software with the ./cryptotsla command. A sample systemd unit file is provided in the systemd subdirectory.

Hacking

GNU Make and a Go compiler, version 1.11 or higher are required. In addition, GolangCI-Lint is needed.

Build the software with the make dev command.

Licensing

cryptotsla is Free Software, released under the GNU Affero GPL v3 or later. See the LICENSE file for the text of the license.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL