Coder Social home page Coder Social logo

pine-bot-client's Introduction

Pine Bot Client

日本語

What's this?

This is a client implementation of trading program(bot) which can use Pine script langauge used in TradingView to define a strategy.

  • (Currently) Only support crypto trading using ccxt and cryptowatch API.
  • Work with server module (which is not public)
  • Pine script is processed on server-side.
  • Client module collects price information (OHLCV) adn make an order. (API key and secret information won't be sent to server.)

Exchange/Market support

This program uses ccxt to make an order and use cryptowatch API to acquire price information to reduce the number API calls of exchange. It means you can trade any pairs at any exchanges which are supported by both modules theortically.

However the above two system often diffrent symbol name for identical market, so we need to translate it (by implementing). Your feedback and request are appreciated.

Restrictions in Pine language

(In server-side,) an original Pine runtime is implemented and used. So far it has supported subset of Pine language and here are notable restrictions.

  • Version 3 is supported
  • Not implemented builtin functions
    • security()
    • strategy.order()
    • Many others...(Your request is appreciated)
  • Syntax
    • Multiple assignment statement
  • Order
    • Limit order
    • Stop/Stop-limit order
    • Pyramiding
  • starategy.risk builtin variables

Installation

Just extract released tarball/zip file.

Here are prerequistics:

  • Python >= 3.6 (Mandaotry)
  • ccxt >= 1.17.376 (Recommendation)

How to use

1. Move to the directory made by tarball extractio.

$ cd pine-bot-client-xxxx

2. Prepare global parameter file from template.

$ mv global-parameters.json.tmpl global-parameters.json

Supported parameters are explained in different section. You set API key in this file usually.

3. Generate Pine local paramter file.

$ python pine-bot-client.py init <your Pine script>

If finished successfully, it generates <Pine script>.json file. You usually set exchange, market, time resolution and order lot with the parameters you defined by input() function in the Pine script.

4. Run

$ python pine-bot-client.py run <your Pine script>

It outputs log files under log/ directory with console output.

Other commands

In the above section, init and run commands are introduced. There are other commands, help to show usage and support command to output exchange/market support information.

Show usage

$ python pine-bot-client.py help

Show list of supported exchange

$ python pine-bot-client.py support

Supported symbols in an exchange.

$ python pine-bot-client.py support <exchange>

You can specify an identifier of supported exchange.

This is a simple output.

$ python pine-bot-client.py support bitflyer
BTC/JPY: ['BTC/JPY', 'BTCJPY', 'BTC_JPY']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']
FX_BTC_JPY: ['FX_BTC_JPY', 'FXBTCJPY']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']
ETH/BTC: ['ETH/BTC', 'ETHBTC', 'ETH_BTC']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']
BCH/BTC: ['BCH/BTC', 'BCHBTC', 'BCH_BTC']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']
BTCJPY29MAR2019: ['BTCJPY29MAR2019']: False: []
BTCJPY01MAR2019: ['BTCJPY01MAR2019']: False: []
BTCJPY08MAR2019: ['BTCJPY08MAR2019']: False: []
BTC/USD: ['BTC/USD', 'BTCUSD', 'BTC_USD']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']
BTC/EUR: ['BTC/EUR', 'BTCEUR', 'BTC_EUR']: True: ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '12h', '1d', '3d', '1w']

The first column is symbol name. You can also use aliases show in next column surronded by [].

Next column including True/False show whether price infomration is availabe with cryptowatch API (with successful tranlation of symbol names).

Last column is supported time resolution. If it's empty, the symbole is not available.

Notes

The clock of the box where this bot client is running should be accurate enough even if this program calibrates internally using server-side clock. (The observed delay is shown in log information as jitter=.

Configuration files

This bot uses three kinds of JSON-format configuration files.

  • glogal-parameters.json under current working directory.
  • <pine script name>.json` next to Pine script file to run.
  • Additonal file specified as last optional argument of run command. You can write all configuration itmes in any of these files because they are merged into single object before running.

In merging, it follows following priority order.

 global-parameters.json < <pine script>.json < run command json

Configuration Items

Top-level items

  • exchange (string) - Exchange id.
  • symbol (string) - Market symbol.
  • resolution (string,integer) - Time resolution. Something like shown as support command or integer value in minute.

inputs

Under this item, you can specify paramters defined by input() function. You need to follow type defined in input() function.

strategy

Under this item, you can change paramters defined in strategy() function. Most relavant one should be default_qty_value.

  • default_qty_value (float) - Order lot Currently default_qty_type is ignored and this value is directly used as order size in each market.

ccxt

You can specify options to give to ccxt library. Please refer to ccxt document for details. Here are most relavant options.

  • apiKey (string) - API key
  • secret (string) - API secret

You can use different ccxt parameters for different exchanges. It's useful to write API key/secret informations for all exchanges in global-parameters.json.

discord

Items for push notification using Discord

  • name (string) - Notification name
  • url (string) - URL for notification issued by Discord
  • avatar_url (string) - URL for avatar image

pine-bot-client's People

Contributors

kzh-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pine-bot-client's Issues

502 Bad Gateway

The server http://pine-api.kzh-crypto.net/ is not responding. Is there anyway you can include a module to perform what this server is doing in pine-bot-client?

os.system("python pine-bot-client.py support bitflyer")
2019-04-02 22:59:59,383: CRITICAL: fail to execute 'support: Bad status code: <Response [502]>
Traceback (most recent call last):
File "pine-bot-client.py", line 139, in
do_support(params, args[0], args[1])
File "C:\Temp\NotKnowing\command\support.py", line 9, in do_support
res = call_api(params, '/exchange-support', exchange=exchange, market=market)
File "C:\Temp\NotKnowing\util\comm.py", line 23, in call_api
_, json = _call_api(ap_params, path, **kws)
File "C:\Temp\NotKnowing\util\comm.py", line 15, in _call_api
raise BadResponse('Bad status code: {}'.format(r))
util.comm.BadResponse: Bad status code: <Response [502]>

Need help

Hi

I would like to know If I can use this repo to use for Indian NSE Market for stocks?
Can you suggest what are the changes I should take care of or any pointers please.

Thanks
Anand

When I try python pine-bot-client.py init <your Pine script> I get an error

I get this error when I try python pine-bot-client.py init <your Pine script>:

2021-05-08 01:37:40,198: CRITICAL: fail to execute 'init: Bad status code: <Response [404]>
Traceback (most recent call last):
  File "C:\Users\Kadiem Alqazzaz\Desktop\pine-bot-client-master\pine-bot-client.py", line 144, in <module>
    do_init(params, pine_fname, pine_str)
  File "C:\Users\Kadiem Alqazzaz\Desktop\pine-bot-client-master\command\init.py", line 9, in do_init
    res = call_api(params, '/scan-input', code=pine_str)
  File "C:\Users\Kadiem Alqazzaz\Desktop\pine-bot-client-master\util\comm.py", line 23, in call_api
    _, json = _call_api(ap_params, path, **kws)
  File "C:\Users\Kadiem Alqazzaz\Desktop\pine-bot-client-master\util\comm.py", line 15, in _call_api
    raise BadResponse('Bad status code: {}'.format(r))
util.comm.BadResponse: Bad status code: <Response [404]>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.