Files
gocryptotrader/gctscript
Andrew b26ec86d43 Withdraw additional functionality (validation/submission/tracking) (#409)
* reworked request struct and exchange response started work on validation system

* removed import cycle until work around

* Added intial withdraw support via CLI added

* Added Crypto command to gctcli

* moved var declartion to single line

* Test updates for binance and anx

* All exchange tests have been updated test coverage added to validate

* First pass at adding withdrawl select from database

* started adding basic lru cache system

* Added basic LRU cache including Add Get Remove Contains ContainsOrAdd Clear

* wording changes on comments

* removed exported var's in strut as they are not required

* Added README

* README updates

* corrected ID on commands

* rm line :D

* merged in origin/cache

* linter fixes (gofmt)

* Added basic cache lookup to events

* swapped to mutex over rwmutex updated comments

* unexported getNewest & getOldest

* unexported getNewest & getOldest

* Updated comments and cited references in source

* updated comments

* WIP

* Migrated exchange WithdrawFiat wrapper to new struct response

* Migrated exchange WithdrawFiat wrapper to new struct response

* started work on bank management

* Added exchange level banking details back with migration to banking package

* Removed broken tests for now

* Added validation to bank accounts

* removed duplicate bank details from withdraw struct

* Test coverage increased

* gofmt

* merged upstream/master with clean up

* First pass at adding command line linking to gctcli

* added validation for crypto address, added gctcli support to retreive previous withdrawal requests

* general cleanup

* general cleanup

* reordered imports

* Increased test coverage moved to database sublogger

* Pass incorrect currency no longer return error from c.CheckBankAccountConfig

* remove TestMain() for now as other tests in this package will need to be reworked

* Happy little race car

* Reverted to upstream tests

* Added test covarege for validation method, corrected response on cli protobuf

* query clean up and removal of duplicated code

* cleaned up queries into singlem ethod increased test coverage

* Migrated international fund withdraw to new exchange response and added cache size override

* Migrated international fund withdraw to new exchange response and added cache size override

* Extended gctcli commands

* lowered default cache to 25

* small code clean up

* added get by date method

* add returned error

* cli commands cleaing return error on nil results to fix out of bounds

* merged write & read helpers into one for test coverage and increased engine/withdraw test coverage

* gofmt

* Added test coverage for valid ID

* removed unused param

* converted to use timestamp package from protobuf

* gofmt

* use built in RFC3339 timestamp

* remove setting of CreatedAt & UpdatedAt and allow ORm to take care of it

* also use ptype on byid

* code flow improvements

* remove inverse conditional check and linters run

* removed test data

* removed comment

* removed comment

* also write failures to database for auditing

* converted to use default time for start & end

* Default to time.Now() minus 30 days

* Default to time.Now() minus 30 days

* small code clean up

* fixed missing semicolon on migrations, code clean up

* updated sqlite migrations

* Added additonal check for exchange level bank account if global is not found

* case sensativity fix for currency names

* use correct compare

* test coverage fixed

* removed space

* return pointer to banking.Account

* return pointer to banking.Account

* added else check back to validate()

* Added empty string as default to migration over NULL due to retrivial of data
2020-02-26 15:45:13 +11:00
..
2020-01-23 13:54:04 +11:00
2020-02-12 18:09:56 +11:00
2020-01-23 13:54:04 +11:00
2020-02-06 12:32:01 +11:00

GoCryptoTrader package gctscript

Build Status Software License GoDoc Coverage Status Go Report Card

This gctscript package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for gctscript package

  • Execute scripts
  • Terminate scripts
  • Autoload scripts on bot startup
  • Current Exchange features supported:
    • Enabled Exchanges
    • Enabled currency pairs
    • Account information
    • Query Order
    • Submit Order
    • Cancel Order
    • Ticker
    • Orderbook

How to use

Prerequisites

To Enable database logging support you must have an active migrated database by following the database setup guide

Configuration

The gctscript configuration struct is currently:

type Config struct {
	Enabled       bool          `json:"enabled"`
	ScriptTimeout time.Duration `json:"timeout"`
	AllowImports  bool          `json:"allow_imports"`
	AutoLoad      []string      `json:"auto_load"`
	Verbose       bool          `json:"Verbose"`
}

With an example configuration being:

 "gctscript": {
  "enabled": true,
  "timeout": 600000000,
  "allow_imports": true,
  "auto_load": [],
  "debug": false
 },
Script Control
  • You can autoload scripts on bot start up by placing their name in the "auto_load" config entry

    "auto_load": ["one","two"]
    

    This will look in your GoCryptoTrader data directory in a folder called "scripts" for files one.gct and two.gct and autoload them

  • Manual control of scripts can be done via the gctcli command with support for the following:

    • Enable/Disable GCTScript:
     gctcli enablesubsystem "gctscript"
     gctcli disablesubsystem "gctscript"
    
    • Start/Execute:
      gctcli gctscript execute <scriptname> <pathoverride>
      gctcli gctscript execute "timer.gct" "~/gctscript"
    
      {
        "status": "ok",
        "data": "timer.gct executed"
      }
    
    • Stop:
      gctcli gctscript stop <uuid>
      gctcli gctscript stop 821bd73e-02b1-4974-9463-874cb49f130d
    
      {
        "status": "ok",
        "data": "821bd73e-02b1-4974-9463-874cb49f130d terminated"
      }
    
    • Status:
      gctcli gctscript status 
    
      {
        "status": "ok",
        "scripts": [
          {
            "uuid": "821bd73e-02b1-4974-9463-874cb49f130d",
            "name": "timer.gct",
            "next_run": "2019-11-14 13:11:40.224919456 +1100 AEDT m=+91.062103259"
          }
        ]
      }
    
    • Read file:
      gctcli gctscript read <filename>
      gctcli gctscript read "timer.gct"
    
      {
        "status": "ok",
        "script": {
        "name": "timer.gct",
        "path": "/home/x/.gocryptotrader/scripts"
        },
        "data": "fmt := import(\"fmt\")\nt := import(\"times\")\n\nname := \"run\"\ntimer := \"5s\"\n\nload := func() {\n\tfmt.printf(\"5s %s\\n\",t.now())\n}\n\nload()\n"
      }
    
    • Query running script:
      gctcli gctscript query <uuid>
      gctcli gctscript query 821bd73e-02b1-4974-9463-874cb49f130d
      {
        "status": "ok",
        "script": {
        "UUID": "bf692e2d-fa1e-4d95-92fd-33d7634d3d77",
        "name": "timer.gct",
        "path": "/home/x/.gocryptotrader/scripts",
        "next_run": "2019-12-12 07:44:19.747572406 +1100 AEDT m=+16.782773385"
      },
      "data": "fmt := import(\"fmt\")\nt := import(\"times\")\n\nname := \"run\"\ntimer := \"5s\"\n\nload := func() {\n\tfmt.printf(\"5s %s\\n\",t.now())\n}\n\nload()\n"
      }
      load()  
    
    • Add script to autoload:
    gctcli gctscript autoload add timer
    {
      "status": "success",
      "data": "script timer added to autoload list"
    }
    
    • Remove script from autoload:
      gctcli gctscript autoload remove timer
      {
        "status": "success",
        "data": "script timer removed from autoload list"
      }
    
Scripting & Extending modules

The scripting engine utilises tengo an intro tutorial for it can be found here

Modules have been written so far linking up common exchange features including

  • Orderbook
  • Ticker
  • Order Management
  • Account information
  • Withdraw funds
  • Get Deposit Addresses

Extending or creating new modules:

Extending an existing module the exchange module for example is simple

  • Open required module
  • Add to exchangeModule map
  • Define function with signature (args ...objects.Object) (ret objects.Object, err error)

Similar steps can be taken to add a new module with a few adjustments

  • Open required GCT
  • Add module name to GCTModules map
GCT module methods

Current supported methods added and exposed to scripts are as follows:

accountinfo
-> exchange:string

depositaddress
-> exchange:string
-> currency:string

orderbook
-> exchange:string
-> currency pair:string
-> delimiter:string
-> asset:string

ticker
-> exchange:string
-> currency pair:string
-> delimiter:string
-> asset:string

pairs
-> exchange:string
-> enabled only:bool
-> asset:string

queryorder
-> exchange:string
-> order id:string

submitorder
-> exchange:string
-> currency pair:string
-> delimiter:string
-> order type:string
-> order side:string
-> price:float64
-> amount:float64
-> client_id:string

withdrawfiat
-> exchange:string
-> currency:string
-> description:string
-> amount:float64
-> bank id:string

withdrawcrypto
-> exchange:string
-> currency:string
-> address:string
-> address tag:string
-> amount:float64
-> fee:float64
-> description:string

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc