├── .gitignore ├── README.md ├── Using git bash.txt ├── csharp ├── ReadMe └── src │ └── com │ └── gate │ └── rest │ ├── GetHMACSHA512.cs │ ├── HttpUtilManager.cs │ ├── stock │ └── IStockRestApi.cs │ └── test │ └── StockRestApiTest.cs ├── go └── gateioApi.go ├── java ├── .classpath ├── .project ├── .settings │ └── org.eclipse.core.resources.prefs ├── ReadMe ├── lib │ ├── commons-codec-1.7.jar │ ├── commons-io-2.2.jar │ ├── commons-logging-1.0.4.jar │ ├── fastjson-1.1.23.jar │ ├── httpclient-4.3.6.jar │ ├── httpcore-4.3.3.jar │ ├── jackson-annotations-2.0.2.jar │ ├── jackson-core-2.0.2.jar │ ├── jackson-databind-2.0.2.jar │ └── json-20140107.jar └── src │ └── com │ └── gate │ └── rest │ ├── HttpUtilManager.java │ ├── MD5Util.java │ ├── StockClient.java │ ├── StringUtil.java │ └── stock │ ├── IStockRestApi.java │ └── impl │ └── StockRestApi.java ├── nodejs ├── app.js ├── lib │ └── gate.js └── package.json ├── perl └── gateioApi.pl ├── php └── gate.php └── python ├── Client.py ├── HttpUtil.py └── gateAPI.py /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/go,perl,node,java,python,csharp 3 | # Edit at https://www.gitignore.io/?templates=go,perl,node,java,python,csharp 4 | 5 | ### Csharp ### 6 | ## Ignore Visual Studio temporary files, build results, and 7 | ## files generated by popular Visual Studio add-ons. 8 | ## 9 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 10 | 11 | # User-specific files 12 | *.rsuser 13 | *.suo 14 | *.user 15 | *.userosscache 16 | *.sln.docstates 17 | 18 | # User-specific files (MonoDevelop/Xamarin Studio) 19 | *.userprefs 20 | 21 | # Mono auto generated files 22 | mono_crash.* 23 | 24 | # Build results 25 | [Dd]ebug/ 26 | [Dd]ebugPublic/ 27 | [Rr]elease/ 28 | [Rr]eleases/ 29 | x64/ 30 | x86/ 31 | [Aa][Rr][Mm]/ 32 | [Aa][Rr][Mm]64/ 33 | bld/ 34 | [Bb]in/ 35 | [Oo]bj/ 36 | [Ll]og/ 37 | 38 | # Visual Studio 2015/2017 cache/options directory 39 | .vs/ 40 | # Uncomment if you have tasks that create the project's static files in wwwroot 41 | #wwwroot/ 42 | 43 | # Visual Studio 2017 auto generated files 44 | Generated\ Files/ 45 | 46 | # MSTest test Results 47 | [Tt]est[Rr]esult*/ 48 | [Bb]uild[Ll]og.* 49 | 50 | # NUnit 51 | *.VisualState.xml 52 | TestResult.xml 53 | nunit-*.xml 54 | 55 | # Build Results of an ATL Project 56 | [Dd]ebugPS/ 57 | [Rr]eleasePS/ 58 | dlldata.c 59 | 60 | # Benchmark Results 61 | BenchmarkDotNet.Artifacts/ 62 | 63 | # .NET Core 64 | project.lock.json 65 | project.fragment.lock.json 66 | artifacts/ 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # JustCode is a .NET coding add-in 135 | .JustCode 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Visual Studio code coverage results 148 | *.coverage 149 | *.coveragexml 150 | 151 | # NCrunch 152 | _NCrunch_* 153 | .*crunch*.local.xml 154 | nCrunchTemp_* 155 | 156 | # MightyMoose 157 | *.mm.* 158 | AutoTest.Net/ 159 | 160 | # Web workbench (sass) 161 | .sass-cache/ 162 | 163 | # Installshield output folder 164 | [Ee]xpress/ 165 | 166 | # DocProject is a documentation generator add-in 167 | DocProject/buildhelp/ 168 | DocProject/Help/*.HxT 169 | DocProject/Help/*.HxC 170 | DocProject/Help/*.hhc 171 | DocProject/Help/*.hhk 172 | DocProject/Help/*.hhp 173 | DocProject/Help/Html2 174 | DocProject/Help/html 175 | 176 | # Click-Once directory 177 | publish/ 178 | 179 | # Publish Web Output 180 | *.[Pp]ublish.xml 181 | *.azurePubxml 182 | # Note: Comment the next line if you want to checkin your web deploy settings, 183 | # but database connection strings (with potential passwords) will be unencrypted 184 | *.pubxml 185 | *.publishproj 186 | 187 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 188 | # checkin your Azure Web App publish settings, but sensitive information contained 189 | # in these scripts will be unencrypted 190 | PublishScripts/ 191 | 192 | # NuGet Packages 193 | *.nupkg 194 | # NuGet Symbol Packages 195 | *.snupkg 196 | # The packages folder can be ignored because of Package Restore 197 | **/[Pp]ackages/* 198 | # except build/, which is used as an MSBuild target. 199 | !**/[Pp]ackages/build/ 200 | # Uncomment if necessary however generally it will be regenerated when needed 201 | #!**/[Pp]ackages/repositories.config 202 | # NuGet v3's project.json files produces more ignorable files 203 | *.nuget.props 204 | *.nuget.targets 205 | 206 | # Microsoft Azure Build Output 207 | csx/ 208 | *.build.csdef 209 | 210 | # Microsoft Azure Emulator 211 | ecf/ 212 | rcf/ 213 | 214 | # Windows Store app package directories and files 215 | AppPackages/ 216 | BundleArtifacts/ 217 | Package.StoreAssociation.xml 218 | _pkginfo.txt 219 | *.appx 220 | *.appxbundle 221 | *.appxupload 222 | 223 | # Visual Studio cache files 224 | # files ending in .cache can be ignored 225 | *.[Cc]ache 226 | # but keep track of directories ending in .cache 227 | !?*.[Cc]ache/ 228 | 229 | # Others 230 | ClientBin/ 231 | ~$* 232 | *~ 233 | *.dbmdl 234 | *.dbproj.schemaview 235 | *.jfm 236 | *.pfx 237 | *.publishsettings 238 | orleans.codegen.cs 239 | 240 | # Including strong name files can present a security risk 241 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 242 | #*.snk 243 | 244 | # Since there are multiple workflows, uncomment next line to ignore bower_components 245 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 246 | #bower_components/ 247 | 248 | # RIA/Silverlight projects 249 | Generated_Code/ 250 | 251 | # Backup & report files from converting an old project file 252 | # to a newer Visual Studio version. Backup files are not needed, 253 | # because we have git ;-) 254 | _UpgradeReport_Files/ 255 | Backup*/ 256 | UpgradeLog*.XML 257 | UpgradeLog*.htm 258 | ServiceFabricBackup/ 259 | *.rptproj.bak 260 | 261 | # SQL Server files 262 | *.mdf 263 | *.ldf 264 | *.ndf 265 | 266 | # Business Intelligence projects 267 | *.rdl.data 268 | *.bim.layout 269 | *.bim_*.settings 270 | *.rptproj.rsuser 271 | *- [Bb]ackup.rdl 272 | *- [Bb]ackup ([0-9]).rdl 273 | *- [Bb]ackup ([0-9][0-9]).rdl 274 | 275 | # Microsoft Fakes 276 | FakesAssemblies/ 277 | 278 | # GhostDoc plugin setting file 279 | *.GhostDoc.xml 280 | 281 | # Node.js Tools for Visual Studio 282 | .ntvs_analysis.dat 283 | node_modules/ 284 | 285 | # Visual Studio 6 build log 286 | *.plg 287 | 288 | # Visual Studio 6 workspace options file 289 | *.opt 290 | 291 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 292 | *.vbw 293 | 294 | # Visual Studio LightSwitch build output 295 | **/*.HTMLClient/GeneratedArtifacts 296 | **/*.DesktopClient/GeneratedArtifacts 297 | **/*.DesktopClient/ModelManifest.xml 298 | **/*.Server/GeneratedArtifacts 299 | **/*.Server/ModelManifest.xml 300 | _Pvt_Extensions 301 | 302 | # Paket dependency manager 303 | .paket/paket.exe 304 | paket-files/ 305 | 306 | # FAKE - F# Make 307 | .fake/ 308 | 309 | # CodeRush personal settings 310 | .cr/personal 311 | 312 | # Python Tools for Visual Studio (PTVS) 313 | __pycache__/ 314 | *.pyc 315 | 316 | # Cake - Uncomment if you are using it 317 | # tools/** 318 | # !tools/packages.config 319 | 320 | # Tabs Studio 321 | *.tss 322 | 323 | # Telerik's JustMock configuration file 324 | *.jmconfig 325 | 326 | # BizTalk build output 327 | *.btp.cs 328 | *.btm.cs 329 | *.odx.cs 330 | *.xsd.cs 331 | 332 | # OpenCover UI analysis results 333 | OpenCover/ 334 | 335 | # Azure Stream Analytics local run output 336 | ASALocalRun/ 337 | 338 | # MSBuild Binary and Structured Log 339 | *.binlog 340 | 341 | # NVidia Nsight GPU debugger configuration file 342 | *.nvuser 343 | 344 | # MFractors (Xamarin productivity tool) working folder 345 | .mfractor/ 346 | 347 | # Local History for Visual Studio 348 | .localhistory/ 349 | 350 | # BeatPulse healthcheck temp database 351 | healthchecksdb 352 | 353 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 354 | MigrationBackup/ 355 | 356 | ### Go ### 357 | # Binaries for programs and plugins 358 | *.exe 359 | *.exe~ 360 | *.dll 361 | *.so 362 | *.dylib 363 | 364 | # Test binary, built with `go test -c` 365 | *.test 366 | 367 | # Output of the go coverage tool, specifically when used with LiteIDE 368 | *.out 369 | 370 | # Dependency directories (remove the comment below to include it) 371 | # vendor/ 372 | 373 | ### Go Patch ### 374 | /vendor/ 375 | /Godeps/ 376 | 377 | ### Java ### 378 | # Compiled class file 379 | *.class 380 | 381 | # Log file 382 | 383 | # BlueJ files 384 | *.ctxt 385 | 386 | # Mobile Tools for Java (J2ME) 387 | .mtj.tmp/ 388 | 389 | # Package Files # 390 | *.jar 391 | *.war 392 | *.nar 393 | *.ear 394 | *.zip 395 | *.tar.gz 396 | *.rar 397 | 398 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 399 | hs_err_pid* 400 | 401 | ### Node ### 402 | # Logs 403 | logs 404 | npm-debug.log* 405 | yarn-debug.log* 406 | yarn-error.log* 407 | lerna-debug.log* 408 | 409 | # Diagnostic reports (https://nodejs.org/api/report.html) 410 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 411 | 412 | # Runtime data 413 | pids 414 | *.pid 415 | *.seed 416 | *.pid.lock 417 | 418 | # Directory for instrumented libs generated by jscoverage/JSCover 419 | lib-cov 420 | 421 | # Coverage directory used by tools like istanbul 422 | coverage 423 | *.lcov 424 | 425 | # nyc test coverage 426 | .nyc_output 427 | 428 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 429 | .grunt 430 | 431 | # Bower dependency directory (https://bower.io/) 432 | bower_components 433 | 434 | # node-waf configuration 435 | .lock-wscript 436 | 437 | # Compiled binary addons (https://nodejs.org/api/addons.html) 438 | build/Release 439 | 440 | # Dependency directories 441 | jspm_packages/ 442 | 443 | # TypeScript v1 declaration files 444 | typings/ 445 | 446 | # TypeScript cache 447 | *.tsbuildinfo 448 | 449 | # Optional npm cache directory 450 | .npm 451 | 452 | # Optional eslint cache 453 | .eslintcache 454 | 455 | # Optional REPL history 456 | .node_repl_history 457 | 458 | # Output of 'npm pack' 459 | *.tgz 460 | 461 | # Yarn Integrity file 462 | .yarn-integrity 463 | 464 | # dotenv environment variables file 465 | .env 466 | .env.test 467 | 468 | # parcel-bundler cache (https://parceljs.org/) 469 | .cache 470 | 471 | # next.js build output 472 | .next 473 | 474 | # nuxt.js build output 475 | .nuxt 476 | 477 | # react / gatsby 478 | public/ 479 | 480 | # vuepress build output 481 | .vuepress/dist 482 | 483 | # Serverless directories 484 | .serverless/ 485 | 486 | # FuseBox cache 487 | .fusebox/ 488 | 489 | # DynamoDB Local files 490 | .dynamodb/ 491 | 492 | ### Perl ### 493 | !Build/ 494 | .last_cover_stats 495 | /META.yml 496 | /META.json 497 | /MYMETA.* 498 | *.o 499 | *.pm.tdy 500 | *.bs 501 | 502 | # Devel::Cover 503 | cover_db/ 504 | 505 | # Devel::NYTProf 506 | nytprof.out 507 | 508 | # Dizt::Zilla 509 | /.build/ 510 | 511 | # Module::Build 512 | _build/ 513 | Build 514 | Build.bat 515 | 516 | # Module::Install 517 | inc/ 518 | 519 | # ExtUtils::MakeMaker 520 | /blib/ 521 | /_eumm/ 522 | /*.gz 523 | /Makefile 524 | /Makefile.old 525 | /MANIFEST.bak 526 | /pm_to_blib 527 | /*.zip 528 | 529 | ### Python ### 530 | # Byte-compiled / optimized / DLL files 531 | *.py[cod] 532 | *$py.class 533 | 534 | # C extensions 535 | 536 | # Distribution / packaging 537 | .Python 538 | build/ 539 | develop-eggs/ 540 | dist/ 541 | downloads/ 542 | eggs/ 543 | .eggs/ 544 | lib/ 545 | lib64/ 546 | parts/ 547 | sdist/ 548 | var/ 549 | wheels/ 550 | pip-wheel-metadata/ 551 | share/python-wheels/ 552 | *.egg-info/ 553 | .installed.cfg 554 | *.egg 555 | MANIFEST 556 | 557 | # PyInstaller 558 | # Usually these files are written by a python script from a template 559 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 560 | *.manifest 561 | *.spec 562 | 563 | # Installer logs 564 | pip-log.txt 565 | pip-delete-this-directory.txt 566 | 567 | # Unit test / coverage reports 568 | htmlcov/ 569 | .tox/ 570 | .nox/ 571 | .coverage 572 | .coverage.* 573 | nosetests.xml 574 | coverage.xml 575 | *.cover 576 | .hypothesis/ 577 | .pytest_cache/ 578 | 579 | # Translations 580 | *.mo 581 | *.pot 582 | 583 | # Scrapy stuff: 584 | .scrapy 585 | 586 | # Sphinx documentation 587 | docs/_build/ 588 | 589 | # PyBuilder 590 | target/ 591 | 592 | # pyenv 593 | .python-version 594 | 595 | # pipenv 596 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 597 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 598 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 599 | # install all needed dependencies. 600 | #Pipfile.lock 601 | 602 | # celery beat schedule file 603 | celerybeat-schedule 604 | 605 | # SageMath parsed files 606 | *.sage.py 607 | 608 | # Spyder project settings 609 | .spyderproject 610 | .spyproject 611 | 612 | # Rope project settings 613 | .ropeproject 614 | 615 | # Mr Developer 616 | .mr.developer.cfg 617 | .project 618 | .pydevproject 619 | 620 | # mkdocs documentation 621 | /site 622 | 623 | # mypy 624 | .mypy_cache/ 625 | .dmypy.json 626 | dmypy.json 627 | 628 | # Pyre type checker 629 | .pyre/ 630 | 631 | # End of https://www.gitignore.io/api/go,perl,node,java,python,csharp 632 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rest API Introduction 2 | 3 | Welcome to the Gate Rest API! You can use this API to get market data, trade, and manage your account. 4 | 5 | Each API call is described in detail in the [API2.0](https://gate.io/en/api2) English documentation 6 | 7 | The API v2 version is no longer being updated and maintained, and we recommend that you use the latest [API v4](https://www.gate.io/docs/developers/apiv4/en/) version. 8 | 9 | ## API Interface Address 10 | 11 | https://data.gateapi.io 12 | 13 | * Access via proxy is not recommended for reasons such as high latency and poor stability. 14 | 15 | 16 | ## Rate Limit 17 | 10r/s 18 | 19 | ## Create API Key 20 | You can create the API Key at [here](https://www.gate.io/en/myaccount/apikeys). 21 | 22 | API Keys includes the following two parts 23 | 24 | Key : API key 25 | 26 | Secret : The key used for signature authentication encryption 27 | 28 | Write the requested API keys to the application configuration file. 29 | 30 | // API settings, add your Key and Secret at here 31 | $key = ''; 32 | $secret = ''; 33 | 34 | 35 | *When creating API Keys, you can choose to bind IPs, which can be set by IP whitelist (multiple IPs separated by half comma). 36 | *Note: Using the API Keys above will allow you to perform account information inquiries and trading operations through the program, but not withdrawal operations. Do not disclose the API Keys to others. 37 | *Create new API Keys: Generate new API Keys, the old ones will be invalidated immediately. 38 | 39 | ## Request Format 40 | All API requests are called as GET or POST. Getting market data is requested via GET, with all parameters in path parameters; for transaction and account data is requested via POST, and all parameters are sent in JSON format. 41 | 42 | ## Return Format 43 | All interface returns are in JSON format. The [API2.0](https://gate.io/en/api2) document has JSON fields for request status and properties. 44 | 45 | ## Error message 46 | 47 | The system returns an error code corresponding to the description 48 | 49 | Error Codes Details 50 | 1 Invalid request 51 | 2 Invalid version 52 | 3 Invalid request 53 | 4 Forbidden access 54 | 5,6 Invalid sign 55 | 7 Currency is not supported 56 | 8,9 Currency is not supported 57 | 10 Verified failed 58 | 11 Obtaining address failed 59 | 12 Empty params 60 | 13 Internal error, please report to administrator 61 | 14 Invalid user 62 | 15 Cancel order too fast, please wait 1 min and try again 63 | 16 Invalid order id or order is already closed 64 | 17 Invalid orderid 65 | 18 Invalid amount 66 | 19 Not permitted or trade is disabled 67 | 20 Your order size is too small 68 | 21 You don't have enough fund 69 | 40 Too many attempts 70 | 71 | -------------------------------------------------------------------------------- /Using git bash.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/Using git bash.txt -------------------------------------------------------------------------------- /csharp/ReadMe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/csharp/ReadMe -------------------------------------------------------------------------------- /csharp/src/com/gate/rest/GetHMACSHA512.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Security.Cryptography; 7 | 8 | namespace Com.Gate.Rest 9 | { 10 | class GetHMACSHA512 11 | { 12 | 13 | public static Object hash_hmac(string signatureString, string secretKey, bool raw_output = false) 14 | { 15 | var enc = Encoding.UTF8; 16 | HMACSHA512 hmac = new HMACSHA512(enc.GetBytes(secretKey)); 17 | hmac.Initialize(); 18 | 19 | byte[] buffer = enc.GetBytes(signatureString); 20 | if (raw_output) 21 | { 22 | return hmac.ComputeHash(buffer); 23 | } 24 | else 25 | { 26 | return BitConverter.ToString(hmac.ComputeHash(buffer)).Replace("-", "").ToLower(); 27 | } 28 | } 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /csharp/src/com/gate/rest/HttpUtilManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.IO; 7 | using System.Web; 8 | using System.Net; 9 | using Newtonsoft.Json.Linq; 10 | using System.Security.Cryptography; 11 | 12 | namespace Com.Gate.Rest 13 | { 14 | class HttpUtilManager 15 | { 16 | private static String SECRET = ""; //您的API Secret 17 | private static String KEY = ""; //您的API Key 18 | private static HttpUtilManager instance = new HttpUtilManager(); 19 | private HttpUtilManager() { } 20 | public static HttpUtilManager getInstance() 21 | { 22 | return instance; 23 | } 24 | 25 | String result = ""; 26 | 27 | //请求类 28 | HttpWebRequest request = null; 29 | //请求响应类 30 | HttpWebResponse response = null; 31 | //响应结果读取类 32 | StreamReader reader = null; 33 | 34 | public String requestHttpGet(String url_prex, String url, String param) 35 | { 36 | url = url_prex + url; 37 | if (param == null || !"".Equals(url)) 38 | { 39 | if (url.EndsWith("?")) 40 | { 41 | url = url + param; 42 | } 43 | else 44 | { 45 | url = url + "?" + param; 46 | } 47 | } 48 | //http连接数限制默认为2,多线程情况下可以增加该连接数,非多线程情况下可以注释掉此行代码 49 | //ServicePointManager.DefaultConnectionLimit = 500; 50 | request = WebRequest.Create(url) as HttpWebRequest; 51 | request.ProtocolVersion = HttpVersion.Version10; 52 | request.Method = "GET"; 53 | request.Timeout = 30000; 54 | response = (HttpWebResponse)request.GetResponse(); 55 | reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); 56 | result = reader.ReadToEnd(); 57 | return result; 58 | } 59 | 60 | public String doRequest(String api, String requestType, String url, Dictionary arguments) 61 | { 62 | string result = ""; 63 | String postData = ""; 64 | if (arguments.Count > 0) 65 | { 66 | foreach (var str in arguments) 67 | { 68 | if (postData.Length > 0) 69 | { 70 | postData += "&"; 71 | } 72 | postData += str.Key + "=" + str.Value; 73 | } 74 | } 75 | request = (HttpWebRequest)WebRequest.Create(url); 76 | request.Method = requestType; 77 | request.ContentType = "application/x-www-form-urlencoded"; 78 | request.Headers.Add("Key", KEY); 79 | request.Headers.Add("Sign", (String)GetHMACSHA512.hash_hmac(postData, SECRET)); 80 | StringBuilder builder = new StringBuilder(); 81 | int i = 0; 82 | foreach (var item in arguments) 83 | { 84 | if (i > 0) 85 | builder.Append("&"); 86 | builder.AppendFormat("{0}={1}", item.Key, item.Value); 87 | i++; 88 | } 89 | byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); 90 | request.ContentLength = data.Length; 91 | using (Stream reqStream = request.GetRequestStream()) 92 | { 93 | reqStream.Write(data, 0, data.Length); 94 | reqStream.Close(); 95 | } 96 | HttpWebResponse resp = (HttpWebResponse)request.GetResponse(); 97 | Stream stream = resp.GetResponseStream(); 98 | //获取响应内容 99 | using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) 100 | { 101 | result = reader.ReadToEnd(); 102 | } 103 | return result; 104 | 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /csharp/src/com/gate/rest/stock/IStockRestApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.IO; 7 | using System.Web; 8 | using System.Net; 9 | using Com.Gate.Rest; 10 | 11 | namespace Com.Gate.Rest.Stock 12 | { 13 | public interface IStockRestApi 14 | { 15 | String pairs(); 16 | String marketinfo(); 17 | String marketlist(); 18 | String tickers(); 19 | String ticker(String symbol); 20 | String orderBook(String symbol); 21 | String tradeHistory(String symbol); 22 | String balance(); 23 | String depositAddress(String symbol); 24 | String depositsWithdrawals(String startTime, String endTime); 25 | String buy(String currencyPair, String rate, String amount); 26 | String sell(String currencyPair, String rate, String amount); 27 | String cancelOrder(String orderNumber, String currencyPair); 28 | String cancelOrders(String ordersJson) ; 29 | String cancelAllOrders(String type, String currencyPair); 30 | String getOrder(String orderNumber, String currencyPair); 31 | String openOrders(); 32 | String openOrders(String currencyPair); 33 | String myTradeHistory(String currencyPair); 34 | String myTradeHistory(String currencyPair, String orderNumber); 35 | String withdraw(String currency, String amount, String address); 36 | String candlestick2(String symbol, String groupSec, String rangeHour); 37 | } 38 | 39 | class StockRestApi : IStockRestApi 40 | { 41 | private String url_prex; 42 | 43 | public StockRestApi(String url_prex) 44 | { 45 | this.url_prex = url_prex; 46 | } 47 | 48 | public const String PAIRS_URL = "/api2/1/pairs"; 49 | 50 | 51 | public const String MARKETINFO_URL = "/api2/1/marketinfo"; 52 | 53 | 54 | public const String MARKETLIST_URL = "/api2/1/marketlist"; 55 | 56 | 57 | public const String TICKERS_URL = "/api2/1/tickers"; 58 | 59 | 60 | public const String TICKER_URL = "/api2/1/ticker"; 61 | 62 | 63 | public const String ORDERBOOK_URL = "/api2/1/orderBook"; 64 | 65 | 66 | public const String BALANCE_URL = "/api2/1/private/balances"; 67 | 68 | 69 | private const String DEPOSITADDRESS_URL = "/api2/1/private/depositAddress"; 70 | 71 | 72 | private const String DEPOSITESWITHDRAWALS_URL = "/api2/1/private/depositsWithdrawals"; 73 | 74 | 75 | private const String BUY_URL = "/api2/1/private/buy"; 76 | 77 | 78 | private const String SELL_URL = "/api2/1/private/sell"; 79 | 80 | 81 | private const String CANCELORDER_URL = "/api2/1/private/cancelOrder"; 82 | 83 | private const String CANCELORDERS_URL = "/api2/1/private/cancelOrders"; 84 | 85 | private const String CANDLESTICK2_URL = "/api2/1/candlestick2/"; 86 | 87 | private const String CANCELALLORDERS_URL = "/api2/1/private/cancelAllOrders"; 88 | 89 | 90 | private const String GETORDER_URL = "/api2/1/private/getOrder"; 91 | 92 | 93 | private const String OPENORDERS_URL = "/api2/1/private/openOrders"; 94 | 95 | 96 | private const String TRADEHISTORY_URL = "/api2/1/tradeHistory"; 97 | 98 | 99 | private const String WITHDRAW_URL = "/api2/1/private/withdraw"; 100 | 101 | 102 | private const String MYTRADEHISTORY_URL = "/api2/1/private/tradeHistory"; 103 | 104 | 105 | public String pairs() 106 | { 107 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 108 | String param = ""; 109 | String result = httpUtil.requestHttpGet(url_prex, PAIRS_URL, param); 110 | return result; 111 | } 112 | 113 | public String marketinfo() 114 | { 115 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 116 | String param = ""; 117 | String result = httpUtil.requestHttpGet(url_prex, MARKETINFO_URL, param); 118 | return result; 119 | } 120 | 121 | public String marketlist() 122 | { 123 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 124 | String param = ""; 125 | String result = httpUtil.requestHttpGet(url_prex, MARKETLIST_URL, param); 126 | return result; 127 | } 128 | 129 | public String tickers() 130 | { 131 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 132 | String param = ""; 133 | String result = httpUtil.requestHttpGet(url_prex, TICKERS_URL, param); 134 | return result; 135 | } 136 | 137 | public String ticker(String symbol) 138 | { 139 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 140 | String param = ""; 141 | 142 | param += "/" + symbol; 143 | 144 | String result = httpUtil.requestHttpGet(url_prex, TICKER_URL + param, ""); 145 | return result; 146 | } 147 | 148 | public String orderBook(String symbol) 149 | { 150 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 151 | String param = ""; 152 | if (!String.IsNullOrWhiteSpace(param)) 153 | { 154 | if (String.Compare("", param) == 0) 155 | { 156 | param += "/"; 157 | } 158 | param += symbol; 159 | } 160 | String result = httpUtil.requestHttpGet(url_prex, ORDERBOOK_URL + param, param); 161 | return result; 162 | } 163 | 164 | public String tradeHistory(String symbol) 165 | { 166 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 167 | String param = ""; 168 | if (String.IsNullOrWhiteSpace(param)) 169 | { 170 | if (String.Compare("", param) == 0) 171 | { 172 | param += "/"; 173 | } 174 | param += symbol; 175 | } 176 | String result = httpUtil.requestHttpGet(url_prex, TRADEHISTORY_URL + param, ""); 177 | return result; 178 | } 179 | 180 | public String balance() 181 | { 182 | Dictionary Params = new Dictionary(); 183 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 184 | String result = httpUtil.doRequest("data", "post", url_prex + BALANCE_URL, Params ); 185 | return result; 186 | } 187 | 188 | public String depositAddress(String symbol) 189 | { 190 | 191 | Dictionary Params = new Dictionary(); 192 | 193 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 194 | String result = httpUtil.doRequest("data", "post", url_prex + DEPOSITADDRESS_URL, Params ); 195 | return result; 196 | } 197 | 198 | public String depositsWithdrawals(String startTime, String endTime) 199 | { 200 | 201 | Dictionary Params = new Dictionary(); 202 | Params.Add("start", startTime); 203 | Params.Add("end", endTime); 204 | 205 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 206 | String result = httpUtil.doRequest("data", "post", url_prex + DEPOSITESWITHDRAWALS_URL, Params); 207 | return result; 208 | } 209 | 210 | public String buy(String currencyPair, String rate, String amount) 211 | { 212 | 213 | Dictionary Params = new Dictionary(); 214 | Params.Add("currencyPair", currencyPair); 215 | Params.Add("rate", rate); 216 | Params.Add("amount", amount); 217 | 218 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 219 | String result = httpUtil.doRequest("data", "post", url_prex + BUY_URL, Params); 220 | return result; 221 | } 222 | 223 | public String sell(String currencyPair, String rate, String amount) 224 | { 225 | 226 | Dictionary Params = new Dictionary(); 227 | Params.Add("currencyPair", currencyPair); 228 | Params.Add("rate", rate); 229 | Params.Add("amount", amount); 230 | 231 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 232 | String result = httpUtil.doRequest("data", "post", url_prex + SELL_URL, Params); 233 | return result; 234 | } 235 | 236 | public String cancelOrder(String orderNumber, String currencyPair) 237 | { 238 | 239 | Dictionary Params = new Dictionary(); 240 | Params.Add("orderNumber", orderNumber); 241 | Params.Add("currencyPair", currencyPair); 242 | 243 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 244 | String result = httpUtil.doRequest("data", "post", url_prex + CANCELORDER_URL, Params); 245 | return result; 246 | } 247 | 248 | public String cancelOrders(String orderJson) 249 | { 250 | 251 | Dictionary Params = new Dictionary(); 252 | Params.Add("orders_json", orderJson); 253 | 254 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 255 | String result = httpUtil.doRequest("data", "post", url_prex + CANCELORDERS_URL, Params); 256 | return result; 257 | } 258 | 259 | public String cancelAllOrders(String type, String currencyPair) 260 | { 261 | 262 | Dictionary Params = new Dictionary(); 263 | Params.Add("type", type); 264 | Params.Add("currencyPair", currencyPair); 265 | 266 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 267 | String result = httpUtil.doRequest("data", "post", url_prex + CANCELALLORDERS_URL, Params); 268 | return result; 269 | } 270 | 271 | public String getOrder(String orderNumber, String currencyPair) 272 | { 273 | 274 | Dictionary Params = new Dictionary(); 275 | Params.Add("orderNumber", orderNumber); 276 | Params.Add("currencyPair", currencyPair); 277 | 278 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 279 | String result = httpUtil.doRequest("data", "post", url_prex + GETORDER_URL, Params); 280 | return result; 281 | } 282 | 283 | public String openOrders() 284 | { 285 | 286 | Dictionary Params = new Dictionary(); 287 | 288 | 289 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 290 | String result = httpUtil.doRequest("data", "post", url_prex + OPENORDERS_URL, Params); 291 | return result; 292 | } 293 | 294 | public String openOrders(String currencyPair) 295 | { 296 | if(currencyPair==null||"".Equals(currencyPair)) 297 | { 298 | return openOrders(); 299 | } 300 | else 301 | { 302 | Dictionary Params = new Dictionary(); 303 | Params.Add("currencyPair", currencyPair); 304 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 305 | String result = httpUtil.doRequest("data", "post", url_prex + OPENORDERS_URL, Params); 306 | return result; 307 | } 308 | } 309 | 310 | public String myTradeHistory(String currencyPair) 311 | { 312 | 313 | Dictionary Params = new Dictionary(); 314 | Params.Add("currencyPair", currencyPair); 315 | 316 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 317 | String result = httpUtil.doRequest("data", "post", url_prex + MYTRADEHISTORY_URL, Params); 318 | return result; 319 | } 320 | 321 | public String myTradeHistory(String currencyPair, String orderNumber) 322 | { 323 | if(orderNumber==null||"".Equals(orderNumber)) 324 | { 325 | return myTradeHistory(currencyPair); 326 | } 327 | else 328 | { 329 | Dictionary Params = new Dictionary(); 330 | Params.Add("currencyPair", currencyPair); 331 | Params.Add("orderNumber", orderNumber); 332 | 333 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 334 | String result = httpUtil.doRequest("data", "post", url_prex + MYTRADEHISTORY_URL, Params); 335 | return result; 336 | } 337 | } 338 | 339 | public String withdraw(String currency, String amount, String address) 340 | { 341 | 342 | Dictionary Params = new Dictionary(); 343 | Params.Add("currency", currency); 344 | Params.Add("amount", amount); 345 | Params.Add("address", address); 346 | 347 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 348 | String result = httpUtil.doRequest("data", "post", url_prex + WITHDRAW_URL, Params); 349 | return result; 350 | } 351 | 352 | public String candlestick2(String symbol, String groupSec, String rangeHour) 353 | { 354 | 355 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 356 | String param = ""; 357 | if ((!"".Equals(symbol))&&symbol != null) 358 | { 359 | param += symbol; 360 | if((!"".Equals(groupSec)) && groupSec != null) 361 | { 362 | param += "?group_sec=" + groupSec; 363 | if((!"".Equals(rangeHour)) && rangeHour != null) 364 | { 365 | param += "&range_hour=" + rangeHour; 366 | } 367 | } 368 | else { 369 | if((!"".Equals(rangeHour)) && rangeHour != null) 370 | { 371 | param += "?range_hour=" + rangeHour; 372 | } 373 | } 374 | } 375 | String result = httpUtil.doRequest("data","POST", url_prex + CANDLESTICK2_URL + param, new Dictionary()); 376 | return result; 377 | } 378 | 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /csharp/src/com/gate/rest/test/StockRestApiTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Com.Gate.Rest.Stock; 7 | using Com.Gate.Rest; 8 | 9 | namespace Com.Gate.Rest.Test 10 | { 11 | class StockRestApiTest 12 | { 13 | private static String QURL = "https://data.gateio.life"; 14 | private static String TURL = "https://api.gateio.life"; 15 | private static IStockRestApi stockGet = new StockRestApi(QURL); 16 | private static IStockRestApi stockPost = new StockRestApi(TURL); 17 | 18 | static void Main(string[] args) 19 | { 20 | Console.Write(testMyTradeHistory("eth_usdt", "12345")); 21 | } 22 | 23 | private String testPairs() 24 | { 25 | String pairs = stockGet.pairs(); 26 | return pairs; 27 | } 28 | 29 | private String testMarketlist() 30 | { 31 | String marketlist = stockGet.marketlist(); 32 | return marketlist; 33 | } 34 | 35 | private String testTickers() 36 | { 37 | String tickers = stockGet.tickers(); 38 | return tickers; 39 | } 40 | 41 | private String testTicker(String symbol) 42 | { 43 | String ticker = stockGet.ticker(symbol); 44 | return ticker; 45 | } 46 | 47 | private String testOrderBooks(String symbol) 48 | { 49 | String orderBooks = stockGet.orderBook(symbol); 50 | return orderBooks; 51 | } 52 | 53 | private String testTradeHistory(String symbol) 54 | { 55 | String tradeHistory = stockGet.tradeHistory(symbol); 56 | return tradeHistory; 57 | } 58 | 59 | private String testBalances() 60 | { 61 | String balance = stockPost.balance(); 62 | return balance; 63 | } 64 | 65 | private String testDepositAddress(String symbol) 66 | { 67 | String depositAddress = stockPost.depositAddress(symbol); 68 | return depositAddress; 69 | } 70 | 71 | private String testDepositsWithdrawals(String startTime, String endTime) 72 | { 73 | String depositsWithdrawals = depositsWithdrawals = stockPost.depositsWithdrawals(startTime, endTime); 74 | return depositsWithdrawals; 75 | } 76 | 77 | private String testBuy(String currencyPair, String rate, String amount) 78 | { 79 | String buy = stockPost.buy(currencyPair, rate, amount); 80 | return buy; 81 | } 82 | 83 | private String testSell(String currencyPair, String rate, String amount) 84 | { 85 | String sell = stockPost.sell(currencyPair, rate, amount); 86 | return sell; 87 | } 88 | 89 | private String testCancelOrder(String orderNumber, String currencyPair) 90 | { 91 | String cancelOrder = stockPost.cancelOrder(orderNumber, currencyPair); 92 | return cancelOrder; 93 | } 94 | 95 | private String testCancelOrders(String ordersJson) 96 | { 97 | String cancelOrder = stockPost.cancelOrders(ordersJson); ; 98 | return cancelOrder; 99 | } 100 | 101 | private String testCancelAllOrders(String type, String currencyPair) 102 | { 103 | String cancelAllOrders = stockPost.cancelAllOrders(type, currencyPair); 104 | return cancelAllOrders; 105 | } 106 | 107 | private String testGetOrder(String orderNumber, String currencyPair) 108 | { 109 | String getOrder = stockPost.getOrder(orderNumber, currencyPair); 110 | return getOrder; 111 | } 112 | 113 | private String testOpenOrders(String currencyPair) 114 | { 115 | String openOrders = stockPost.openOrders(currencyPair); 116 | return openOrders; 117 | } 118 | 119 | private static String testMyTradeHistory(String currencyPair, String orderNumber) 120 | { 121 | String myTradeHistory = stockPost.myTradeHistory(currencyPair, orderNumber); 122 | return myTradeHistory; 123 | } 124 | 125 | private static String testWithdraw(String currency, String amount, String address) 126 | { 127 | String withdraw = stockPost.withdraw(currency, amount, address); 128 | return withdraw; 129 | } 130 | 131 | private String testCandlestick2(String symbol, String groupSec, String rangeHour) 132 | { 133 | String candlestick2 = stockGet.candlestick2(symbol, groupSec, rangeHour); 134 | return candlestick2; 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /go/gateioApi.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/hmac" 5 | "crypto/sha512" 6 | // "encoding/hex" 7 | // "encoding/json" 8 | "net/http" 9 | // "net/url" 10 | // "sort" 11 | "io/ioutil" 12 | "strings" 13 | "fmt" 14 | ) 15 | 16 | const KEY = "your api key"; // gate.io api key 17 | const SECRET = "your api secret"; // gate.io api secret 18 | 19 | func main() { 20 | 21 | // Method call 22 | 23 | // all pairs 24 | var ret string = getPairs() 25 | fmt.Println(ret) 26 | 27 | 28 | 29 | } 30 | 31 | // all support pairs 32 | func getPairs() string { 33 | var method string = "GET" 34 | var url string = "http://data.gateio.life/api2/1/pairs" 35 | var param string = "" 36 | var ret string = httpDo(method,url,param) 37 | return ret 38 | } 39 | 40 | // Market Info 41 | func marketinfo() string { 42 | var method string = "GET" 43 | var url string = "http://data.gateio.life/api2/1/marketinfo" 44 | var param string = "" 45 | var ret string = httpDo(method,url,param) 46 | return ret 47 | } 48 | 49 | 50 | // Market Details 51 | func marketlist() string { 52 | var method string = "GET" 53 | var url string = "http://data.gateio.life/api2/1/marketlist" 54 | var param string = "" 55 | var ret string = httpDo(method,url,param) 56 | return ret 57 | } 58 | 59 | 60 | // tickers 61 | func tickers() string { 62 | var method string = "GET" 63 | var url string = "http://data.gateio.life/api2/1/tickers" 64 | var param string = "" 65 | var ret string = httpDo(method,url,param) 66 | return ret 67 | } 68 | 69 | 70 | // ticker 71 | func ticker(ticker string) string { 72 | var method string = "GET" 73 | var url string = "http://data.gateio.life/api2/1/ticker" + "/" + ticker 74 | var param string = "" 75 | var ret string = httpDo(method,url,param) 76 | return ret 77 | } 78 | 79 | 80 | // Depth 81 | func orderBooks() string { 82 | var method string = "GET" 83 | var url string = "http://data.gateio.life/api2/1/orderBooks" 84 | var param string = "" 85 | var ret string = httpDo(method,url,param) 86 | return ret 87 | } 88 | 89 | 90 | // Depth of pair 91 | func orderBook(params string) string { 92 | var method string = "GET" 93 | var url string = "http://data.gateio.life/api2/1/orderBook/" + params 94 | var param string = "" 95 | var ret string = httpDo(method,url,param) 96 | return ret 97 | } 98 | 99 | 100 | // Trade History 101 | func tradeHistory(params string) string { 102 | var method string = "GET" 103 | var url string = "http://data.gateio.life/api2/1/tradeHistory/" + params 104 | var param string = "" 105 | var ret string = httpDo(method,url,param) 106 | return ret 107 | } 108 | 109 | 110 | // Get account fund balances 111 | func balances() string { 112 | var method string = "POST" 113 | var url string = "https://api.gateio.life/api2/1/private/balances" 114 | var param string = "" 115 | var ret string = httpDo(method,url,param) 116 | return ret 117 | } 118 | 119 | 120 | 121 | // get deposit address 122 | func depositAddress(currency string) string { 123 | var method string = "POST" 124 | var url string = "https://api.gateio.life/api2/1/private/depositAddress" 125 | var param string = "currency=" + currency 126 | var ret string = httpDo(method,url,param) 127 | return ret 128 | } 129 | 130 | 131 | // get deposit withdrawal history 132 | func depositsWithdrawals(start string, end string) string { 133 | var method string = "POST" 134 | var url string = "https://api.gateio.life/api2/1/private/depositsWithdrawals" 135 | var param string = "start=" + start + "&end=" + end 136 | var ret string = httpDo(method,url,param) 137 | return ret 138 | } 139 | 140 | 141 | // Place order buy 142 | func buy(currencyPair string, rate string, amount string) string { 143 | var method string = "POST" 144 | var url string = "https://api.gateio.life/api2/1/private/buy" 145 | var param string = "currencyPair=" + currencyPair + "&rate=" + rate + "&amount=" + amount 146 | var ret string = httpDo(method,url,param) 147 | return ret 148 | } 149 | 150 | // Place order sell 151 | func sell(currencyPair string, rate string, amount string) string { 152 | var method string = "POST" 153 | var url string = "https://api.gateio.life/api2/1/private/sell" 154 | var param string = "currencyPair=" + currencyPair + "&rate=" + rate + "&amount=" + amount 155 | var ret string = httpDo(method,url,param) 156 | return ret 157 | } 158 | 159 | 160 | // Cancel order 161 | func cancelOrder(orderNumber string, currencyPair string ) string { 162 | var method string = "POST" 163 | var url string = "https://api.gateio.life/api2/1/private/cancelOrder" 164 | var param string = "orderNumber=" + orderNumber + "¤cyPair=" + currencyPair 165 | var ret string = httpDo(method,url,param) 166 | return ret 167 | } 168 | 169 | // Cancel all orders 170 | func cancelAllOrders( types string, currencyPair string ) string { 171 | var method string = "POST" 172 | var url string = "https://api.gateio.life/api2/1/private/cancelAllOrders" 173 | var param string = "type=" + types + "¤cyPair=" + currencyPair 174 | var ret string = httpDo(method,url,param) 175 | return ret 176 | } 177 | 178 | 179 | // Get order status 180 | func getOrder( orderNumber string, currencyPair string ) string { 181 | var method string = "POST" 182 | var url string = "https://api.gateio.life/api2/1/private/getOrder" 183 | var param string = "orderNumber=" + orderNumber + "¤cyPair=" + currencyPair 184 | var ret string = httpDo(method,url,param) 185 | return ret 186 | } 187 | 188 | 189 | // Get my open order list 190 | func openOrders() string { 191 | var method string = "POST" 192 | var url string = "https://api.gateio.life/api2/1/private/openOrders" 193 | var param string = "" 194 | var ret string = httpDo(method,url,param) 195 | return ret 196 | } 197 | 198 | 199 | // 获取我的24小时内成交记录 200 | func myTradeHistory( currencyPair string, orderNumber string) string { 201 | var method string = "POST" 202 | var url string = "https://api.gateio.life/api2/1/private/tradeHistory" 203 | var param string = "orderNumber=" + orderNumber + "¤cyPair=" + currencyPair 204 | var ret string = httpDo(method,url,param) 205 | return ret 206 | } 207 | 208 | 209 | // Get my last 24h trades 210 | func withdraw( currency string, amount string, address string) string { 211 | var method string = "POST" 212 | var url string = "https://api.gateio.life/api2/1/private/withdraw" 213 | var param string = "currency=" + currency + "&amount=" + amount + "&address=" + address 214 | var ret string = httpDo(method,url,param) 215 | return ret 216 | } 217 | 218 | 219 | func getSign( params string) string { 220 | key := []byte(SECRET) 221 | mac := hmac.New(sha512.New, key) 222 | mac.Write([]byte(params)) 223 | return fmt.Sprintf("%x", mac.Sum(nil)) 224 | } 225 | 226 | /** 227 | * http request 228 | */ 229 | func httpDo(method string,url string, param string) string { 230 | client := &http.Client{} 231 | 232 | req, err := http.NewRequest(method, url, strings.NewReader(param)) 233 | if err != nil { 234 | // handle error 235 | } 236 | var sign string = getSign(param) 237 | 238 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") 239 | req.Header.Set("key", KEY) 240 | req.Header.Set("sign", sign) 241 | 242 | resp, err := client.Do(req) 243 | 244 | defer resp.Body.Close() 245 | 246 | body, err := ioutil.ReadAll(resp.Body) 247 | if err != nil { 248 | // handle error 249 | } 250 | 251 | return string(body); 252 | } 253 | -------------------------------------------------------------------------------- /java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gateio_rest_java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /java/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/com/gate/rest/FutureClient.java=UTF-8 3 | encoding//src/com/gate/rest/MD5Util.java=UTF-8 4 | encoding//src/com/gate/rest/StockClient.java=UTF-8 5 | encoding//src/com/gate/rest/stock/IStockRestApi.java=UTF-8 6 | encoding//src/com/gate/rest/stock/impl/StockRestApi.java=UTF-8 7 | -------------------------------------------------------------------------------- /java/ReadMe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/ReadMe -------------------------------------------------------------------------------- /java/lib/commons-codec-1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/commons-codec-1.7.jar -------------------------------------------------------------------------------- /java/lib/commons-io-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/commons-io-2.2.jar -------------------------------------------------------------------------------- /java/lib/commons-logging-1.0.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/commons-logging-1.0.4.jar -------------------------------------------------------------------------------- /java/lib/fastjson-1.1.23.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/fastjson-1.1.23.jar -------------------------------------------------------------------------------- /java/lib/httpclient-4.3.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/httpclient-4.3.6.jar -------------------------------------------------------------------------------- /java/lib/httpcore-4.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/httpcore-4.3.3.jar -------------------------------------------------------------------------------- /java/lib/jackson-annotations-2.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/jackson-annotations-2.0.2.jar -------------------------------------------------------------------------------- /java/lib/jackson-core-2.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/jackson-core-2.0.2.jar -------------------------------------------------------------------------------- /java/lib/jackson-databind-2.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/jackson-databind-2.0.2.jar -------------------------------------------------------------------------------- /java/lib/json-20140107.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gateio/rest-v2/139d4c0a2efb6128952cccb8c3cb94240c3c7154/java/lib/json-20140107.jar -------------------------------------------------------------------------------- /java/src/com/gate/rest/HttpUtilManager.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.io.UnsupportedEncodingException; 8 | import java.security.InvalidKeyException; 9 | import java.security.NoSuchAlgorithmException; 10 | import java.util.ArrayList; 11 | import java.util.Iterator; 12 | import java.util.LinkedList; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.Map.Entry; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | import javax.crypto.Mac; 19 | import javax.crypto.spec.SecretKeySpec; 20 | 21 | import org.apache.commons.codec.binary.Hex; 22 | import org.apache.commons.io.IOUtils; 23 | import org.apache.http.Consts; 24 | import org.apache.http.Header; 25 | import org.apache.http.HttpEntity; 26 | import org.apache.http.HttpException; 27 | import org.apache.http.HttpResponse; 28 | import org.apache.http.NameValuePair; 29 | import org.apache.http.client.HttpClient; 30 | import org.apache.http.client.config.RequestConfig; 31 | import org.apache.http.client.entity.UrlEncodedFormEntity; 32 | import org.apache.http.client.methods.HttpGet; 33 | import org.apache.http.client.methods.HttpPost; 34 | import org.apache.http.client.methods.HttpRequestBase; 35 | import org.apache.http.conn.ConnectionKeepAliveStrategy; 36 | import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; 37 | import org.apache.http.impl.client.HttpClientBuilder; 38 | import org.apache.http.impl.client.HttpClients; 39 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 40 | import org.apache.http.message.BasicHeader; 41 | import org.apache.http.message.BasicNameValuePair; 42 | import org.apache.http.protocol.HttpContext; 43 | import org.json.JSONObject; 44 | 45 | 46 | 47 | public class HttpUtilManager { 48 | 49 | private static String SECRET = "your secret"; 50 | private static String KEY = "your key"; 51 | 52 | private static HttpUtilManager instance = new HttpUtilManager(); 53 | private static HttpClient client; 54 | private static long startTime = System.currentTimeMillis(); 55 | public static PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); 56 | private static ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy() { 57 | 58 | public long getKeepAliveDuration( 59 | HttpResponse response, 60 | HttpContext context) { 61 | long keepAlive = super.getKeepAliveDuration(response, context); 62 | 63 | if (keepAlive == -1) { 64 | keepAlive = 5000; 65 | } 66 | return keepAlive; 67 | } 68 | 69 | }; 70 | private HttpUtilManager() { 71 | client = HttpClients.custom().setConnectionManager(cm).setKeepAliveStrategy(keepAliveStrat).build(); 72 | } 73 | 74 | public static void IdleConnectionMonitor(){ 75 | 76 | if(System.currentTimeMillis()-startTime>30000){ 77 | startTime = System.currentTimeMillis(); 78 | cm.closeExpiredConnections(); 79 | cm.closeIdleConnections(30, TimeUnit.SECONDS); 80 | } 81 | } 82 | 83 | private static RequestConfig requestConfig = RequestConfig.custom() 84 | .setSocketTimeout(20000) 85 | .setConnectTimeout(20000) 86 | .setConnectionRequestTimeout(20000) 87 | .build(); 88 | 89 | 90 | public static HttpUtilManager getInstance() { 91 | return instance; 92 | } 93 | 94 | public HttpClient getHttpClient() { 95 | return client; 96 | } 97 | 98 | private HttpPost httpPostMethod(String url) { 99 | return new HttpPost(url); 100 | } 101 | 102 | private HttpRequestBase httpGetMethod(String url) { 103 | return new HttpGet(url); 104 | } 105 | 106 | public String requestHttpGet(String url_prex,String url,String param) throws HttpException, IOException{ 107 | 108 | IdleConnectionMonitor(); 109 | url=url_prex+url; 110 | if(param!=null && !param.equals("")){ 111 | if(url.endsWith("?")){ 112 | url = url+param; 113 | }else{ 114 | url = url+"?"+param; 115 | } 116 | } 117 | HttpRequestBase method = this.httpGetMethod(url); 118 | method.setConfig(requestConfig); 119 | HttpResponse response = client.execute(method); 120 | HttpEntity entity = response.getEntity(); 121 | if(entity == null){ 122 | return ""; 123 | } 124 | InputStream is = null; 125 | String responseData = ""; 126 | try{ 127 | is = entity.getContent(); 128 | responseData = IOUtils.toString(is, "UTF-8"); 129 | }finally{ 130 | if(is!=null){ 131 | is.close(); 132 | } 133 | } 134 | return responseData; 135 | } 136 | 137 | public String requestHttpPost(String url_prex,String url,Map params) throws HttpException, IOException{ 138 | 139 | IdleConnectionMonitor(); 140 | url=url_prex+url; 141 | 142 | 143 | HttpPost method = this.httpPostMethod(url); 144 | List valuePairs = this.convertMap2PostParams(params); 145 | 146 | 147 | UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(valuePairs, Consts.UTF_8); 148 | method.setEntity(urlEncodedFormEntity); 149 | method.setConfig(requestConfig); 150 | System.out.println(method); 151 | HttpResponse response = client.execute(method); 152 | HttpEntity entity = response.getEntity(); 153 | if(entity == null){ 154 | return ""; 155 | } 156 | InputStream is = null; 157 | String responseData = ""; 158 | try{ 159 | is = entity.getContent(); 160 | responseData = IOUtils.toString(is, "UTF-8"); 161 | }finally{ 162 | if(is!=null){ 163 | is.close(); 164 | } 165 | } 166 | return responseData; 167 | 168 | } 169 | 170 | private List convertMap2PostParams(Map params){ 171 | List keys = new ArrayList(params.keySet()); 172 | if(keys.isEmpty()){ 173 | return null; 174 | } 175 | int keySize = keys.size(); 176 | List data = new LinkedList() ; 177 | for(int i=0;i arguments ) throws HttpException, IOException{ 187 | 188 | List< NameValuePair > urlParameters = new ArrayList< NameValuePair >( ); 189 | 190 | Mac mac = null; 191 | SecretKeySpec key = null; 192 | 193 | String postData = ""; 194 | 195 | for ( Iterator< Entry< String, String >> argumentIterator = arguments.entrySet( ).iterator( ); argumentIterator.hasNext( ); ) { 196 | 197 | Map.Entry< String, String > argument = argumentIterator.next( ); 198 | 199 | urlParameters.add( new BasicNameValuePair( argument.getKey( ).toString( ), argument.getValue( ).toString( ) ) ); 200 | 201 | if ( postData.length( ) > 0 ) { 202 | postData += "&"; 203 | } 204 | 205 | postData += argument.getKey( ) + "=" + argument.getValue( ); 206 | 207 | } 208 | 209 | // Create a new secret key 210 | try { 211 | key = new SecretKeySpec( SECRET.getBytes( "UTF-8" ), "HmacSHA512" ); 212 | } catch ( UnsupportedEncodingException uee ) { 213 | System.err.println( "Unsupported encoding exception: " + uee.toString( ) ); 214 | } 215 | 216 | try { 217 | mac = Mac.getInstance( "HmacSHA512" ); 218 | } catch ( NoSuchAlgorithmException nsae ) { 219 | System.err.println( "No such algorithm exception: " + nsae.toString( ) ); 220 | } 221 | 222 | try { 223 | mac.init( key ); 224 | } catch ( InvalidKeyException ike ) { 225 | System.err.println( "Invalid key exception: " + ike.toString( ) ); 226 | } 227 | 228 | // add header 229 | Header[] headers = new Header[ 2 ]; 230 | headers[ 0 ] = new BasicHeader( "Key", KEY ); 231 | headers[ 1 ] = new BasicHeader( "Sign", Hex.encodeHexString( mac.doFinal( postData.getBytes( "UTF-8" ) ) ) ); 232 | 233 | 234 | HttpClient client = HttpClientBuilder.create( ).build( ); 235 | HttpPost post = null; 236 | HttpGet get = null; 237 | HttpResponse response = null; 238 | 239 | if ( requestType == "post" ) { 240 | post = new HttpPost( url ); 241 | post.setEntity( new UrlEncodedFormEntity( urlParameters ) ); 242 | post.setHeaders( headers ); 243 | response = client.execute( post ); 244 | } else if ( requestType == "get" ) { 245 | get = new HttpGet( url ); 246 | get.setHeaders( headers ); 247 | response = client.execute( get ); 248 | } 249 | 250 | HttpEntity entity = response.getEntity(); 251 | if(entity == null){ 252 | return ""; 253 | } 254 | InputStream is = null; 255 | String responseData = ""; 256 | 257 | is = entity.getContent(); 258 | responseData = IOUtils.toString(is, "UTF-8"); 259 | return responseData; 260 | 261 | 262 | } 263 | 264 | } 265 | 266 | -------------------------------------------------------------------------------- /java/src/com/gate/rest/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class MD5Util { 11 | 12 | public static String buildMysignV1(Map sArray, 13 | String secretKey) { 14 | String mysign = ""; 15 | try { 16 | String prestr = createLinkString(sArray); 17 | prestr = prestr + "&secret_key=" + secretKey; 18 | mysign = getMD5String(prestr); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | return mysign; 23 | } 24 | 25 | public static String buildMysign(Map sArray, 26 | String secretKey) { 27 | String mysign = ""; 28 | try { 29 | String prestr = createLinkString(sArray); 30 | prestr = prestr + secretKey; 31 | mysign = getMD5String(prestr); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | return mysign; 36 | } 37 | 38 | public static String createLinkString(Map params) { 39 | 40 | List keys = new ArrayList(params.keySet()); 41 | Collections.sort(keys); 42 | String prestr = ""; 43 | for (int i = 0; i < keys.size(); i++) { 44 | String key = keys.get(i); 45 | String value = params.get(key); 46 | if (i == keys.size() - 1) { 47 | prestr = prestr + key + "=" + value; 48 | } else { 49 | prestr = prestr + key + "=" + value + "&"; 50 | } 51 | } 52 | return prestr; 53 | } 54 | 55 | private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', 56 | '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 57 | 58 | public static String getMD5String(String str) { 59 | try { 60 | if (str == null || str.trim().length() == 0) { 61 | return ""; 62 | } 63 | byte[] bytes = str.getBytes(); 64 | MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 65 | messageDigest.update(bytes); 66 | bytes = messageDigest.digest(); 67 | StringBuilder sb = new StringBuilder(); 68 | for (int i = 0; i < bytes.length; i++) { 69 | sb.append(HEX_DIGITS[(bytes[i] & 0xf0) >> 4] + "" 70 | + HEX_DIGITS[bytes[i] & 0xf]); 71 | } 72 | return sb.toString(); 73 | } catch (NoSuchAlgorithmException e) { 74 | e.printStackTrace(); 75 | } 76 | return ""; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /java/src/com/gate/rest/StockClient.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.HttpException; 6 | 7 | import com.alibaba.fastjson.JSONObject; 8 | import com.gate.rest.stock.IStockRestApi; 9 | import com.gate.rest.stock.impl.StockRestApi; 10 | 11 | 12 | public class StockClient { 13 | 14 | public static void main(String[] args) throws HttpException, IOException { 15 | 16 | 17 | String query_url = "https://data.gateio.life"; 18 | String trade_url = "https://api.gateio.life"; 19 | 20 | 21 | IStockRestApi stockGet = new StockRestApi(query_url); 22 | 23 | IStockRestApi stockPost = new StockRestApi(trade_url); 24 | 25 | // All trading Pairs 26 | String pairs = stockGet.pairs(); 27 | System.out.println(pairs); 28 | 29 | // Market Info 30 | // String marketinfo = stockGet.marketinfo(); 31 | // System.out.println(marketinfo); 32 | 33 | // Market Details 34 | // String marketlist = stockGet.marketlist(); 35 | // System.out.println(marketlist); 36 | 37 | // Tickers 38 | // String tickers = stockGet.tickers(); 39 | // System.out.println(tickers); 40 | 41 | // Ticker 42 | // String ticker = stockGet.ticker("eth_btc"); 43 | // System.out.println(ticker); 44 | 45 | // Depth 46 | // String orderBook = stockGet.orderBook("eth_btc"); 47 | // System.out.println(orderBook); 48 | 49 | // Trade History 50 | // String tradeHistory = stockGet.tradeHistory("eth_btc"); 51 | // System.out.println(tradeHistory); 52 | 53 | // Get account fund balances 54 | // String balance = stockPost.balance(); 55 | // System.out.println(balance); 56 | 57 | // get deposit address 58 | // String depositAddress = stockPost.depositAddress("btc"); 59 | // System.out.println(depositAddress); 60 | 61 | // get deposit withdrawal history 62 | // String depositsWithdrawals = stockPost.depositsWithdrawals("1469092370", 63 | // "1669092370"); 64 | // System.out.println(depositsWithdrawals); 65 | 66 | // Place order buy 67 | // String buy = stockPost.buy("ltc_btc", "999","123"); 68 | // System.out.println(buy); 69 | 70 | // Place order sell 71 | // String sell = stockPost.sell("ltc_btc", "999","123"); 72 | // System.out.println(sell); 73 | 74 | // Cancel order 75 | // String cancelOrder = stockPost.cancelOrder("123456789", "ltc_btc"); 76 | // System.out.println(cancelOrder); 77 | 78 | // Cancel all orders 79 | // String cancelAllOrders = stockPost.cancelAllOrders("1", "ltc_btc"); 80 | // System.out.println(cancelAllOrders); 81 | 82 | // Get order status 83 | // String getOrder = stockPost.getOrder("123456789", "ltc_btc"); 84 | // System.out.println(getOrder); 85 | 86 | // Get my open order list 87 | // String openOrders = stockPost.openOrders(); 88 | // System.out.println(openOrders); 89 | 90 | // Get my last 24h trades 91 | // String myTradeHistory = stockPost.myTradeHistory("eth_btc","123456789"); 92 | // System.out.println(myTradeHistory); 93 | 94 | // withdrawal 95 | // String withdraw = stockPost.withdraw("btc","99","your addr"); 96 | // System.out.println(withdraw); 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /java/src/com/gate/rest/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest; 2 | 3 | public class StringUtil { 4 | 5 | public static boolean isEmpty(String str) { 6 | if(str == null) 7 | return true; 8 | String tempStr = str.trim(); 9 | if(tempStr.length() == 0) 10 | return true; 11 | if(tempStr.equals("null")) 12 | return true; 13 | return false; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java/src/com/gate/rest/stock/IStockRestApi.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest.stock; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.HttpException; 6 | 7 | 8 | public interface IStockRestApi { 9 | 10 | public String pairs() throws HttpException, IOException; 11 | public String marketinfo() throws HttpException, IOException; 12 | public String marketlist() throws HttpException, IOException; 13 | 14 | public String tickers() throws HttpException, IOException; 15 | public String ticker(String symbol) throws HttpException, IOException; 16 | public String orderBook(String symbol) throws HttpException, IOException; 17 | public String tradeHistory(String symbol) throws HttpException, IOException; 18 | public String balance() throws HttpException, IOException; 19 | public String depositAddress(String symbol) throws HttpException, IOException; 20 | public String depositsWithdrawals(String startTime,String endTime) throws HttpException, IOException; 21 | public String buy(String currencyPair,String rate, String amount) throws HttpException, IOException; 22 | public String sell(String currencyPair,String rate, String amount) throws HttpException, IOException; 23 | public String cancelOrder(String orderNumber, String currencyPair) throws HttpException, IOException; 24 | public String cancelAllOrders(String type, String currencyPair) throws HttpException, IOException; 25 | public String getOrder(String orderNumber, String currencyPair) throws HttpException, IOException; 26 | public String openOrders() throws HttpException, IOException; 27 | public String myTradeHistory(String currencyPair,String orderNumber) throws HttpException, IOException; 28 | public String withdraw(String currency,String amount, String address) throws HttpException, IOException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java/src/com/gate/rest/stock/impl/StockRestApi.java: -------------------------------------------------------------------------------- 1 | package com.gate.rest.stock.impl; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpException; 8 | 9 | 10 | import com.gate.rest.HttpUtilManager; 11 | import com.gate.rest.MD5Util; 12 | import com.gate.rest.StringUtil; 13 | import com.gate.rest.stock.IStockRestApi; 14 | 15 | 16 | public class StockRestApi implements IStockRestApi{ 17 | 18 | 19 | 20 | private String url_prex; 21 | 22 | 23 | 24 | public StockRestApi(String url_prex){ 25 | this.url_prex = url_prex; 26 | } 27 | 28 | 29 | 30 | public final String PAIRS_URL = "/api2/1/pairs"; 31 | 32 | 33 | public final String MARKETINFO_URL = "/api2/1/marketinfo"; 34 | 35 | 36 | public final String MARKETLIST_URL = "/api2/1/marketlist"; 37 | 38 | 39 | public final String TICKERS_URL = "/api2/1/tickers"; 40 | 41 | 42 | public final String TICKER_URL = "/api2/1/ticker"; 43 | 44 | 45 | public final String ORDERBOOK_URL = "/api2/1/orderBook"; 46 | 47 | 48 | public final String BALANCE_URL = "/api2/1/private/balances"; 49 | 50 | 51 | private final String DEPOSITADDRESS_URL = "/api2/1/private/depositAddress"; 52 | 53 | 54 | private final String DEPOSITESWITHDRAWALS_URL = "/api2/1/private/depositsWithdrawals"; 55 | 56 | 57 | private final String BUY_URL = "/api2/1/private/buy"; 58 | 59 | 60 | private final String SELL_URL = "/api2/1/private/sell"; 61 | 62 | 63 | private final String CANCELORDER_URL = "/api2/1/private/cancelOrder"; 64 | 65 | 66 | private final String CANCELALLORDERS_URL = "/api2/1/private/cancelAllOrders"; 67 | 68 | 69 | private final String GETORDER_URL = "/api2/1/private/getOrder"; 70 | 71 | 72 | private final String OPENORDERS_URL = "/api2/1/private/openOrders"; 73 | 74 | 75 | private final String TRADEHISTORY_URL = "/api2/1/tradeHistory"; 76 | 77 | 78 | private final String WITHDRAW_URL = "/api2/1/private/withdraw"; 79 | 80 | 81 | private final String MYTRADEHISTORY_URL = "/api2/1/private/tradeHistory"; 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | @Override 92 | public String pairs() throws HttpException, IOException { 93 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 94 | String param = ""; 95 | String result = httpUtil.requestHttpGet(url_prex, PAIRS_URL, param); 96 | return result; 97 | } 98 | 99 | @Override 100 | public String marketinfo() throws HttpException, IOException { 101 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 102 | String param = ""; 103 | String result = httpUtil.requestHttpGet(url_prex, MARKETINFO_URL, param); 104 | return result; 105 | } 106 | 107 | @Override 108 | public String marketlist() throws HttpException, IOException { 109 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 110 | String param = ""; 111 | String result = httpUtil.requestHttpGet(url_prex, MARKETLIST_URL, param); 112 | return result; 113 | } 114 | 115 | @Override 116 | public String tickers() throws HttpException, IOException { 117 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 118 | String param = ""; 119 | String result = httpUtil.requestHttpGet(url_prex, TICKERS_URL, param); 120 | return result; 121 | } 122 | 123 | @Override 124 | public String ticker(String symbol) throws HttpException, IOException { 125 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 126 | String param = ""; 127 | 128 | param += "/"+symbol; 129 | 130 | String result = httpUtil.requestHttpGet(url_prex, TICKER_URL + param, ""); 131 | return result; 132 | } 133 | 134 | @Override 135 | public String orderBook(String symbol) throws HttpException, IOException { 136 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 137 | String param = ""; 138 | if(!StringUtil.isEmpty(symbol)) { 139 | if(param.equals("")) { 140 | param += "/"; 141 | } 142 | param += symbol; 143 | } 144 | String result = httpUtil.requestHttpGet(url_prex, ORDERBOOK_URL + param, param); 145 | return result; 146 | } 147 | 148 | @Override 149 | public String tradeHistory(String symbol) throws HttpException, IOException { 150 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 151 | String param = ""; 152 | if(!StringUtil.isEmpty(symbol )) { 153 | if(param.equals("")) { 154 | param += "/"; 155 | } 156 | param += symbol; 157 | } 158 | System.out.println(TRADEHISTORY_URL+param); 159 | String result = httpUtil.requestHttpGet(url_prex, TRADEHISTORY_URL + param, ""); 160 | return result; 161 | } 162 | 163 | @Override 164 | public String balance() throws HttpException, IOException { 165 | Map params = new HashMap(); 166 | 167 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 168 | 169 | String result = httpUtil.doRequest( "data", "post", url_prex+BALANCE_URL, params ); 170 | return result; 171 | } 172 | 173 | 174 | @Override 175 | public String depositAddress(String symbol) throws HttpException, IOException { 176 | Map params = new HashMap(); 177 | params.put("currency", symbol); 178 | 179 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 180 | String result = httpUtil.doRequest( "data", "post", url_prex+DEPOSITADDRESS_URL, params ); 181 | return result; 182 | } 183 | 184 | 185 | @Override 186 | public String depositsWithdrawals(String startTime,String endTime) throws HttpException, IOException { 187 | Map params = new HashMap(); 188 | params.put("start", startTime); 189 | params.put("end", endTime); 190 | 191 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 192 | String result = httpUtil.doRequest( "data", "post", url_prex+ DEPOSITESWITHDRAWALS_URL, params ); 193 | return result; 194 | } 195 | 196 | @Override 197 | public String buy(String currencyPair,String rate, String amount) throws HttpException, IOException { 198 | Map params = new HashMap(); 199 | params.put("currencyPair", currencyPair); 200 | params.put("rate", rate); 201 | params.put("amount", amount); 202 | 203 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 204 | String result = httpUtil.doRequest( "data", "post", url_prex+ BUY_URL, params ); 205 | return result; 206 | } 207 | 208 | @Override 209 | public String sell(String currencyPair,String rate, String amount) throws HttpException, IOException { 210 | Map params = new HashMap(); 211 | params.put("currencyPair", currencyPair); 212 | params.put("rate", rate); 213 | params.put("amount", amount); 214 | 215 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 216 | String result = httpUtil.doRequest( "data", "post", url_prex+ SELL_URL, params ); 217 | return result; 218 | } 219 | 220 | 221 | @Override 222 | public String cancelOrder(String orderNumber,String currencyPair) throws HttpException, IOException { 223 | Map params = new HashMap(); 224 | params.put("orderNumber", orderNumber); 225 | params.put("currencyPair", currencyPair); 226 | 227 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 228 | String result = httpUtil.doRequest( "data", "post", url_prex+ CANCELORDER_URL, params ); 229 | return result; 230 | } 231 | 232 | @Override 233 | public String cancelAllOrders(String type,String currencyPair) throws HttpException, IOException { 234 | Map params = new HashMap(); 235 | params.put("type", type); 236 | params.put("currencyPair", currencyPair); 237 | 238 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 239 | String result = httpUtil.doRequest( "data", "post", url_prex+ CANCELALLORDERS_URL, params ); 240 | return result; 241 | } 242 | 243 | @Override 244 | public String getOrder(String orderNumber,String currencyPair) throws HttpException, IOException { 245 | Map params = new HashMap(); 246 | params.put("orderNumber", orderNumber); 247 | params.put("currencyPair", currencyPair); 248 | 249 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 250 | String result = httpUtil.doRequest( "data", "post", url_prex+ GETORDER_URL, params ); 251 | return result; 252 | } 253 | 254 | 255 | @Override 256 | public String openOrders() throws HttpException, IOException { 257 | Map params = new HashMap(); 258 | 259 | 260 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 261 | String result = httpUtil.doRequest( "data", "post", url_prex+ OPENORDERS_URL, params ); 262 | return result; 263 | } 264 | 265 | 266 | @Override 267 | public String myTradeHistory(String currencyPair,String orderNumber) throws HttpException, IOException { 268 | Map params = new HashMap(); 269 | params.put("currencyPair", currencyPair); 270 | params.put("orderNumber", orderNumber); 271 | 272 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 273 | String result = httpUtil.doRequest( "data", "post", url_prex+ MYTRADEHISTORY_URL, params ); 274 | return result; 275 | } 276 | 277 | 278 | @Override 279 | public String withdraw(String currency,String amount, String address) throws HttpException, IOException { 280 | Map params = new HashMap(); 281 | params.put("currency", currency); 282 | params.put("amount", amount); 283 | params.put("address", address); 284 | 285 | HttpUtilManager httpUtil = HttpUtilManager.getInstance(); 286 | String result = httpUtil.doRequest( "data", "post", url_prex+ WITHDRAW_URL, params ); 287 | return result; 288 | } 289 | 290 | 291 | 292 | 293 | 294 | 295 | public String getUrl_prex() { 296 | return url_prex; 297 | } 298 | 299 | public void setUrl_prex(String url_prex) { 300 | this.url_prex = url_prex; 301 | } 302 | 303 | } 304 | -------------------------------------------------------------------------------- /nodejs/app.js: -------------------------------------------------------------------------------- 1 | var gate = require('./lib/gate'); 2 | 3 | // Trading Pairs 4 | gate.getPairs(function (res) { 5 | console.log(res); 6 | }); 7 | 8 | 9 | // Market Info 10 | // gate.getMarketinfo(function (res) { 11 | // console.log(res); 12 | // }); 13 | 14 | 15 | // Market Details 16 | // gate.getMarketlist(function (res) { 17 | // console.log(res); 18 | // }); 19 | 20 | 21 | // Tickers for all the supported trading pairs 22 | // gate.getTickers(function (res) { 23 | // console.log(res); 24 | // }); 25 | 26 | 27 | //Ticker 28 | // gate.getTicker('eth_btc',function (res) { 29 | // console.log(res); 30 | // }); 31 | 32 | 33 | // Depth 34 | // gate.orderBooks(function (res) { 35 | // console.log(res); 36 | // }); 37 | 38 | 39 | // Depth of pair 40 | // gate.orderBook('etc_btc',function (res) { 41 | // console.log(res); 42 | // }); 43 | 44 | 45 | // Trade History 46 | // gate.tradeHistory('etc_btc',function (res) { 47 | // console.log(res); 48 | // }); 49 | 50 | 51 | // Get account fund balances 52 | // gate.getBalances(function (res) { 53 | // console.log(res); 54 | // }); 55 | 56 | 57 | // get deposit address 58 | // gate.depositAddress('btc',function (res) { 59 | // console.log(res); 60 | // }); 61 | 62 | 63 | // get deposit withdrawal history 64 | // gate.depositsWithdrawals('1508225535','1508311935',function (res) { 65 | // console.log(res); 66 | // }); 67 | 68 | // Place order buy 69 | // gate.buy('etc_btc','0.001', '0.876',function (res) { 70 | // console.log(res); 71 | // }); 72 | 73 | 74 | // Place order sell 75 | // gate.sell('etc_btc','0.02','3',function (res) { 76 | // console.log(res); 77 | // }); 78 | 79 | // Cancel order 80 | // gate.cancelOrder('267040896','etc_btc', function (res) { 81 | // console.log(res); 82 | // }); 83 | 84 | // Cancel all orders 85 | // gate.cancelAllOrders('1', 'etc_btc', function (res) { 86 | // console.log(res); 87 | // }); 88 | 89 | // Get order status 90 | // gate.getOrder('267040896', 'etc_btc', function (res) { 91 | // console.log(res); 92 | // }); 93 | 94 | 95 | //Get my open order list 96 | // gate.openOrders( function (res) { 97 | // console.log(res); 98 | // }); 99 | 100 | 101 | // Get my last 24h trades 102 | // gate.myTradeHistory('etc_btc','267040896', function (res) { 103 | // console.log(res); 104 | // }); 105 | 106 | 107 | // withdrawal 108 | // gate.withdraw('btc','123', '1CGJ7kWYC8fHYShC4m8Wy9j9BfrD9fLn58', function (res) { 109 | // console.log(res); 110 | // }); 111 | -------------------------------------------------------------------------------- /nodejs/lib/gate.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | var crypto = require('crypto'); 3 | var querystring = require('querystring'); 4 | 5 | // add your key and secret 6 | const KEY = 'your key'; 7 | const SECRET = 'your secret'; 8 | 9 | const API_QUERY_URL = 'https://data.gateio.life/'; 10 | const API_TRADE_URL = 'https://api.gateio.life/'; 11 | const PAIRS_URL = 'api2/1/pairs'; 12 | const MARKETINFO_URL = 'api2/1/marketinfo'; 13 | const MARKETLIST_URL = 'api2/1/marketlist'; 14 | const TICKERS_URL = 'api2/1/tickers'; 15 | const TICKER_URL = 'api2/1/ticker'; 16 | const ORDERBOOKS_URL = 'api2/1/orderBooks'; 17 | const ORDERBOOK_URL = 'api2/1/orderBook'; 18 | const TRADEHISTORY_URL = 'api2/1/tradeHistory'; 19 | 20 | const BALANCE_URL = 'api2/1/private/balances'; 21 | const DEPOSITADDRESS_URL = 'api2/1/private/depositAddress'; 22 | const DEPOSITSWITHDRAWALS_URL = 'api2/1/private/depositsWithdrawals'; 23 | const BUY_URL = 'api2/1/private/buy'; 24 | const SELL_URL = 'api2/1/private/sell'; 25 | const CANCELORDER_URL = 'api2/1/private/cancelOrder'; 26 | const CANCELALLORDERS_URL = 'api2/1/private/cancelAllOrders'; 27 | const GETORDER_URL = 'api2/1/private/getOrder'; 28 | const OPENORDERS_URL = 'api2/1/private/openOrders'; 29 | const MYTRADEHISTORY_URL = 'api2/1/private/tradeHistory'; 30 | const WITHDRAW_URL = 'api2/1/private/withdraw'; 31 | 32 | 33 | 34 | const USER_AGENT = ''; 35 | 36 | function Request (params,cp){ 37 | request(params, function(error, response, body) { 38 | if(error) { 39 | cp(error); 40 | }else{ 41 | cp(body); 42 | } 43 | }); 44 | } 45 | function getSign(str) { 46 | let unescapeStr = querystring.unescape(str); 47 | return crypto.createHmac('sha512', SECRET).update(unescapeStr).digest('hex').toString(); 48 | } 49 | 50 | var gate = { 51 | 52 | getPairs: function(cp) { 53 | Request({method: 'GET', url: API_QUERY_URL + PAIRS_URL, headers: { 'User-Agent' : USER_AGENT } },cp); 54 | }, 55 | 56 | getMarketinfo:function(cp) { 57 | Request({method: 'GET', url: API_QUERY_URL + MARKETINFO_URL, headers: { 'User-Agent' : USER_AGENT } },cp); 58 | }, 59 | 60 | getMarketlist:function (cp) { 61 | Request({method: 'GET', url: API_QUERY_URL + MARKETLIST_URL, headers: { 'User-Agent' : USER_AGENT } },cp); 62 | }, 63 | 64 | getTickers:function (cp) { 65 | Request({method: 'GET', url: API_QUERY_URL + TICKERS_URL, headers: { 'User-Agent' : USER_AGENT } },cp); 66 | }, 67 | 68 | getTicker:function (param,cp) { 69 | Request({method: 'GET', url: API_QUERY_URL + TICKER_URL + '/'+ param, headers: { 'User-Agent' : USER_AGENT } },cp); 70 | }, 71 | 72 | orderBooks:function (cp) { 73 | Request({method: 'GET', url: API_QUERY_URL + ORDERBOOKS_URL, headers: { 'User-Agent' : USER_AGENT } },cp); 74 | }, 75 | 76 | orderBook:function (param,cp) { 77 | Request({method: 'GET', url: API_QUERY_URL + ORDERBOOK_URL+ '/'+ param, headers: { 'User-Agent' : USER_AGENT } },cp); 78 | }, 79 | 80 | tradeHistory:function (param,cp) { 81 | Request({method: 'GET', url: API_QUERY_URL + TRADEHISTORY_URL+ '/'+ param, headers: { 'User-Agent' : USER_AGENT } },cp); 82 | }, 83 | 84 | getBalances:function (cp) { 85 | let form = {}; 86 | let header = {}; 87 | header.KEY = KEY; 88 | header.SIGN = getSign(querystring.stringify(form)); 89 | Request({method: 'POST', url: API_TRADE_URL + BALANCE_URL, headers: header, form:form },cp); 90 | }, 91 | 92 | depositAddress:function (currency, cp) { 93 | let form = {'currency':currency}; 94 | let header = {}; 95 | header.KEY = KEY; 96 | header.SIGN = getSign(querystring.stringify(form)); 97 | console.log(header); 98 | console.log(querystring.stringify(form)); 99 | console.log(API_TRADE_URL + DEPOSITADDRESS_URL); 100 | Request({method: 'POST', url: API_TRADE_URL + DEPOSITADDRESS_URL, headers: header, form:form },cp); 101 | }, 102 | 103 | 104 | depositsWithdrawals:function (start,end, cp) { 105 | let form = {'start':start,'end':end}; 106 | let header = {}; 107 | header.KEY = KEY; 108 | header.SIGN = getSign(querystring.stringify(form)); 109 | Request({method: 'POST', url: API_TRADE_URL + DEPOSITSWITHDRAWALS_URL, headers: header, form:form },cp); 110 | }, 111 | 112 | buy:function (currencyPair, rate, amount, cp) { 113 | let form = {'currencyPair':currencyPair,'rate':rate,'amount':amount}; 114 | let header = {}; 115 | header.KEY = KEY; 116 | header.SIGN = getSign(querystring.stringify(form)); 117 | Request({method: 'POST', url: API_TRADE_URL + BUY_URL, headers: header, form:form },cp); 118 | }, 119 | 120 | sell:function (currencyPair, rate, amount, cp) { 121 | let form = {'currencyPair':currencyPair,'rate':rate,'amount':amount}; 122 | let header = {}; 123 | header.KEY = KEY; 124 | header.SIGN = getSign(querystring.stringify(form)); 125 | Request({method: 'POST', url: API_TRADE_URL + SELL_URL, headers: header, form:form },cp); 126 | }, 127 | 128 | cancelOrder:function (orderNumber, currencyPair , cp) { 129 | let form = {'currencyPair':currencyPair,'orderNumber':orderNumber}; 130 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 131 | header.KEY = KEY; 132 | header.SIGN = getSign(querystring.stringify(form)); 133 | Request({method: 'POST', url: API_TRADE_URL + CANCELORDER_URL, headers: header, form:form },cp); 134 | }, 135 | 136 | cancelAllOrders:function (type, currencyPair , cp) { 137 | let form = {'currencyPair':currencyPair,'orderNumber':type}; 138 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 139 | header.KEY = KEY; 140 | header.SIGN = getSign(querystring.stringify(form)); 141 | Request({method: 'POST', url: API_TRADE_URL + CANCELALLORDERS_URL, headers: header, form:form },cp); 142 | }, 143 | 144 | getOrder:function (orderNumber, currencyPair , cp) { 145 | let form = {'currencyPair':currencyPair,'orderNumber':orderNumber}; 146 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 147 | header.KEY = KEY; 148 | header.SIGN = getSign(querystring.stringify(form)); 149 | Request({method: 'POST', url: API_TRADE_URL + GETORDER_URL, headers: header, form:form },cp); 150 | }, 151 | 152 | openOrders:function ( cp) { 153 | let form = {}; 154 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 155 | header.KEY = KEY; 156 | header.SIGN = getSign(querystring.stringify(form)); 157 | Request({method: 'POST', url: API_TRADE_URL + OPENORDERS_URL, headers: header, form:form },cp); 158 | }, 159 | 160 | myTradeHistory:function (currencyPair, orderNumber, cp) { 161 | let form = {'currencyPair':currencyPair,'orderNumber':orderNumber}; 162 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 163 | header.KEY = KEY; 164 | header.SIGN = getSign(querystring.stringify(form)); 165 | Request({method: 'POST', url: API_TRADE_URL + MYTRADEHISTORY_URL, headers: header, form:form },cp); 166 | }, 167 | 168 | withdraw:function (currency,amount, address, cp) { 169 | let form = {'currency':currency,'amount':amount,'address':address}; 170 | let header = {'Content-Type':'application/x-www-form-urlencoded'}; 171 | header.KEY = KEY; 172 | header.SIGN = getSign(querystring.stringify(form)); 173 | Request({method: 'POST', url: API_TRADE_URL + WITHDRAW_URL, headers: header, form:form },cp); 174 | }, 175 | 176 | }; 177 | 178 | 179 | module.exports = gate; 180 | -------------------------------------------------------------------------------- /nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gateio", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "nonce": "^1.0.4", 13 | "q": "^1.5.0", 14 | "request": "^2.83.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /perl/gateioApi.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # $Id: gateioApi.pl,v 0.01 2018/04/26 09:31:48 rob Exp $ 4 | # 5 | 6 | package GateIO; 7 | 8 | use Mojo::Base -base; 9 | use Mojo::UserAgent; 10 | use Digest::SHA qw(hmac_sha512_hex); 11 | 12 | use constant API_QUERY => 'https://data.gateio.life'; 13 | use constant API_TRADE => 'https://api.gateio.life'; 14 | use constant { 15 | URL_PAIRS => '/api2/1/pairs', 16 | URL_MARKET_INFO => '/api2/1/marketinfo', 17 | URL_MARKET_LIST => '/api2/1/marketlist', 18 | URL_TICKERS => '/api2/1/tickers', 19 | URL_TICKER => '/api2/1/ticker', 20 | URL_ORDER_BOOKS => '/api2/1/orderBooks', 21 | URL_ORDER_BOOK => '/api2/1/orderBook', 22 | URL_TRADE_HISTORY => '/api2/1/tradeHistory', 23 | URL_CANDLESTICK => '/api2/1/candlestick2', 24 | URL_BALANCES => '/api2/1/private/balances', 25 | URL_DEPOSIT_ADDRESS => '/api2/1/private/depositAddress', 26 | URL_DEPOSITS_WITHDRAWALS => '/api2/1/private/depositsWithdrawals', 27 | URL_BUY => '/api2/1/private/buy', 28 | URL_SELL => '/api2/1/private/sell', 29 | URL_CANCEL_ORDER => '/api2/1/private/cancelOrder', 30 | URL_CANCEL_ORDERS => '/api2/1/private/cancelOrders', 31 | URL_CANCEL_ALL_ORDERS => '/api2/1/private/cancelAllOrders', 32 | URL_GET_ORDER => '/api2/1/private/getOrder', 33 | URL_OPEN_ORDERS => '/api2/1/private/openOrders', 34 | URL_MY_TRADE_HISTORY => '/api2/1/private/tradeHistory', 35 | URL_WITHDRAW => '/api2/1/private/withdraw', 36 | }; 37 | 38 | has 'api_key'; 39 | has 'secret_key'; 40 | has ua => sub { Mojo::UserAgent->new }; 41 | 42 | # 所有交易对 43 | sub pairs { 44 | shift->ua->get(API_QUERY . URL_PAIRS)->res->json; 45 | } 46 | 47 | # 市场订单参数 48 | sub market_info { 49 | shift->ua->get(API_QUERY . URL_MARKET_LIST)->res->json; 50 | } 51 | 52 | # 交易市场详细行情 53 | sub market_list { 54 | shift->ua->get(API_QUERY . URL_MARKET_LIST)->res->json; 55 | } 56 | 57 | # 所有交易行情 58 | sub tickers { 59 | shift->ua->get(API_QUERY . URL_TICKERS)->res->json; 60 | } 61 | 62 | # 单项交易行情 63 | sub ticker { 64 | my $self = shift; 65 | my $param = shift; # 交易对名称 66 | $self->ua->get(API_QUERY . URL_TICKER . '/' . $param)->res->json; 67 | } 68 | 69 | # 所有交易对市场深度 70 | sub order_books { 71 | shift->ua->get(API_QUERY . URL_ORDER_BOOKS)->res->json; 72 | } 73 | 74 | # 单项交易对市场深度 75 | sub order_book { 76 | my $self = shift; 77 | my $param = shift; # 交易对名称 78 | $self->ua->get(API_QUERY . URL_ORDER_BOOK . '/' . $param)->res->json; 79 | } 80 | 81 | # 历史成交记录 82 | sub trade_history { 83 | my $self = shift; 84 | my $param = shift; # 交易对名称 85 | my $tid = shift; 86 | $param .= "/$tid" if defined $tid and $tid =~ /^\d+$/; 87 | $self->ua->get(API_QUERY . URL_TRADE_HISTORY . '/' . $param)->res->json; 88 | } 89 | 90 | # 交易市场K线数据 91 | sub candlestick { 92 | my $self = shift; 93 | my $param = shift; # 交易对名称 94 | my $group_sec = shift; 95 | my $rang_hour = shift; 96 | 97 | my $q = "/$param"; 98 | if (defined $group_sec and defined $rang_hour) { 99 | $q .= "?group_sec=$group_sec&rang_hour=$rang_hour"; 100 | } 101 | $self->ua->get(API_QUERY . URL_TRADE_HISTORY . $q)->res->json; 102 | } 103 | 104 | # 获取帐号资金余额 105 | sub balances { 106 | my $self = shift; 107 | my $params = {}; 108 | return $self->ua->post((API_TRADE . URL_BALANCES) 109 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 110 | => form => $params 111 | )->res->json; 112 | } 113 | 114 | sub deposit_address { 115 | my $self = shift; 116 | my $params = { @_ == 1 ? ('currency' => shift) : @_ }; 117 | return $self->ua->post((API_TRADE . URL_DEPOSIT_ADDRESS) 118 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 119 | => form => $params 120 | )->res->json; 121 | } 122 | 123 | sub deposits_withdrawals { 124 | my $self = shift; 125 | my $params = { @_ }; 126 | return $self->ua->post((API_TRADE . URL_DEPOSITS_WITHDRAWALS) 127 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 128 | => form => $params 129 | )->res->json; 130 | } 131 | 132 | sub buy { 133 | my $self = shift; 134 | my $params = { @_ }; 135 | return $self->ua->post((API_TRADE . URL_BUY) 136 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 137 | => form => $params 138 | )->res->json; 139 | } 140 | 141 | sub sell { 142 | my $self = shift; 143 | my $params = { @_ }; 144 | return $self->ua->post((API_TRADE . URL_SELL) 145 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 146 | => form => $params 147 | )->res->json; 148 | } 149 | 150 | sub cancel_order { 151 | my $self = shift; 152 | my $params = { @_ }; 153 | return $self->ua->post((API_TRADE . URL_CANCEL_ORDER) 154 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 155 | => form => $params 156 | )->res->json; 157 | } 158 | 159 | sub cancel_orders { 160 | my $self = shift; 161 | my $params = { @_ }; 162 | return $self->ua->post((API_TRADE . URL_CANCEL_ORDERS) 163 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 164 | => form => $params 165 | )->res->json; 166 | } 167 | 168 | sub cancel_all_orders { 169 | my $self = shift; 170 | my $params = { @_ }; 171 | return $self->ua->post((API_TRADE . URL_CANCEL_ALL_ORDERS) 172 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 173 | => form => $params 174 | )->res->json; 175 | } 176 | 177 | sub get_order { 178 | my $self = shift; 179 | my $params = { @_ }; 180 | return $self->ua->post((API_TRADE . URL_GET_ORDER) 181 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 182 | => form => $params 183 | )->res->json; 184 | } 185 | 186 | sub open_orders { 187 | my $self = shift; 188 | my $params = {}; 189 | return $self->ua->post((API_TRADE . URL_OPEN_ORDERS) 190 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 191 | => form => $params 192 | )->res->json; 193 | } 194 | 195 | sub my_trade_history { 196 | my $self = shift; 197 | my $params = { @_ }; 198 | return $self->ua->post((API_TRADE . URL_MY_TRADE_HISTORY) 199 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 200 | => form => $params 201 | )->res->json; 202 | } 203 | 204 | sub withdraw { 205 | my $self = shift; 206 | my $params = { @_ }; 207 | return $self->ua->post((API_TRADE . URL_WITHDRAW) 208 | => { KEY => $self->api_key, SIGN => $self->build_sign($params) } 209 | => form => $params 210 | )->res->json; 211 | } 212 | 213 | sub build_sign { 214 | my $self = shift; 215 | my $params = shift; 216 | my $sign = ''; 217 | 218 | for my $k ( sort(keys %$params) ) { 219 | $sign .= $k . '=' . $params->{$k} .'&'; 220 | } 221 | $sign =~ s/&$//; 222 | 223 | return hmac_sha512_hex($sign, $self->secret_key); 224 | } 225 | 226 | 227 | package main; 228 | 229 | use strict; 230 | use Data::Dumper; 231 | 232 | # 设置API Key,Secret Key 233 | my $api_key = 'your api key'; 234 | my $secret_key = 'your secret key'; 235 | 236 | my $api = GateIO->new; 237 | 238 | # Setting proxy 239 | # my $proxy = 'socks://127.0.0.1:2080/'; 240 | # $api->ua->proxy->http($proxy)->https($proxy); 241 | 242 | say Dumper( $api->pairs ); 243 | say Dumper( $api->ticker('btc_usdt') ); 244 | 245 | 246 | $api->api_key($api_key); 247 | $api->secret_key($secret_key); 248 | 249 | say Dumper( $api->balances ); 250 | say Dumper( $api->my_trade_history(currencyPair => 'btc_usdt') ); 251 | 252 | 253 | 1; 254 | -------------------------------------------------------------------------------- /php/gate.php: -------------------------------------------------------------------------------- 1 | $order_number 169 | ) 170 | ); 171 | } 172 | 173 | function withdraw($currency, $amount, $address) { 174 | 175 | return gate_query('1/private/withdraw', 176 | array( 177 | 'currency' => strtoupper($currency), 178 | 'amount' => $amount, 179 | 'address' => $address 180 | ) 181 | ); 182 | } 183 | 184 | function get_order($order_number, $currency_pair) { 185 | 186 | return gate_query('1/private/getOrder', 187 | array( 188 | 'orderNumber' => $order_number, 189 | 'currencyPair' => strtoupper($currency_pair) 190 | ) 191 | ); 192 | } 193 | 194 | function cancel_order($order_number, $currency_pair) { 195 | 196 | return gate_query('1/private/cancelOrder', 197 | array( 198 | 'orderNumber' => $order_number, 199 | 'currencyPair' => strtoupper($currency_pair) 200 | ) 201 | ); 202 | } 203 | 204 | function cancel_orders($orders) { 205 | return gate_query('1/private/cancelOrders', 206 | // ['orders_json'=> $orders] 207 | ['orders_json'=>json_encode( $orders)] 208 | ); 209 | } 210 | 211 | function cancel_all_orders($type, $currency_pair) { 212 | 213 | return gate_query('1/private/cancelAllOrders', 214 | array( 215 | 'type' => $type, 216 | 'currencyPair' => strtoupper($currency_pair) 217 | ) 218 | ); 219 | } 220 | 221 | function sell($currency_pair, $rate, $amount) { 222 | 223 | return gate_query('1/private/sell', 224 | array( 225 | 'currencyPair' => strtoupper($currency_pair), 226 | 'rate' => $rate, 227 | 'amount' => $amount, 228 | ) 229 | ); 230 | } 231 | 232 | function buy($currency_pair, $rate, $amount) { 233 | 234 | return gate_query('1/private/buy', 235 | array( 236 | 'currencyPair' => strtoupper($currency_pair), 237 | 'rate' => $rate, 238 | 'amount' => $amount, 239 | ) 240 | ); 241 | } 242 | 243 | function get_my_trade_history($currency_pair, $order_number) { 244 | 245 | return gate_query('1/private/tradeHistory', 246 | array( 247 | 'currencyPair' => strtoupper($currency_pair), 248 | 'orderNumber' => $order_number 249 | ) 250 | ); 251 | } 252 | 253 | function open_orders($currency_pair='') { 254 | 255 | return gate_query('1/private/openOrders', 256 | array( 257 | 'currencyPair' => strtoupper($currency_pair) 258 | )); 259 | } 260 | 261 | function deposites_withdrawals($start, $end) { 262 | 263 | return gate_query('1/private/depositsWithdrawals', 264 | array( 265 | 'start' => $start, 266 | 'end' => $end 267 | ) 268 | ); 269 | } 270 | 271 | function new_adddress($currency) { 272 | 273 | return gate_query('1/private/newAddress', 274 | array( 275 | 'currency' => strtoupper($currency) 276 | ) 277 | ); 278 | } 279 | 280 | function deposit_address($currency) { 281 | 282 | return gate_query('1/private/depositAddress', 283 | array( 284 | 'currency' => strtoupper($currency) 285 | ) 286 | ); 287 | } 288 | 289 | function check_username($username, $phone, $sign) { 290 | 291 | 292 | return gate_query('1/checkUsername', 293 | array( 294 | 'username' => $username, 295 | 'phone' => $phone, 296 | 'sign' => $sign 297 | ) 298 | ); 299 | } 300 | 301 | try { 302 | 303 | /*** public API methods examples ***/ 304 | 305 | // 所有交易对 306 | // print_r( get_pairs()); 307 | 308 | 309 | //交易市场订单参数 310 | // print_r(get_marketinfo()); 311 | 312 | //交易市场详细行情 313 | // print_r(get_marketlist()); 314 | 315 | // 所有交易行情 316 | // print_r(get_tickers()); 317 | 318 | //单项交易行情 319 | // print_r(get_ticker('eth_btc')); 320 | 321 | //交易对的市场深度 322 | // print_r(get_orderbooks()); 323 | 324 | //指定交易对的市场深度 325 | // print_r(get_orderbook('btc_usdt')); 326 | 327 | //历史成交记录 328 | // print_r(get_trade_history('btc_usdt', 1000)); 329 | 330 | 331 | 332 | /*** private API methods examples ***/ 333 | 334 | 335 | // 获取账号资金余额 336 | // print_r(get_balances()); 337 | 338 | 339 | //获取充值地址 340 | // print_r(deposit_address('btc')); 341 | 342 | 343 | //获取充值提现历史 344 | // print_r(deposites_withdrawals('1469092370', '1670713981')); 345 | 346 | 347 | //下单交易买入 348 | // print_r(buy('etc_btc', '0.0035', '0.3')); 349 | 350 | //下单交易卖出 351 | // print_r(sell('etc_btc', '0.00214', '0.3')); 352 | 353 | 354 | //取消下单 355 | // print_r(cancel_order(263393711), 'etc_btc'); 356 | 357 | 358 | //取消所有下单 359 | // print_r(cancel_all_orders('0', 'etc_btc')); 360 | 361 | 362 | //获取下单状态 363 | // print_r(get_order(263393711, 'etc_btc')); 364 | 365 | 366 | //获取我的当前挂单列表 367 | // print_r(open_orders()); 368 | 369 | 370 | //获取我的24小时内成交记录 371 | // print_r(get_trade_history('eth_btc',27817390)); 372 | 373 | 374 | //提现 375 | // print_r(withdraw('btc','11','your wallet address')); 376 | 377 | 378 | } catch (Exception $e) { 379 | echo "Error:".$e->getMessage(); 380 | } 381 | ?> 382 | -------------------------------------------------------------------------------- /python/Client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # encoding: utf-8 4 | 5 | ''' 6 | Provide user specific data and interact with gate.io 7 | ''' 8 | 9 | from gateAPI import GateIO 10 | 11 | # 填写 apiKey APISECRET 12 | apiKey = 'your api key' 13 | secretKey = 'your api secret' 14 | 15 | # address 16 | btcAddress = 'your btc address' 17 | 18 | 19 | # Provide constants 20 | 21 | API_QUERY_URL = 'data.gateio.life' 22 | API_TRADE_URL = 'api.gateio.life' 23 | 24 | # Create a gate class instance 25 | 26 | gate_query = GateIO(API_QUERY_URL, apiKey, secretKey) 27 | gate_trade = GateIO(API_TRADE_URL, apiKey, secretKey) 28 | 29 | 30 | # Trading Pairs 31 | print(gate_query.pairs()) 32 | 33 | 34 | # Below, use general methods that query the exchange 35 | 36 | # Market Info 37 | # print(gate_query.marketinfo()) 38 | 39 | # Market Details 40 | # print(gate_query.marketlist()) 41 | 42 | # Tickers 43 | # print(gate_query.tickers()) 44 | # Depth 45 | # print(gate_query.orderBooks()) 46 | 47 | # orders 48 | # print(gate_query.openOrders()) 49 | 50 | 51 | # Below, use methods that make use of the users keys 52 | 53 | # Ticker 54 | # print(gate_query.ticker('btc_usdt')) 55 | 56 | # Market depth of pair 57 | # print(gate_query.orderBook('btc_usdt')) 58 | 59 | # Trade History 60 | # print(gate_query.tradeHistory('btc_usdt')) 61 | 62 | # Get account fund balances 63 | # print(gate_trade.balances()) 64 | 65 | # get new address 66 | # print(gate_trade.depositAddres('btc')) 67 | 68 | # get deposit withdrawal history 69 | # print(gate_trade.depositsWithdrawals('1469092370', '1569092370')) 70 | 71 | # Place order sell 72 | # print(gate_trade.buy('etc_btc', '0.001', '123')) 73 | 74 | # Place order sell 75 | # print(gate_trade.sell('etc_btc', '0.001', '123')) 76 | 77 | # Cancel order 78 | # print(gate_trade.cancelOrder('267040896', 'etc_btc')) 79 | 80 | # Cancel all orders 81 | # print(gate_trade.cancelAllOrders('0', 'etc_btc')) 82 | 83 | # Get order status 84 | # print(gate_trade.getOrder('267040896', 'eth_btc')) 85 | 86 | # Get my last 24h trades 87 | # print(gate_trade.mytradeHistory('etc_btc', '267040896')) 88 | 89 | # withdraw 90 | # print(gate_trade.withdraw('btc', '88', btcAddress)) 91 | -------------------------------------------------------------------------------- /python/HttpUtil.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import http.client 5 | import urllib 6 | import json 7 | import hashlib 8 | import hmac 9 | 10 | def getSign(params, secretKey): 11 | bSecretKey = bytes(secretKey, encoding='utf8') 12 | 13 | sign = '' 14 | for key in params.keys(): 15 | value = str(params[key]) 16 | sign += key + '=' + value + '&' 17 | bSign = bytes(sign[:-1], encoding='utf8') 18 | 19 | mySign = hmac.new(bSecretKey, bSign, hashlib.sha512).hexdigest() 20 | return mySign 21 | 22 | def httpGet(url, resource, params=''): 23 | conn = http.client.HTTPSConnection(url, timeout=10) 24 | conn.request("GET", resource + '/' + params) 25 | response = conn.getresponse() 26 | data = response.read().decode('utf-8') 27 | return json.loads(data) 28 | 29 | def httpPost(url, resource, params, apiKey, secretKey): 30 | headers = { 31 | "Content-type" : "application/x-www-form-urlencoded", 32 | "KEY":apiKey, 33 | "SIGN":getSign(params, secretKey) 34 | } 35 | 36 | conn = http.client.HTTPSConnection(url, timeout=10) 37 | 38 | tempParams = urllib.parse.urlencode(params) if params else '' 39 | conn.request("POST", resource, tempParams, headers) 40 | response = conn.getresponse() 41 | data = response.read().decode('utf-8') 42 | params.clear() 43 | conn.close() 44 | return data 45 | -------------------------------------------------------------------------------- /python/gateAPI.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' 5 | Provide the GateIO class to abstract web interaction 6 | ''' 7 | 8 | from HttpUtil import getSign, httpGet, httpPost 9 | 10 | class GateIO: 11 | def __init__(self, url, apiKey, secretKey): 12 | self.__url = url 13 | self.__apiKey = apiKey 14 | self.__secretKey = secretKey 15 | 16 | ## General methods that query the exchange 17 | 18 | #所有交易对 19 | def pairs(self): 20 | URL = "/api2/1/pairs" 21 | params='' 22 | return httpGet(self.__url, URL, params) 23 | 24 | #所有货币 25 | def coins_info(self): 26 | URL = "/api2/1/coininfo" 27 | params = '' 28 | return httpGet(self.__url, URL, params) 29 | 30 | #市场订单参数 31 | def marketinfo(self): 32 | URL = "/api2/1/marketinfo" 33 | params='' 34 | return httpGet(self.__url, URL, params) 35 | 36 | #交易市场详细行情 37 | def marketlist(self): 38 | URL = "/api2/1/marketlist" 39 | params='' 40 | return httpGet(self.__url, URL, params) 41 | 42 | #所有交易行情 43 | def tickers(self): 44 | URL = "/api2/1/tickers" 45 | params='' 46 | return httpGet(self.__url, URL, params) 47 | 48 | # 所有交易对市场深度 49 | def orderBooks(self): 50 | URL = "/api2/1/orderBooks" 51 | param='' 52 | return httpGet(self.__url, URL, param) 53 | 54 | #单项交易行情 55 | def ticker(self, param): 56 | URL = "/api2/1/ticker" 57 | return httpGet(self.__url, URL, param) 58 | 59 | # 单项交易对市场深度 60 | def orderBook(self, param): 61 | URL = "/api2/1/orderBook" 62 | return httpGet(self.__url, URL, param) 63 | 64 | # 历史成交记录 65 | def tradeHistory(self, param): 66 | URL = "/api2/1/tradeHistory" 67 | return httpGet(self.__url, URL, param) 68 | 69 | ## Methods that make use of the users keys 70 | 71 | #获取帐号资金余额 72 | def balances(self): 73 | URL = "/api2/1/private/balances" 74 | param = {} 75 | return httpPost(self.__url, URL, param, self.__apiKey, self.__secretKey) 76 | 77 | # 获取充值地址 78 | def depositAddres(self,param): 79 | URL = "/api2/1/private/depositAddress" 80 | params = {'currency':param} 81 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 82 | 83 | # 获取充值提现历史 84 | def depositsWithdrawals(self, start,end): 85 | URL = "/api2/1/private/depositsWithdrawals" 86 | params = {'start': start,'end':end} 87 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 88 | 89 | # 买入 90 | def buy(self, currencyPair,rate, amount): 91 | URL = "/api2/1/private/buy" 92 | params = {'currencyPair': currencyPair,'rate':rate, 'amount':amount} 93 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 94 | 95 | # 卖出 96 | def sell(self, currencyPair, rate, amount): 97 | URL = "/api2/1/private/sell" 98 | params = {'currencyPair': currencyPair, 'rate': rate, 'amount': amount} 99 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 100 | 101 | # 取消订单 102 | def cancelOrder(self, orderNumber, currencyPair): 103 | URL = "/api2/1/private/cancelOrder" 104 | params = {'orderNumber': orderNumber, 'currencyPair': currencyPair} 105 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 106 | 107 | # 取消所有订单 108 | def cancelAllOrders(self, type, currencyPair): 109 | URL = "/api2/1/private/cancelAllOrders" 110 | params = {'type': type, 'currencyPair': currencyPair} 111 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 112 | 113 | # 获取下单状态 114 | def getOrder(self, orderNumber, currencyPair): 115 | URL = "/api2/1/private/getOrder" 116 | params = {'orderNumber': orderNumber, 'currencyPair': currencyPair} 117 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 118 | 119 | # 获取我的当前挂单列表 120 | def openOrders(self): 121 | URL = "/api2/1/private/openOrders" 122 | params = {} 123 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 124 | 125 | # 获取我的24小时内成交记录 126 | def mytradeHistory(self, currencyPair, orderNumber): 127 | URL = "/api2/1/private/tradeHistory" 128 | params = {'currencyPair': currencyPair, 'orderNumber': orderNumber} 129 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 130 | 131 | # 提现 132 | def withdraw(self, currency, amount, address): 133 | URL = "/api2/1/private/withdraw" 134 | params = {'currency': currency, 'amount': amount,'address':address} 135 | return httpPost(self.__url, URL, params, self.__apiKey, self.__secretKey) 136 | --------------------------------------------------------------------------------