Skip to content

Commit 31768b9

Browse files
author
github-actions
committed
[BUILD]: 3fa165591d0f7628e00452dc5f2bf4b04f47a300
1 parent 9393aa1 commit 31768b9

File tree

11 files changed

+256
-186
lines changed

11 files changed

+256
-186
lines changed

.github/scripts/push-to-repo.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ GITHUB_SHA=$3
88
# Clone and push to the repo
99
TEMP_DIR=$(mktemp -d)
1010
TEMP_DIR_GIT="$TEMP_DIR/$EXCHANGE_NAME-python"
11+
echo "Cloning $EXCHANGE_NAME-python repository into $TEMP_DIR_GIT"
1112
git clone https://x-access-token:$API_TOKEN@github.com/ccxt/$EXCHANGE_NAME-python.git $TEMP_DIR_GIT
1213
# at first, clean th directory (except .git directory) and copy all files
14+
echo "Clone finished"
1315
rm -rf $TEMP_DIR_GIT/*
1416
rm -rf $TEMP_DIR_GIT/.github/*
15-
rsync -av --exclude='.git' ./ $TEMP_DIR_GIT
16-
# remove all yml files except remote
17-
dir $TEMP_DIR_GIT/.github/workflows/
17+
rsync -av --info=progress2 --info=name0 --exclude='.git/' --exclude='tmp/' --exclude='build/ccxt/' ./ $TEMP_DIR_GIT
1818
rm -f $TEMP_DIR_GIT/.github/workflows/transfer-all.yml && rm -f $TEMP_DIR_GIT/.github/workflows/transfer-exchange.yml
1919
cd $TEMP_DIR_GIT
2020
git config user.name github-actions
2121
git config user.email [email protected]
2222
git add .
2323
rm -f README.md
24-
echo $EXCHANGE_NAME > name
24+
echo $EXCHANGE_NAME > exchange_name
2525
(git commit -m "[BUILD]: $GITHUB_SHA" && git push origin main --force) || echo "No changes to commit"

.github/scripts/pushback.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
git config --local user.email "[email protected]"
4+
git config --local user.name "GitHub Action"
5+
git add README.md
6+
git commit -m "Update README with exchange repository links" || echo "No changes to commit"
7+
git push

.github/workflows/build-single-exchange.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,30 @@ jobs:
2727
cd build || echo "already in build"
2828
# get repository name and it's first word before hypher and pass that as argument
2929
REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2 | cut -d'-' -f1)
30-
echo "REPO_NAME: $REPO_NAME"
3130
npm run build -- $REPO_NAME
3231
3332
- name: Commit and push changes
3433
run: |
35-
git config --local user.email "[email protected]"
36-
git config --local user.name "GitHub Action"
37-
git add README.md
38-
git commit -m "Update README with exchange repository links" || echo "No changes to commit"
39-
git push
34+
chmod +x .github/scripts/pushback.sh
35+
.github/scripts/pushback.sh
36+
37+
- name: Set up Python
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: '3.x'
41+
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install build twine
46+
47+
- name: Build package
48+
run: |
49+
cd temp_pypi
50+
python -m build
51+
52+
- name: Publish to PyPI
53+
env:
54+
TWINE_USERNAME: __token__
55+
TWINE_PASSWORD: ${{ secrets.PYPI_API_SECRET }}
56+
run: twine upload dist/*

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
"program": "${file}",
1212
"console": "integratedTerminal"
1313
},
14+
{
15+
"name": "TSX: file",
16+
"type": "node",
17+
"request": "launch",
18+
"runtimeExecutable": "tsx",
19+
"program": "${file}",
20+
"console": "integratedTerminal",
21+
"internalConsoleOptions": "neverOpen",
22+
"skipFiles": [
23+
"<node_internals>/**",
24+
"node_modules/**"
25+
],
26+
"sourceMaps": true,
27+
},
1428
{
1529
"name": "TSX: build",
1630
"type": "node",

README.md

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,3 @@
1-
# kucoin-python
2-
Python SDK (sync and async) for Kucoin with Rest and WS capabilities.
3-
4-
You can check Kucoin's docs here: [Docs](https://example.com)
5-
6-
7-
You can check the SDK docs here: [SDK](https://docs.ccxt.com/#/exchanges/kucoin)
8-
9-
*This package derives from CCXT and allows you to call pretty much every endpoint by either using the unified CCXT API or calling the endpoints directly*
10-
11-
## Installation
12-
13-
```
14-
pip install kucoin-api
15-
```
16-
17-
## Usage
18-
19-
### Async
20-
21-
```Python
22-
from kucoin-api import KucoinAsync
23-
24-
async def main():
25-
instance = KucoinAsync({})
26-
order = await instance.create_order(__EXAMPLE_SYMBOL__, "limit", "buy", 1, 100000)
27-
```
28-
29-
### Sync
30-
31-
```Python
32-
from kucoin-api import KucoinSync
33-
34-
def main():
35-
instance = KucoinSync({})
36-
order = instance.create_order(__EXAMPLE_SYMBOL__, "limit", "buy", 1, 100000)
37-
```
38-
39-
### Websockets
40-
41-
```Python
42-
from kucoin-api import KucoinWs
43-
44-
async def main():
45-
instance = KucoinWs({})
46-
while True:
47-
orders = await instance.watch_orders(__EXAMPLE_SYMBOL__)
48-
```
1+
# central repo for single exchanges
492

3+
this is dev.repo, not meant to be used by end users.

build/build.ts

Lines changed: 20 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,11 @@
11
import * as fs from 'fs'
22
import path from 'path'
3-
import { fileURLToPath } from 'url';
4-
import { exec, execSync } from 'node:child_process';
5-
6-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
73

4+
import { argvs, exchangeArgv, execSync, cp, capitalize, regexAll } from './utils';
85

9-
// ##################### helpers ##################### //
10-
11-
function cp(source: string, destination: string): void {
12-
// check if source is file or dir
13-
if (!fs.existsSync(source)) {
14-
throw new Error(`Source file/directory does not exist: ${source}`);
15-
}
16-
const stats = fs.statSync(source);
17-
if (stats.isFile()) {
18-
// get parent directory
19-
const parentDir = path.dirname(destination);
20-
// check if parent directory exists
21-
if (!fs.existsSync(parentDir)) {
22-
fs.mkdirSync(parentDir, { recursive: true });
23-
}
24-
fs.copyFileSync(source, destination);
25-
return;
26-
}
27-
if (!fs.existsSync(destination)) {
28-
fs.mkdirSync(destination, { recursive: true });
29-
}
30-
const files = fs.readdirSync(source);
31-
for (const file of files) {
32-
const srcPath = path.join(source, file);
33-
const destPath = path.join(destination, file);
34-
cp(srcPath, destPath);
35-
}
36-
}
37-
38-
function capitalize(str) {
39-
return str.charAt(0).toUpperCase() + str.slice(1);
40-
}
6+
import { fileURLToPath } from 'url';
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
418

42-
// ################################################### //
439

4410

4511

@@ -60,7 +26,7 @@ class build {
6026
this.init(exchange);
6127
}
6228

63-
async downloadRepo() {
29+
async downloadCcxtRepo() {
6430
try {
6531
execSync('rm -rf ccxt/', { stdio: 'ignore' });
6632
} catch (ex) {
@@ -69,7 +35,7 @@ class build {
6935
execSync ('git clone --depth 1 https://github.com/ccxt/ccxt.git');
7036
}
7137

72-
copyFiles (exchange:string): void {
38+
copyCcxtFiles (exchange:string): void {
7339
const sourceDir = this.sourceFolder + '/python/ccxt/';
7440
const copyList = [
7541
// exchange files
@@ -101,21 +67,11 @@ class build {
10167
}
10268
}
10369

104-
regexAll (text: string, array: any[]) {
105-
for (const i in array) {
106-
const regexValue = array[i][0]
107-
const flags = (typeof regexValue === 'string') ? 'g' : undefined
108-
const regex = new RegExp (regexValue, flags)
109-
text = text.replace (regex, array[i][1])
110-
}
111-
return text
112-
}
113-
11470
async cleanInitFile(filePath: string, async = false) {
11571
let fileContent = fs.readFileSync(filePath, 'utf8');
11672
for (const id of this.allExchangesList) {
11773
if (id !== this.exchange) {
118-
fileContent = this.regexAll (fileContent, [
74+
fileContent = regexAll (fileContent, [
11975
[ new RegExp(`from ccxt\.${id} import ${id}.+\n`), '' ],
12076
[ new RegExp(`from ccxt\.async_support\.${id} import ${id}.+\n`), '' ],
12177
[ new RegExp(`from ccxt\.pro\.${id} import ${id}.+\n`), '' ],
@@ -183,19 +139,22 @@ class build {
183139
fs.writeFileSync (__dirname + '/../meta.json', stringified);
184140
}
185141

186-
capitalize (str: string) {
187-
return str.charAt(0).toUpperCase() + str.slice(1);
188-
}
189-
190142
replaceGlobalRegexes (text: string, array: any[]) {
191143
let newText = text;
192-
newText = this.regexAll (newText, [
144+
newText = regexAll (newText, [
193145
['__exchangeName__', this.exchange],
194-
['__ExchangeName__', this.capitalize(this.exchange)],
146+
['__ExchangeName__', capitalize(this.exchange)],
195147
]);
148+
const otherStrings = {
149+
'__LINK_TO_OFFICIAL_EXCHANGE_DOCS__': 'https://ccxt.com',
150+
'__PYTHON_PACKAGE_NAME__': undefined,
151+
'__TEST_SYMBOL__': 'BTC/USDC',
152+
};
196153
const exchangeConfig = this.globalConfigs['exchanges'][this.exchange];
197-
for (const key in exchangeConfig) {
198-
newText = newText.replace(new RegExp(`${key}`, 'g'), exchangeConfig[key]);
154+
for (const key in otherStrings) {
155+
const defaultValue = otherStrings[key];
156+
let value = exchangeConfig[key] || defaultValue; // at first, read from config, if not, use default
157+
newText = newText.replace(new RegExp(`${key}`, 'g'), value);
199158
}
200159
return newText;
201160
}
@@ -223,9 +182,9 @@ class build {
223182

224183
async init (exchange:string) {
225184
if (this.downloadAndDelete) {
226-
await this.downloadRepo ();
185+
await this.downloadCcxtRepo ();
227186
}
228-
this.copyFiles (exchange);
187+
this.copyCcxtFiles (exchange);
229188
await this.setAllExchangesList ();
230189
await this.creataPackageInitFile ();
231190

@@ -250,18 +209,5 @@ class build {
250209

251210

252211

253-
254-
const argvs = process.argv.slice(2);
255-
let exchange = argvs[0];
256-
if (!exchange || exchange.includes('--')) {
257-
const nameFile = __dirname + '/../exchange_name';
258-
if (fs.existsSync(nameFile)) {
259-
exchange = fs.readFileSync(nameFile, 'utf8').trim();
260-
}
261-
}
262-
if (!exchange) {
263-
console.error('Please pass exchange name to build script or set it in a "exchange_name" file in the root of the project');
264-
process.exit(1);
265-
}
266212
const donwloadAndDelete = !argvs.includes('--nodownload');
267-
new build(exchange, donwloadAndDelete);
213+
new build(exchangeArgv, donwloadAndDelete);

0 commit comments

Comments
 (0)