-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
newcoin.nim
79 lines (65 loc) · 2.33 KB
/
newcoin.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## TradingBot that buys new coins listed on Binance, as soon as they are available, at a cheap price, and sell them when they are pumped up in price.
import std/[os, json, strutils, httpcore, math], binance
proc main() =
let
client = newBinance(getEnv"BINANCE_API_KEY", getEnv"BINANCE_API_SECRET")
exchangeData = parseJson(client.exchangeInfo())["symbols"]
var
i = 0
currentCryptos: JsonNode
currentLen, newCoin: int
amount, priceToBuy: float
symbolToBuy, symbol: string
message = newStringOfCap(6)
prevCryptos = parseJson(client.request(client.tickerPrice()))
prevLen = prevCryptos.len
while on:
currentCryptos = parseJson(client.request(client.tickerPrice()))
currentLen = currentCryptos.len
message.addInt prevLen
echo message
message.setLen 0
if prevLen < currentLen:
newCoin = prevLen
echo currentCryptos[newCoin]
break
else:
sleep 10_000
for indx in newCoin ..< currentLen:
symbol = currentCryptos[indx]["symbol"].getStr
for asset in exchangeData:
if asset["symbol"].getStr == symbol:
symbolToBuy = asset["quoteAsset"].getStr
break
priceToBuy = currentCryptos[i]["price"].getStr.parseFloat
checkFloat priceToBuy
case symbolToBuy
of "BTC" : amount = 0.0013
of "ETH" : amount = 0.03
of "USDT": amount = 15.0
of "BUSD": amount = 15.0
of "BNB" : amount = 0.7
else: echo "symbolToBuy not in 'BTC', 'ETH', 'USDT', 'BUSD', 'BNB'."
if amount == 0.0: continue
elif amount > 0.0:
inc i
echo client.request(client.postOrder(
symbol = symbol,
side = SIDE_BUY,
quantity = client.truncate(amount / priceToBuy, 3),
price = client.truncate(priceToBuy, 3),
tipe = ORDER_TYPE_LIMIT,
), HttpPost)
echo client.request(client.newOrderOco(
symbol = symbol,
side = SIDE_SELL,
quantity = client.truncate(amount / priceToBuy, 3),
price = client.truncate(priceToBuy * 1.020, 3),
stopPrice = client.truncate(priceToBuy * 0.995, 3),
stopLimitPrice = client.truncate(priceToBuy * 0.994, 3),
stopLimitTimeInForce = $TIME_IN_FORCE_GTC
), HttpPost)
sleep 10_000
client.close()
when isMainModule:
main()